1
0
Fork 0
isopod.cool/blog/posts/guide_things_i_keep_having_to_google/index.php

127 lines
11 KiB
PHP

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Guide - Things I Keep Having to Google</title>
<link href="../../../style.css" rel="stylesheet" type="text/css" media="all">
<style>
/*h1 {
background-image: url('wireguard_logo.png');
}
summary > * {
margin-bottom: 0;
display: inline-block;
}
details[open] > summary h6 {
display: none;
}*/
td {
padding: .2rem;
}
td h4 {
margin: 0;
}
</style>
</head>
<body>
<h1>guide:</h1>
<h2 id="caption">Things I Keep Having to Google</h2>
<nav>
<a href="../../../">home</a>
<a href="../../">blog</a>
</nav>
<p>This isn't really a guide to anything in particular, I just wanted an easily accessible reference for all the things I'm sick of wading through google results for, or otherwise seem to need help remembering. I've put it here in case someone else might find this helpful. I'll likely be adding to this as I find myself repeatedly googling things.</p>
<h2>Binding things to just the Super key in KDE</h2>
<ol>
<li>Bind it to some other keyboard shortcut using KDE's typical GUI methods. Any shortcut will do.</li>
<li>Find the entry for it in <code>~/.config/khotkeysrc</code>. There should be a line that looks like: <code>Uuid={77575b17-36d6-4b4e-b01f-2f1156e38583}</code>. Copy everything inside the curly braces, including the braces themselves.</li>
<li>Run the following commands:</li>
</ol>
<code style="overflow: scroll;">$ kwriteconfig5 --file ~/.config/kwinrc --group ModifierOnlyShortcuts --key Meta "org.kde.kglobalaccel,/component/khotkeys,org.kde.kglobalaccel.Component,invokeShortcut,&lt;YOUR UUID HERE&gt;"<br>$ qdbus org.kde.KWin /KWin reconfigure</code>
<h2>Linux command line/Bash stuff</h2>
<table>
<tr><td colspan="2"><h4>pipeline</h4></td></tr>
<tr><td><code>command | command2</code></td><td>uses the output of one command as the input to the next</td></tr>
<tr><td><code>command &gt; file</code></td><td>saves the output of a command to a file</td></tr>
<tr><td><code>command &lt; file</code></td><td>uses a file as the input to a command</td></tr>
<tr><td><code>command &lt; fileA &gt; fileB</code></td><td>will therefore run <code>command</code> with the contents of <code>fileA</code> as the input, and save the output to <code>fileB</code></td></tr>
<tr><td style="white-space:nowrap;"><code>command &lt;&lt;&lt; "string or $variable"</code></td><td>will use the string or variable as the input to a command, the same as <code>&nbsp;&lt; file</code></td></tr>
<tr><td colspan="2"><h4>variables</h4></td></tr>
<tr><td><code>variable=value</code></td><td>assigns a variable</td></tr>
<tr><td><code>$variable</code></td><td>references it</td></tr>
<tr><td><code>$(command)</code></td><td>lets you treat the output of a command like a variable reference</td></tr>
<tr><td><code>$((number+variable))</code></td><td>does the same thing for integer math expressions.</td></tr>
<tr><td><code>$((&nbsp;$(command)&nbsp;))<br>$((&nbsp;variable&nbsp;))</code></td><td>This can also just convert strings into integers.</td></tr>
<tr><td><code>"te$(command)xt"<br>"as$((math))df"</code></td><td>Both can be inserted into strings.</td></tr>
<tr><td><code>"some&nbsp;$variable&nbsp;text"<br>"more${variable}text"</code></td><td>Both of these are valid ways to insert a variable into a string.</td></tr>
<tr><td colspan="2"><h4>grep</h4></td></tr>
<tr><td><code>-v</code></td><td>Inverts it, so matches are excluded</td></tr>
<tr><td><code>-E "/regex/"</code></td><td>Lets you use regex</td></tr>
<tr><td colspan="2"><h4>cut</h4></td></tr>
<tr><td><code>-d 'string'</code></td><td>Determines the delimiter string, the default is the TAB character</td></tr>
<tr><td><code>-f n</code></td><td>Specifies a field to output, delimited by <code>-d</code></td></tr>
<tr><td><code>sed 's/&nbsp;&nbsp;*/&nbsp;/g' | cut -d ' '</code></td><td>Piping your thing through this <span title="It's not foolproof, though. Make sure you understand what this is doing so you can adapt it if it breaks.">helps</span> with parsing a lot of Linux commands that output tabular data</td></tr>
<tr><td colspan="2"><h4>sed</h4></td></tr>
<tr><td><code>sed "s/regex/replacement/flags"</code></td><td>The basic sed replacement command, checks a line of input against the provided regular expression <code>regex</code> and replaces matches with <code>replacement</code>.</td></tr>
<tr><td><code>sed "s/a/b/;s/c/d/"</code></td><td>Multiple sed commands can be strung together in one, like so.</td></tr>
<tr><td><code>sed "s/a/b/g"</code></td><td>The <code>g</code> flag makes sed replace all occurences of the pattern, not just the first</td></tr>
<tr><td><code>sed "s/a/b/&lt;number&gt;"</code></td><td>Insert any number to tell sed to replace only that occurence. Counts from 1. Theoretically, <code>s/a/b/</code> is the same as <code>s/a/b/1</code>.</td></tr>
<tr><td><code>sed "s/a/b/i"</code></td><td>GNU extension - Match case-insensitively.</td></tr>
<tr><td><code>sed "s/^a/b/"</code></td><td>Require that a match be at the beginning of the line.</td></tr>
<tr><td><code>sed "s/a$/b/"</code></td><td>Require that a match be at the end of the line.</td></tr>
<tr><td><code>sed "s/^a$/b/"</code></td><td>Require that a match be both at the beginning and the end - in other words, require that a match be the entire line.</td></tr>
<tr><td colspan="2"><h4>find</h4></td></tr>
<tr><td><code>find</code></td><td>Lists every file and directory in the current working directory</td></tr>
<tr><td><code>find /dir</code></td><td>Does the same for the directory you specify</td></tr>
<tr><td><code>find -name "foo"</code></td><td>Only lists things with a matching name. * can be used as a wildcard.</td></tr>
<tr><td><code>find -exec command {} \;</code></td><td>Runs <code>command</code> on everything found by <code>find</code>. <code>{}</code> is replaced by the output.</td></tr>
<tr><td colspan="2"><h4>misc</h4></td></tr>
<tr><td><code>xrandr --output &lt;display name&gt; --brightness &lt;brightness&gt;</code></td><td title="It would definitely for sure be better to change this via the monitor's built-in menus, but that requires navigating both of my monitors' built-in menus.">Janky software-side display brightness setting with xrandr</td></tr>
<tr><td><code>wget "https://example.com/file.zip" -O temp.zip; unzip temp.zip; rm temp.zip</code></td><td>Bash one-liner to unzip a file from the internet to the current directory</td></tr>
<tr><td><code>yt-dlp -x --audio-format flac --audio-quality 0 -P ~/Music/Library/ -o "%(uploader)s - %(title)s.%(ext)s"</code></td><td>My standard <a href="https://github.com/yt-dlp/yt-dlp#readme">yt-dlp</a> command for ripping music from Youtube and Soundcloud. I have an alias for this so I don't have to write it out every time.</td></tr>
<tr><td><code>alias myalias="command go here"</code></td><td>Set an alias in bash. Put this in your .bashrc or similar to make it permanent.</td></tr>
</table>
<h2>Webdev stuff</h2>
<h4>Tables</h4>
<ul>
<li>Force a <code>&lt;td&gt;</code> element not to wrap by adding the <code>white-space:nowrap;</code> CSS property to it.</li>
<li>Set the <code>table-layout</code> CSS property to <code>fixed</code> to force the the columns to be equal widths.</li>
</ul>
<h4>PHP</h4>
<ul>
<li>The <code>date()</code> function in PHP returns date information. The first argument is a format string and the second is an optional integer for a Unix timestamp. The valid format characters as of PHP 8 can be found <a href="https://www.php.net/manual/en/datetime.format.php">here</a>.<!--, and examples are listed in this table:
<details>
<summary>Show table</summary><br>
It is currently <?php echo date('l, F j, Y \a\t g:i:s A T');?><br><br>
<table class="highlightrows" style="table-layout: fixed; width: 100%;">
<tr style="font-weight: bold;"><td>Character</td><td>Output</td><td>Character</td><td>Output</td></tr>
<tr><td>Y</td><td><?php echo date("Y");?></td><td>y</td><td><?php echo date("y");?></td></tr>
<tr><td>o</td><td><?php echo date("o");?></td><td>L</td><td><?php echo date("L");?></td></tr>
<tr><td>F</td><td><?php echo date("F");?></td><td>M</td><td><?php echo date("M");?></td></tr>
<tr><td>m</td><td><?php echo date("m");?></td><td>n</td><td><?php echo date("n");?></td></tr>
<tr><td>t</td><td><?php echo date("t");?></td><td>W</td><td><?php echo date("W");?></td></tr>
<tr><td>l</td><td><?php echo date("l");?></td><td>D</td><td><?php echo date("D");?></td></tr>
<tr><td>d</td><td><?php echo date("d");?></td><td>j</td><td><?php echo date("j");?></td></tr>
<tr><td>S</td><td><?php echo date("S");?></td><td>z</td><td><?php echo date("z");?></td></tr>
<tr><td>N</td><td><?php echo date("N");?></td><td>w</td><td><?php echo date("w");?></td></tr>
<tr><td>A</td><td><?php echo date("A");?></td><td>a</td><td><?php echo date("a");?></td></tr>
<tr><td>g</td><td><?php echo date("g");?></td><td>G</td><td><?php echo date("G");?></td></tr>
<tr><td>h</td><td><?php echo date("h");?></td><td>H</td><td><?php echo date("H");?></td></tr>
<tr><td>i</td><td><?php echo date("i");?></td><td>s</td><td><?php echo date("s");?></td></tr>
<tr title="These are milliseconds and microseconds respectively. They will both return 0 when used with date() as it takes the Unix timestamp as an integer in seconds, but there are other functions that take this formatting and will return these accurately."><td>v</td><td><?php echo date("v");?></td><td>u</td><td><?php echo date("u");?></td></tr>
<tr><td title="This one is so funny to me. This is Swatch Internet Time, a time system created in 1998 by the Swatch corporation to promote their &quot;Beat&quot; watches. It divides the day into 1000 equal chunks 86.4 seconds long. I encourage you to go read the Wikipedia page for this thing. It's great. Why PHP has a function for it I have no idea.">B</td><td><?php echo date("B");?></td><td>I</td><td><?php echo date("I");?></td></tr>
<tr><td>e</td><td><?php echo date("e");?></td><td>O</td><td><?php echo date("O");?></td></tr>
<tr><td>P</td><td><?php echo date("P");?><td>Z</td><td><?php echo date("Z");?></td></tr>
<tr><td title="You can also use the function time() for this.">U</td><td colspan="3"><?php echo date("U");?></td></tr>
<tr><td>c</td><td colspan="3"><?php echo date("c");?></td></tr>
<tr><td>r</td><td colspan="3"><?php echo date("r");?></td></tr>
</table>
</details--><br><br>
The <code>strtotime()</code> function does the reverse operation, converting date strings to Unix timestamps. Storing dates as Unix timestamps and converting when needed is recommended.</li>
</ul>
<h2>Song Lyrics</h2>
<p>I don't actually have a solution for this one, I just wish there was a resource for looking up the lyrics to songs and looking up songs by their lyrics that wasn't an SEO leech site.</p>
</body>
</html>