all repos — gemini-redirect @ db8d56bcc8b1e3511666182c6dae114890315642

utils/index.html (view raw)

  1<!DOCTYPE html>
  2<html>
  3<head>
  4    <meta charset="utf-8">
  5    <title>Utilities</title>
  6    <link href="https://fonts.googleapis.com/css?family=Inconsolata|Raleway" rel="stylesheet">
  7    <link rel="stylesheet" type="text/css" href="css/theme.css">
  8    <meta name="description" content="Several utilities for almost every purpose">
  9    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
 10    <link rel="stylesheet" type="text/css" href="css/mobile.css"
 11            media="only screen and (max-width: 740px)" />
 12</head>
 13<body>
 14    <div class="card">
 15        <h1>Multipurpose utilities - miscellaneous things</h1>
 16        <p>Welcome! On this page you will find several utilities for various
 17        distinct purposes. You can use the box below to add hashtags if you
 18        want to filter out some cards, or directly search in the content</p>
 19        <input id="hashtagInput">
 20        <button onclick="addHashtag()">Add hashtag filter</button>
 21        <button onclick="clearHashtags()">Clear hashtags</button>
 22        <ul id="filters" class="horizontal"></ul>
 23    </div>
 24<div id="allcards">
 25    <div class="card">
 26        <table>
 27        <tr>
 28        <td><h1>Boot Repair Disk</h1></td>
 29        <td><ul class="filterlist horizontal">
 30            <li>linux</li><li>boot</li><li>repair</li><li>gpt</li><li>recovery</li>
 31        </ul></td>
 32        </tr>
 33        </table>
 34        <p>Small utility to fix broken laptops. It won't boot? Grab a copy of
 35        <a href="https://sourceforge.net/projects/boot-repair-cd/" target="_blank">Boot Repair</a>
 36        (<a href="https://help.ubuntu.com/community/Boot-Repair" target="_blank">wiki</a>)
 37        and fix it!</p>
 38    </div>
 39    <div class="card">
 40        <table>
 41        <tr>
 42        <td><h1>Installing <code>.rpm</code> files</h1></td>
 43        <td><ul class="filterlist horizontal">
 44            <li>linux</li><li>opensuse</li><li>install</li><li>rpm</li>
 45        </ul></td>
 46        </tr>
 47        </table>
 48        <p>You can install <code>.rpm</code> files under openSUSE with the following command:</p>
 49        <pre>sudo zypper install &lt;rpm file name&gt;.rpm</pre>
 50    </div>
 51    <div class="card">
 52        <table>
 53        <tr>
 54        <td><h1>Viewing your local IP address</h1></td>
 55        <td><ul class="filterlist horizontal">
 56            <li>linux</li><li>ipconfig</li><li>ip</li>
 57        </ul></td>
 58        </tr>
 59        </table>
 60        <p>On Windows the command is called <code>ipconfig</code>. It's very
 61        similar under Linux, yet not the same:
 62        <pre>ifconfig</pre>
 63    </div>
 64    <div class="card">
 65        <table>
 66        <tr>
 67        <td><h1>List PCI devices and system information</h1></td>
 68        <td><ul class="filterlist horizontal">
 69            <li>linux</li><li>list</li><li>pci</li><li>graphics</li><li>card</li>
 70            <li>system</li><li>version</li><li>ram</li><li>gpu</li><li>resolution</li>
 71        </ul></td>
 72        </tr>
 73        </table>
 74        <p>Lists all the available PCI devices (USB, audio, SATA controller…).
 75        For example, if you wanted to check your graphic card you could do:</p>
 76        <pre>lspci | grep VGA</pre>
 77        <p>It might also be useful to run <code>screenfetch</code> (or
 78        <code>neofetch</code>) to display more information, in a fancy way.</p>
 79    </div>
 80    <div class="card">
 81        <table>
 82        <tr>
 83        <td><h1>Evaluate expressions</h1></td>
 84        <td><ul class="filterlist horizontal">
 85            <li>linux</li><li>inline</li><li>commnad</li><li>evaluate</li><li>expression</li>
 86        </ul></td>
 87        </tr>
 88        </table>
 89        <p>You can inline commands by surrounding them between <code>`</code>
 90        (back quotes), or by putting them inside parenthesis with a
 91        <code>$</code> (dollar symbol) as prefix:</p>
 92        <pre>echo The date is `date +"%d-%m-%Y"`.
 93
 94echo Or differently $(date +"%d-%m-%Y").</pre>
 95
 96        <p>In a similar way, to use a variable, you can use <code>$VARIABLE</code>
 97        or even <code>${VARIABLE}</code> if it interfers with more text.</p>
 98    </div>
 99    <div class="card">
100        <table>
101        <tr>
102        <td><h1>Force a terminal
103        <a href="http://stackoverflow.com/a/26744968" target="_blank">*</a>
104        </h1></td>
105        <td><ul class="filterlist horizontal">
106            <li>linux</li><li>xfce</li><li>force</li><li>terminal</li><li>bash</li><li>shell</li><li>script</li>
107        </ul></td>
108        </tr>
109        </table>
110        <p>You can force a shell script to launch a terminal if it wasn't opened
111        by one (e.g., if it's an executable script and you opened it via double
112        click) by prepending the following lines to it:</p>
113        <pre>if [ ! -t 0 ]; then
114    x-terminal-emulator -e "$0"
115    exit 0
116fi</pre>
117    </div>
118    <div class="card">
119        <table>
120        <tr>
121        <td><h1>ISO burning and disk formatting</h1></td>
122        <td><ul class="filterlist horizontal">
123            <li>linux</li><li>burn</li><li>iso</li><li>usb</li><li>disk</li>
124            <li>format</li><li>list</li><li>partition</li><li>fat32</li>
125        </ul></td>
126        </tr>
127        </table>
128        <p>To <b>l</b>i<b>s</b>t all the plugged <b>bl</b>oc<b>k</b> devices:</p>
129        <pre>lsblk</pre>
130        
131        <p>For example, if you identify your USB drive and you want to burn an
132        ISO on it or to wipe it completely with zeroes (respectively), after
133        you've made sure that <b>it is not mounted</b>:</p>
134        <pre>dd status=progress if=my.iso of=/dev/sdX
135
136dd status=progress if=/dev/zero of=/dev/sdX</pre>
137        
138        <p>To create a new partition, you can run <code>fdisk</code> and follow
139        its instructions.<br />
140        To formt a partition, as FAT32 for instance, you can run:
141        <pre>mkfs -t vfat /dev/sdXY</pre>
142        
143        <p>A great tool with GUI however, it's <code>gparted</code>.</p>
144    </div>
145    <div class="card">
146        <table>
147        <tr>
148        <td><h1>Disabling the touchpad</h1></td>
149        <td><ul class="filterlist horizontal">
150            <li>linux</li><li>disable</li><li>touchpad</li><li>trackpad</li>
151        </ul></td>
152        </tr>
153        </table>
154        <p>If you're like me, you probably hate the touchpad. No problem:
155        <pre>sudo add-apt-repository ppa:atareao/atareao
156sudo apt-get update
157sudo apt-get install touchpad-indicator</pre>
158    </div>
159    <div class="card">
160        <table>
161        <tr>
162        <td><h1>Find in files</h1></td>
163        <td><ul class="filterlist horizontal">
164            <li>linux</li><li>grep</li><li>find</li><li>search</li><li>regex</li><li>files</li>
165        </ul></td>
166        </tr>
167        </table>
168        <p><code>grep</code> is a little great tool which can also search in files
169        <b>r</b>ecursively and show the line <b>n</b>umber for the matches of
170        an arbitrary <a href="http://regexr.com" target="_blank">regex</a>
171        <b>e</b>xpression:</p>
172        <pre>grep -rn '/path/to/somewhere/' -e "pattern"</pre>
173        <p>You don't know regex or need a quick refresher? Check out
174        <a href="https://www.regexone.com" target="_blank">RegexOne</a>.</p>
175        <p>You can also show the surrounding lines to those you matched by using
176        the <b>b</b>efore and <b>a</b>fter options, as follows:
177        <pre>grep -rn '/path/to/somewhere/' -B1 -A2 -e "pattern"</pre>
178    </div>
179    <div class="card">
180        <table>
181        <tr>
182        <td><h1>Environment variables</h1></td>
183        <td><ul class="filterlist horizontal">
184            <li>linux</li><li>environment</li><li>variable</li>
185        </ul></td>
186        </tr>
187        </table>
188        <p>You can define environment variables under
189        <code>/etc/environment</code>. You probably need to have superuser
190        access before you can modify that file.</p>
191    </div>
192    <div class="card">
193        <table>
194        <tr>
195        <td><h1>Octave fix</h1></td>
196        <td><ul class="filterlist horizontal">
197            <li>linux</li><li>octave</li><li>matlab</li>
198        </ul></td>
199        </tr>
200        </table>
201        <p>If Octave closes itself after plotting a function, you might want
202        to check what it's using to render them with the
203        <code>graphics_toolkit</code> command. If the output is not
204        <code>gnuplot</code>, install it via <code>apt</code>, restart Octave
205        and run <code>graphics_toolkit('gnuplot')</code>.<br />
206
207        <p>To run this command on startup, simply add it to the
208        <code>~/.octaverc</code> file.</p>
209    </div>
210    <div class="card">
211        <table>
212        <tr>
213        <td><h1>Open menu with the super key</h1></td>
214        <td><ul class="filterlist horizontal">
215            <li>linux</li><li>xfce</li><li>key</li><li>shortcut</li><li>hotkey</li>
216        </ul></td>
217        </tr>
218        </table>
219        <p>You can bind the <code>xfce4-popup-whiskermenu</code> command to
220        the super key to open the Whiskers menu.</p>
221    </div>
222    <div class="card">
223        <table>
224        <tr>
225        <td><h1>IO scheduler</h1></td>
226        <td><ul class="filterlist horizontal">
227            <li>linux</li><li>io</li><li>kernel</li><li>scheduler</li>
228        </ul></td>
229        </tr>
230        </table>
231        <p>You can check the currently selected IO scheduler by issuing:</p>
232        <pre>cat /sys/block/sda/queue/scheduler
233    noop [deadline] cfq</pre>
234    
235        <p>This means that the selected scheduler is <code>deadline</code>.
236        On my experience, <code>cfq</code> performs better (e.g., when running
237        a server). You can change it without the need for a reboot by
238        <code>echo</code>ing the desired scheduler to it (<code>su</code> first):</p>
239        <pre>su
240echo cfq > /sys/block/sda/queue/scheduler
241exit</pre>
242        
243        <p>For this change to persist, you need to tell grub
244        <a href="http://askubuntu.com/a/82452" target="_blank">*</a>:</p>
245        <pre>sudo nano /etc/default/grub
246
247# Find and replace:
248GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
249# With:
250GRUB_CMDLINE_LINUX_DEFAULT="quiet splash elevator=&lt;OPTION&gt;"
251# Where option is one of the shown above (noop, deadline or cfq)
252# Press Ctrl+X and to save and exit
253
254sudo update-grub
255</pre>
256    </div>
257    <div class="card">
258        <table>
259        <tr>
260        <td><h1>Libraries</h1></td>
261        <td><ul class="filterlist horizontal">
262            <li>linux</li><li>library</li><li>libraries</li><li>dependency</li><li>dependencies</li>
263        </ul></td>
264        </tr>
265        </table>
266        <p>If sometimes you get the error <code>cannot find -lLibrary</code>,
267        look for <code>libLibrary</code> (note the <code>lib</code> prefix) on
268        the Synaptics package manager, or directly search the missing library
269        with <code>apt-cache</code>:</p>
270        <pre>apt-cache search libLibrary*</pre>
271        
272        <p>You might want to install the <code>-dev</code> version too if you're
273        having trouble when building an application. You can list the libraries
274        a program uses by running <code>ldd &lt;program&gt;</code>.</p>
275    </div>
276    <div class="card">
277        <table>
278        <tr>
279        <td><h1>Terminal shortcuts</h1></td>
280        <td><ul class="filterlist horizontal">
281            <li>linux</li><li>terminal</li><li>shortcut</li><li>hotkey</li>
282        </ul></td>
283        </tr>
284        </table>
285        <ul>
286            <li><code>Ctrl+C</code> cancels the current program.</li>
287            <li><code>Ctrl+D</code> sends <code>EOF</code> (useful for
288            <code>cat</code> or to exit the terminal quickly rather than typing
289            <code>exit</code>.</li>
290            <li><code>Ctrl+W</code> deletes the previous word.</li>
291            <li><code>Ctrl+U</code> deletes the whole entered command.</li>
292            <li><code>Ctrl+Y</code> pastes back the cleared text.</li>
293            <li><code>Ctrl+Shift+C</code> copies the selected text.</li>
294            <li><code>Ctrl+Shift+V</code> pastes the clipboard text.</li>
295        </ul>
296    </div>
297    <div class="card">
298        <table>
299        <tr>
300        <td><h1>Desktop files</h1></td>
301        <td><ul class="filterlist horizontal">
302            <li>linux</li><li>desktop</li><li>launcher</li><li>menu</li><li>startmenu</li>
303        </ul></td>
304        </tr>
305        </table>
306        <p><code>~/.local/share/applications</code> contains the
307        <code>.desktop</code> files used to launch your applications.
308        Their format, although not standarized, is usually as follows:</p>
309        <pre>[Desktop Entry]
310Encoding=UTF-8
311Version=1.0
312Name=My Fancy App
313Comment=This is my fancy application
314Exec=/home/imthebest/My-Apps/launch
315Icon=/home/imthebest/My-Apps/app.png
316Terminal=false
317Type=Application
318Categories=Network;</pre>
319
320        <p><code>/usr/share/applications</code> for all the users.</p>
321    </div>
322    <div class="card">
323        <table>
324        <tr>
325        <td><h1>Stream YouTube music</h1></td>
326        <td><ul class="filterlist horizontal">
327            <li>linux</li><li>stream</li><li>play</li><li>youtube</li><li>music</li><li>audio</li>
328        </ul></td>
329        </tr>
330        </table>
331        <p>You can play songs from YouTube (or even <code>--shuffle</code> a
332        playlist) by using <code>mpv</code>:</p>
333        <pre>mpv --no-video https://www.youtube.com/playlist?list=blahblah</pre>
334        
335        <p>For this to work, you need to have a few things installed:</p>
336        <pre>sudo apt-get install python3-pip mpv
337sudo -H pip3 install youtube-dl</pre>
338        
339        <p>Remember to <code>reset</code> the terminal afterwards.</p>
340    </div>
341    <div class="card">
342        <table>
343        <tr>
344        <td><h1>Screen capture
345        <a href="https://trac.ffmpeg.org/wiki/Capture/Desktop" target="_blank">*</a>
346        </h1></td>
347        <td><ul class="filterlist horizontal">
348            <li>linux</li><li>screen</li><li>grab</li><li>capture</li><li>record</li>
349        </ul></td>
350        </tr>
351        </table>
352        <p>You can use <code>ffmpeg</code> not only to convert files, but also
353        to capture your screen and send it to your friends as a <code>.gif</code>:
354        <pre>ffmpeg -video_size {WIDTH}x{HEIGHT} -framerate 25 -f x11grab -i :0.0+{X},{Y} -t {DURATION} {OUTPUT}.mp4</pre>
355        <p>This can prove very useful when combined with
356        <a href="https://github.com/naelstrof/slop" target="_blank">slop</a>:
357        <pre>DURATION=10
358OUTPUT=screenrecord
359read -r X Y W H < <(slop -f "%x %y %w %h")
360ffmpeg -video_size ${W}x$H -framerate 25 -f x11grab -i :0.0+$X,$Y -t $DURATION $OUTPUT.mp4</pre>
361    </div>
362    <div class="card">
363        <table>
364        <tr>
365        <td><h1>Running commands in parallel</h1></td>
366        <td><ul class="filterlist horizontal">
367            <li>linux</li><li>execute</li><li>run</li><li>command</li>
368            <li>parallel</li><li>multithread</li><li>batch</li>
369        </ul></td>
370        </tr>
371        </table>
372        <p>The <code>parallel</code> command effectively allows you to run a
373        command in parallel, so you can get the most out of your CPU. For example,
374        let's assume you have a file called <code>urllist.txt</code> and you want
375        to <code>wget</code> them all as fast as possible:
376        <pre>cat urllist.txt | parallel --gnu "wget {}"
377
378# Or
379parallel --gnu -a urllist.txt wget
380
381# Or
382parallel --gnu wget &lt; urllist.txt
383</pre>
384    </div>
385    <div class="card">
386        <table>
387        <tr>
388        <td><h1>Move folders to RAM (RAM disk)</h1></td>
389        <td><ul class="filterlist horizontal">
390            <li>linux</li><li>ubuntu</li><li>move</li><li>folder</li><li>ram</li><li>ramdisk</li>
391        </ul></td>
392        </tr>
393        </table>
394        <p>The <code>/dev/shm</code> folder, available on some Linux distrubitions,
395        serves as a faster alternative than <code>/tmp</code>. <b>Note that
396        this is not reliable</b> and should be only used as a faster alternative
397        for temporary storage. You can "move a folder to RAM" as follows:</p>
398        <pre>$FOLDER_NAME="your_folder"
399$IN_RAM="/dev/shm/$folder_name"
400$FOLDER="$(pwd)/$FOLDER_NAME"
401
402mv "$FOLDER" "$FOLDER.packed"
403cp -r "$FOLDER.packed" "$IN_RAM"
404ln -s "$IN_RAM" "$FOLDER"</pre>
405        <p>This will rename the original folder by adding the suffix
406        <code>.packed</code> to it, copy its contents to the RAM, and
407        create a <code>symlink</code> where the previous folder was before
408        to the folder on the RAM.<br />
409        To undo this operation, simply run:
410        <pre>FOLDER_NAME="your_folder"
411IN_RAM="/dev/shm/$folder_name"
412FOLDER="$(pwd)/$folder_name"
413
414rm $FOLDER
415cp -r $IN_RAM $FOLDER
416rm -rf $IN_RAM</pre>
417        <p>This will preserve the <code>.packed</code> version since the RAM
418        may be unstable.</p>
419    </div>
420    <div class="card">
421        <table>
422        <tr>
423        <td><h1><code>MakeFile</code> refresher
424        <a href="http://mrbook.org/blog/tutorials/make/" target="_blank">*</a>
425        </h1></td>
426        <td><ul class="filterlist horizontal">
427            <li>make</li><li>makefile</li><li>build</li>
428        </ul></td>
429        </tr>
430        </table>
431        <p><code>MakeFile</code>s are an easy and powerful tool to build your
432        projects. However, if you're like me, you probably tend to forget how
433        they work too. Here's a quick refresher. Note that you <b>must use
434        the TAB character</b>. Their basic syntax is:
435        <pre>target_name:( target_dependencies)
436&#9;system command
437</pre>
438        <p>A full example would be:</p>
439        <pre>all: hello
440
441hello: main.o hello.o
442&#9;g++ main.o hello.o -o hello
443
444main.o: main.cpp
445&#9;g++ -c main.cpp
446
447hello.o: hello.cpp
448&#9;g++ -c hello.cpp
449
450clean:
451&#9;rm *.o hello</pre>
452        
453        <p>A more powerful example, introducing the use of variables:</p>
454        <pre># Compiler used
455CC=g++
456
457# Compiler flags
458CFLAGS=-c -Wall
459
460all: hello
461
462hello: main.o hello.o
463&#9;$(CC) main.o hello.o -o hello
464
465main.o: main.cpp
466&#9;$(CC) $(CFLAGS) main.cpp
467
468hello.o: hello.cpp
469&#9;$(CC) $(CFLAGS) hello.cpp
470
471clean:
472&#9;rm *.o hello</pre>
473        
474        <p>You can execute the default one by running <code>make</code>,
475        or a specific one with <code>make -f MyMakefile</code>.
476    </div>
477    <div class="card">
478        <table>
479        <tr>
480        <td><h1><code>.gif</code> tricks with FFmpeg</h1></td>
481        <td><ul class="filterlist horizontal">
482            <li>ffmpeg</li><li>convert</li><li>video</li><li>avi</li><li>mp4</li><li>gif</li>
483        </ul></td>
484        </tr>
485        </table>
486        <p><a href="http://ffmpeg.org/" target="_blank">FFmpeg</a> is not only
487        to convert between video and audio formats. It can also convert images
488        (like <code>.webp</code> to <code>.png</code>), and even <code>.gif</code>s:</p>
489        <pre>ffmpeg -i in.mp4 -framerate 10 out.gif</pre>
490        <p>Perhaps the generated file is too large. You can scale to a given size,
491        by either constraining the width, height (the other option will be
492        <code>-1</code>), or both:</p>
493        <pre>ffmpeg -i in.mp4 -framerate 10 -vf "scale=150:-1" out.gif</pre>
494    </div>
495    <div class="card">
496        <table>
497        <tr>
498        <td><h1>Multiple images to video with FFmpeg
499        <a href="http://ffmpeg.org/ffmpeg.html#Video-and-Audio-file-format-conversion" target="_blank">*</a>
500        </h1></td>
501        <td><ul class="filterlist horizontal">
502            <li>ffmpeg</li><li>convert</li><li>multiple</li><li>many</li>
503            <li>images</li><li>video</li><li>avi</li><li>mp4</li><li>gif</li>
504        </ul></td>
505        </tr>
506        </table>
507        <p>Extracting images from a video:</p>
508        <pre>ffmpeg -i in.mp4 -r 1 -s WxH -f image2 out-%03d.jpg</pre>
509        <p>This will extract one video frame per second from <code>in.mp4</code>
510        with the <b>s</b>ize <code>WxH</code> and to <code>out-nnn.jpg</code>.
511        The format <code>%03d</code> on the name specifies 3 digits, 0 padded.
512        <br />
513        If on the other hand you wanted to extract all the images, you can
514        drop the <code>-r 1</code> option, and even the <code>-s</code> option,
515        exactly leaving alone:</p>
516        <pre>ffmpeg -i in.mp4 out%d.jpg</pre>
517        <p>The reverse process, converting many images to a video:</p>
518        <pre>ffmpeg -f image2 -framerate 12 -i in-%03d.jpg -s WxH out.mp4</pre>
519    </div>
520    <div class="card">
521        <table>
522        <tr>
523        <td><h1>Background processes</h1></td>
524        <td><ul class="filterlist horizontal">
525            <li>linux</li><li>background</li><li>process</li><li>processes</li>
526            <li>terminal</li><li>bash</li><li>shell</li>
527        </ul></td>
528        </tr>
529        </table>
530        <p>You can press <kbd>Ctrl+Z</kbd> to send a running process to the
531        background, use <code>jobs</code> to see which have you sent, and
532        <code>fg n</code> to bring them back to foreground.</p>
533    </div>
534</div> <!-- div id="allcards" -->
535
536<script src="js/utils.js"></script>
537<script src="js/hashtags.js"></script>
538</body>
539</html>