Project

General

Profile

Miscellaneous » History » Version 14

Anonymous, 12/18/2023 02:02 PM
adding sshuttle

1 1
h1. Miscellaneous
2
3 14
h2. sshuttle
4
5
<pre>
6
$ sshuttle --dns -NHr dsorber@phalanx.homelinuxserver.org:3268  192.168.0.0/16
7
</pre>
8
9 13
h2. Batch Convert PNG to JPG
10
11
NOTE: @convert@ comes from ImageMagick
12
<pre>
13
& ls -1 *.png | parallel --eta convert '{}' -quality 90 '{.}.jpg'
14
</pre>
15
16 12
h2. Crop Video with ffmpeg
17
18
<pre>
19
$ ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4
20
</pre>
21
22
* @out_w@ is the width of the output rectangle
23
* @out_h@ is the height of the output rectangle
24
* @x@ and @y@ specify the top left corner of the output rectangle (coordinates start at (0,0) in the top left corner of the input) 
25
26
Test using @ffplay@:
27
<pre>
28
$ ffplay -i input -vf "crop=out_w:out_h:x:y"
29
</pre>
30
31 10
h2. Build Custom Windows ISOs
32
33
* https://uupdump.net/
34 11
* https://forums.mydigitallife.net/threads/kms_vl_all-smart-activation-script.79535/
35 10
36 9
h2. Script to Convert Local manpages to html
37
38
Note use @zcat@ if the manpages are compressed:
39
40
<pre>
41
#!/bin/bash
42
43
mkdir -p html
44
for file in *; do
45
        if [ -f $file ] && [ "${file: -3}" != ".sh" ]; then
46
                echo $file
47
                #echo "${file%.*}"
48
                pandoc --from man --to html < $file > html/${file%.*}.html
49
        fi
50
done
51
</pre>
52
53 6
h2. Display Total rsync Progress
54
55
<pre>
56 7
$ rsync -a --no-i-r --info=progress2 /path/to/src /path/to/dest/
57 6
</pre>
58
59
NOTE: @-v@ does not work with @--info=progress2@
60
61
Source: https://serverfault.com/a/441724/472586
62
63 5
h2. Slice Video File 
64
65
<pre>
66
$ ffmpeg -ss 00:01:00 -to 00:02:00  -i input.mp4 -c copy output.mp4
67
</pre>
68
69
Explanation of the command:
70
71
* -i: This specifies the input file. In that case, it is (input.mp4).
72
* -ss: Used with -i, this seeks in the input file (input.mp4) to position.
73
* 00:01:00: This is the time your trimmed video will start with.
74
* -to: This specifies duration from start (00:01:40) to end (00:02:12).
75
* 00:02:00: This is the time your trimmed video will end with.
76
* -c copy: This is an option to trim via stream copy. (NB: Very fast)
77
78 4
h2. Add new drive SW RAID5
79
80
# Format drive if needed (see below for steps).
81
# Add new drive to SW RAID:
82
<pre>
83
$ sudo mdadm --manage /dev/md0 --add /dev/sdd1
84
</pre>
85
# Grow array:
86
<pre>
87
$ sudo mdadm --grow --raid-devices=4 /dev/md0
88
</pre>
89
90
h2. Replace failed SW RAID drive
91
92
# If drive is brand new be sure to create a partition on it:
93
<pre>
94
sorber@file2:~$ sudo parted /dev/sdg
95
GNU Parted 3.3
96
Using /dev/sdg
97
Welcome to GNU Parted! Type 'help' to view a list of commands.
98
(parted) mklabel gpt
99
(parted) mkpart primary 2048s 100%                                        
100
(parted) print                                                            
101
Model: ATA ST2000DM008-2FR1 (scsi)
102
Disk /dev/sdg: 2000GB
103
Sector size (logical/physical): 512B/4096B
104
Partition Table: gpt
105
Disk Flags: 
106
107
Number  Start   End     Size    File system  Name     Flags
108
 1      1049kB  2000GB  2000GB               primary
109
110
(parted) quit
111
</pre>
112
# If needed, mark bad drive as failed:
113
<pre>
114
$ sudo mdadm --manage /dev/md0 --fail /dev/sdd
115
</pre>
116
# Add new drive to replace failed:
117
<pre>
118
$ sudo mdadm --manage /dev/md0 --add /dev/sdd1 /dev/sdg1
119
</pre>
120
# Improve rebuild speed slightly:
121
<pre>
122
$ sudo bash -c "echo 9999999 > /proc/sys/dev/raid/speed_limit_min"
123
$ sudo bash -c "echo 9999999 > /proc/sys/dev/raid/speed_limit_max"
124
</pre>
125
# Monitor rebuild:
126
<pre>
127
$ watch -n1 cat /proc/mdstat 
128
</pre>
129
130
h2. Get detailed drive information
131
132
<pre>
133
$ udevadm info --query=all --name=/dev/sda
134
</pre>
135
136 1
h2. Split flac with cue
137
138
<pre>
139
$ sudo apt install cuetools shntool
140
141
$ shnsplit -f file.cue -t %n-%t -o flac file.flac
142
</pre>
143
144
h2. Fix Chrome Display Glitches
145
146
Somewhere around Chrome 86 display glitches started happening on wake. Here is how to fix:
147
148 3
Enabling @enable-vulkan@ in @chrome://flags@ then restarting the browser fixed it. If that does not work, you can also try enabling `ignore-gpu-blacklist` as well.
149 1
150
h2. Setup SSH Public Key
151
152
# On host machine generate a key pair. This key can be reused for multiple remote machines so it's not really necessary to change the name unless multiple keys are generated, which is also not really needed.
153
<pre>
154
$ ssh-keygen -t rsa
155
</pre>
156 3
 *NOTE:* for NetBeans to use/recognize the ssh key you must use the old PEM format:
157 1
<pre>
158
$ ssh-keygen -m PEM -t rsa
159
</pre>
160
# Now use `ssh-copy-id` to copy the key to the remote machine (for example):
161
<pre>
162
$ ssh-copy-id -i ~/.ssh/phalanx_rsa.pub dsorber@phalanx
163
</pre>
164
165
h2. Read Windows Product Key from ACPI Firmware
166
167
Boot into Linux and run:
168
169
<pre>
170
$ sudo strings /sys/firmware/acpi/tables/MSDM
171
</pre>
172
173
h2. Windows 10 Install and SysPrep Instructions
174
175
Very good instructions: https://theitbros.com/sysprep-windows-10-machine-guide/
176
177
178
h2. Search and Replace on Binary Files
179
180
A good hex editor can do search and replace on binary files but sometimes that's not practical:
181
182
* BBE - https://sourceforge.net/projects/bbe-/
183
 BBE is a binary editor with SED-like syntax:
184
<pre>
185
$ bbe -e 's/\x0a\x0d\x0a/\x0d\x0a/' infile > outfile
186
</pre>
187
* binwalk - https://github.com/ReFirmLabs/binwalk
188
 binwalk can search for hex strings (and do many other things)
189
<pre>
190
$ binwalk -R "\x0a\x0d\x0a" infile
191
192
WARNING: Signature '0    string    \x0a\x0d\x0a    Raw signature (\x0a\x0d\x0a)' is a self-overlapping signature!
193
194
DECIMAL       HEXADECIMAL     DESCRIPTION
195
--------------------------------------------------------------------------------
196
242           0xF2            Raw signature (\x0a\x0d\x0a)
197
412           0x19C           Raw signature (\x0a\x0d\x0a)
198
580           0x244           Raw signature (\x0a\x0d\x0a)
199
749           0x2ED           Raw signature (\x0a\x0d\x0a)
200
. . .
201
</pre>
202
203
h2. Wake-on-LAN WOL
204
205
Must be enabled on interface; need MAC
206
<pre>
207
$ sudo apt install etherwake
208
$ sudo etherwake <target MAC> -i <outgoing interface>
209
210
$ sudo etherwake b4:2e:99:a5:1e:f0 -i enp30s0
211
</pre>
212
213
h2. Allocator Shim
214
215
From Chromium, this is really interesting
216
* https://chromium.googlesource.com/chromium/src/base/+/master/allocator/README.md
217
218
However it is not clear how to use it outside of Chromium.
219
220
h2. Update Geany
221
222
# Install prereq packages (this obviously only needs to be done once):
223
<pre>
224
$ sudo apt install libgtk-3-dev libgtkspell-dev libgtkspell3-3-dev
225
</pre>
226
# Set compile flags:
227
<pre>
228
$ export CFLAGS="-O3 -march=native" 
229
$ export CXXFLAGS=$CFLAGS
230
</pre>
231
# Build geany and set to install in /opt so it won't collide with the packaged version:
232
<pre>
233
$ tar xf geany-1.30.tar.bz2
234
$ cd geany-1.30/
235
$ ./configure --prefix=/opt/local --enable-gtk3
236
$ make -j20
237
$ sudo make install
238
</pre>
239
# Set PKG_CONFIG_PATH environment variable so we can build the plugins.
240
<pre>
241
$ export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig/
242
</pre>
243
# Build geany-plugins:
244
<pre>
245
$ tar xf geany-plugins-1.30.tar.bz2 
246
$ cd geany-plugins-1.30/
247
$ ./configure --prefix=/opt/local --enable-gtk3
248
$ make -j20
249
$ sudo make install
250
</pre>
251
252
h2. Find and replace across multiple files
253
254
<pre>
255
$ find /home/www -type f -print0 | xargs -0 sed -i 's/subdomainA\.example\.com/subdomainB.example.com/g'
256
</pre>
257
258
h2. Useful IPMI commands
259
260
261
Power measurement on the SuperMicro (probably won't work on Dell chassis as they have some proprietary version of ipmi):
262
263
<pre>
264
sudo ipmitool -U ADMIN -P ADMIN -H 10.17.136.108 dcmi power reading
265
</pre>
266
267
Check power status (i.e. on/off) of chassis:
268
<pre>
269
sudo ipmitool -U ADMIN -P ADMIN -H 10.17.70.45 power status
270
sudo ipmitool -U ADMIN -P ADMIN -H 10.17.70.45 power off
271
</pre>
272
273
Get IPMI IP address (look for "IP Address"):
274
<pre>
275
sudo ipmitool lan print 
276
</pre>
277
278
h2. Full sshfs Connect Command
279
280
<pre>
281
sudo sshfs -o idmap=user -o uid=$(id -u) -o gid=$(id -g) -o allow_other -o follow_symlinks ryftuser@sm-X11DGQ:/home/ryftuser /mnt/sm-X11DGQ/
282
</pre>
283
284
h2. Side-by-side Color Diff
285
286
<pre>
287
$ sudo apt-get install colordiff
288
$ colordiff -y --suppress-common-lines data.txt /ryftone/data.txt
289
</pre>
290
291
h2. x86 ABI
292
293
* https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI
294
295
h2. clang-format and clang-tidy
296
297
* http://www.labri.fr/perso/fleury/posts/programming/using-clang-tidy-and-clang-format.html
298
299
h2. Shared Library and Related Resources
300
301
* http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
302
* https://blog.qt.io/blog/2011/10/28/rpath-and-runpath/
303
* http://www.bnikolic.co.uk/blog/linux-ld-debug.html
304
* http://insanecoding.blogspot.com/2012/07/creating-portable-linux-binaries.html
305
* https://stackoverflow.com/questions/4156055/static-linking-only-some-libraries
306
307
h2. Ubuntu: List Grub Entries
308
309
<pre>
310
gawk  'BEGIN {                                                                                                                       
311
  l=0                                                                                                                                
312
  menuindex= 0                                                                                                                       
313
  stack[t=0] = 0                                                                                                                     
314
}                                                                                                                                    
315
316
function push(x) { stack[t++] = x }                                                                                                  
317
318
function pop() { if (t > 0) { return stack[--t] } else { return "" }  }                                                              
319
320
{                                                                                                                                    
321
322
if( $0 ~ /.*menu.*{.*/ )                                                                                                             
323
{                                                                                                                                    
324
  push( $0 )                                                                                                                         
325
  l++;                                                                                                                               
326
327
} else if( $0 ~ /.*{.*/ )                                                                                                            
328
{                                                                                                                                    
329
  push( $0 )                                                                                                                         
330
331
} else if( $0 ~ /.*}.*/ )                                                                                                            
332
{                                                                                                                                    
333
  X = pop()                                                                                                                          
334
  if( X ~ /.*menu.*{.*/ )                                                                                                            
335
  {                                                                                                                                  
336
     l--;                                                                                                                            
337
     match( X, /^[^'\'']*'\''([^'\'']*)'\''.*$/, arr )                                                                               
338
339
     if( l == 0 )                                                                                                                    
340
     {                                                                                                                               
341
       print menuindex ": " arr[1]                                                                                                   
342
       menuindex++                                                                                                                   
343
       submenu=0                                                                                                                     
344
     } else                                                                                                                          
345
     {                                                                                                                               
346
       print "  " (menuindex-1) ">" submenu " " arr[1]                                                                               
347
       submenu++                                                                                                                     
348
     }                                                                                                                               
349
  }                                                                                                                                  
350
}                                                                                                                                    
351
352
}' /boot/grub/grub.cfg
353
</pre>
354
355
* https://askubuntu.com/a/941993/392271
356
357
358
h2.GCC Disable Unused Variable Warnings
359
360
<pre>
361
#pragma GCC diagnostic push
362
#pragma GCC diagnostic ignored "-Wunused-variable"
363
( your problematic library includes )
364
#pragma GCC diagnostic pop
365
</pre>
366
367
See: https://stackoverflow.com/a/22708539/73878
368
369
h2. Fix Steam after NVidia driver update
370
371
Since this has now bitten me twice... Steam requires the 32 bit version of the GL library.
372
373
<pre>
374
$ sudo apt install libnvidia-gl-418:i386
375
</pre>
376
377
h2. Restart Cinnamon from TTY
378
379
# Cinnamon freezes
380
# Switch tty. I usually go to tty6, `Ctrl+Alt+F6`
381
# If you need to login first, do so.
382
# Type `w` (yes, just the letter) and press enter. This commands does a lot of different things, but you need it to figure out the number of the display you are using. The display number is in the column FROM. Mine is `:0` (yes, including the colon).
383
# Assuming that cinnamon is already dead (which you would notice by the windows lacking titles and that you can't move different windows around, and perhaps even not being able to use the keyboard), you type `export DISPLAY=:0; cinnamon &`, and don't forget the colon. I add the ampersand (&) only not to keep that tty busy.
384
385
Sauce: https://askubuntu.com/a/198935/392271
386
387
h2. Ubuntu Set Specific Kernel to Boot
388
389
* Use this command to get a list of available options:
390
<pre>
391
$ grep -Ei 'submenu|menuentry ' /boot/grub/grub.cfg | sed -re "s/(.? )'([^']+)'.*/\1 \2/"
392
menuentry  Ubuntu
393
submenu  Advanced options for Ubuntu
394
    menuentry  Ubuntu, with Linux 4.4.0-34-generic
395
    menuentry  Ubuntu, with Linux 4.4.0-34-generic (upstart)
396
    menuentry  Ubuntu, with Linux 4.4.0-34-generic (recovery mode)
397
menuentry  System setup
398
</pre>
399
* Backup grub configuration, just in case:
400
<pre>
401
$ sudo cp /etc/default/grub /etc/default/grub.bak
402
</pre>
403
* Edit grub configuration and change `GRUB_DEFAULT` to something like this:
404
<pre>
405
$ sudo vim /etc/default/grub
406
407
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-53-generic"
408
</pre>
409
* Update grub configuration
410
<pre>
411
$ sudo update-grub
412
</pre>
413
* See also: https://askubuntu.com/questions/216398/set-older-kernel-as-default-grub-entry
414
415
h2. Ubuntu Networking Resources
416
417
* https://blog.ubuntu.com/2017/12/01/ubuntu-bionic-netplan
418
* https://help.ubuntu.com/lts/serverguide/network-configuration.html.en
419
* https://netplan.io/
420
421
h2. Win10 Licensing Info
422
423
* https://www.windowscentral.com/how-change-product-key-windows-10
424
* https://www.tenforums.com/tutorials/49586-determine-if-windows-license-type-oem-retail-volume.html
425
* https://www.tenforums.com/windows-updates-activation/104569-win-10-activation-expiring-volume-license.html
426
427
h2. Python GTK Development Resources
428
429
* https://python-gtk-3-tutorial.readthedocs.io/en/latest/layout.html
430
* https://lazka.github.io/pgi-docs/Gtk-3.0/classes/Box.html#Gtk.Box.pack_start
431
* https://lazka.github.io/pgi-docs/Gtk-3.0/mapping.html
432
433
h2. cpufrequtils Governor Configuration
434
435
These instructions are intended for Ubuntu 16.04 and later (using systemd init).
436
437
* Check the available and currently set governors. Ubuntu has an โ€œondemandโ€ service that sets the governor to ondemand after boot.
438
<pre>
439
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
440
conservative ondemand userspace powersave performance schedutil
441
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 
442
ondemand
443
</pre>
444
445
* Configure cpufrequtils to set the governor to performance at boot
446
<pre>
447
$ echo 'GOVERNOR="performance"' | sudo tee /etc/default/cpufrequtils
448
GOVERNOR="performance"
449
</pre>
450
451
* Disable the automatic ondemand service. 
452
<pre>
453
$ sudo systemctl disable ondemand
454
</pre>
455
456
* Reboot.
457
458
* Now check that the governor is set to performance for every CPU:
459
<pre>
460
$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
461
performance
462
performance
463
performance
464
performance
465
โ€ฆ
466
performance
467
performance
468
performance
469
</pre>
470
471
* Check current CPU speeds:
472
<pre>
473
$ watch -n 1 bash -c 'cpufreq-info | grep "current CPU frequency"'
474
</pre>
475
476
h2. rsync via ssh example
477
478
<pre>
479
$ rsync --info=progress2 -ahz --compress-level=9 -e "ssh -i ~/ryft-pat-f1.pem" data/ ryftuser@18.205.65.5:/ryftone/regression/pubmed/data/
480
</pre>
481
482
h2. Read Performance using AIO
483
484
Use this fio command (run from temp directory on disk in question) to measure max disk read performance:
485
486
<pre>
487
$ fio --name TEST --eta-newline=5s --filename=fio-tempfile.dat --rw=read --size=10g --io_size=10g --blocksize=512k --ioengine=libaio --fsync=0 --iodepth=32 --direct=1 --numjobs=1 --runtime=300 --group_reporting
488
</pre>
489
490
Note that DIRECT_IO is required when using AIO. (see also: https://askubuntu.com/a/991311/392271)
491
492
h2. Remove Source Files While Creating Tarball
493
494
This is handy as it saves on disk space.
495
<pre>
496
$ tar --remove-files -cf pictures.tar Pictures/
497
</pre>
498
499
h2. Linux Find and Remove Files
500
501
Find and remove files (even with spaces in the path) using case insensitive matching for the wildcard:
502
<pre>
503
$ find . -type f -iname "*.jpg" -print0 | xargs -0 rm
504
</pre>
505
506
h2. Convert ASCII hex to binary
507
This problem seems to come up every so often. There is no need for a one-off solution:
508
509
<pre>
510
$ xxd -r -p input.txt output.bin
511
</pre>
512
513
https://stackoverflow.com/questions/7826526/transform-a-hex-info-to-binary-using-linux-command
514
515
h2. Well Said
516
517
https://developers.slashdot.org/comments.pl?sid=12326098&cid=56908942
518
519
h2. Hex Editor
520
521
I had been using [[https://hexinator.com/|Hexinator]] but I've had some minor issues with it. Today I tried [[https://www.wxhexeditor.org/home.php|wxHexEditor]] and I was pleasantly surprised.
522
523
Download from here: https://github.com/EUA/wxHexEditor
524
525
You'll need the latest version of libwxgtk<version>-dev package.
526
527
I had some minor issues with the build (which seems a somewhat bizarre arrangement...) modify the makefile to set `CC` and `CXX` directly, right about line 90.
528
529
Finally, to get it installed in the right place:
530
<pre>
531
sudo make install DESTDIR=/opt/local BINDIR=bin DATADIR=share
532
</pre>
533
534
h2. Preprocessor Fun
535
536
To invoke the preprocessor directly:
537
<pre>
538
gcc -E -DSOME_DEFINE=SOME_VALUE somefile.c 
539
</pre>
540
541
See also [[https://linux.die.net/man/1/unifdef|unifdef]]: "The unifdef utility acts on #if, #ifdef, #ifndef, #elif, #else, and #endif lines, and it understands only the commonly-used subset of the expression syntax for #if and #elif lines."
542
543
h2. Convert Oversampled .flac to 16 bit 44.1 khz .flac
544
545
<pre>
546
mkdir -p output && find . -type f -name "*.flac" | parallel -j16 "sox {} -b 16 -r 44100 output/{/.}.flac"
547
548
mkdir -p output && find . -type f -name "*.flac" | parallel -j16 "sox -v 0.98 {} -b 16 -r 44100 output/{/.}.flac"
549
</pre>
550
551
h2. Aligned C++ STL Types
552
553
<pre>
554
#include <vector>
555
#include <boost/align/aligned_allocator.hpp>
556
557
template <typename T>
558
using aligned_vector = std::vector<T, boost::alignment::aligned_allocator<T, 4096>>;
559
</pre>
560
561
h2. Command line convert .png to .jpg
562
563
<pre>
564
$ for x in *.png; do convert $x $(basename $x .png).jpg; done
565
</pre>
566
567
You can also add the "`-quality 90`" option if needed.
568
569
h2. Determine CPU Family Name
570
571
<pre>
572
$ gcc -march=native -Q --help=target|grep march
573
</pre>
574
575
h2. Convert .flac to .m4a (AAC)
576
577
Requires `ffmpeg` built with libfdk_aac:
578
579
<pre>
580
$ /opt/bin/ffmpeg -i input.flac -vn -c:a libfdk_aac -vbr 3 output.m4a
581
</pre>
582
583
All together using `find` and `parallel` for magic:
584
<pre>
585
$ find . -type f -name "*.flac" | parallel -j16 "/opt/bin/ffmpeg -i {} -vn -c:a libfdk_aac -vbr 4 {/.}.m4a"
586
</pre>
587
588
h2. PyGObject
589
590
This is the magic needed to have stuff happen quasi asynchronously using PyGObject (GTK+):
591
592
<pre>
593
# Yield to the main loop temporarily
594
while Gtk.events_pending():
595
    Gtk.main_iteration()
596
</pre>
597
598
h2. FUSE Code
599
600
 *https://pastebin.com/wavKntiu
601
602
h2. Use Windoze Schtuffs
603
604
 * https://support.microsoft.com/en-gb/help/17588/fix-problems-that-block-programs-from-being-installed-or-removed (gotta love how this requires a separate program)
605
 * [[http://landinghub.visualstudio.com/visual-cpp-build-tools|MSVC Tools]] - compiler (seems to be the rough equivalent of `build-essential`)
606
 * [[https://docs.microsoft.com/en-us/sysinternals/downloads/procmon|Process Monitor]] - useful debug tool
607
  * https://www.codeproject.com/Articles/560816/Troubleshooting-dependency-resolution-problems-usi - example for using Process Monitor
608
 * http://download.microsoft.com/download/7/2/E/72E0F986-D247-4289-B9DC-C4FB07374894/wdexpress_full.exe - (required by wingtk below)
609
 
610
* https://github.com/wingtk/gvsbuild - haven't tried this yet but looks amazing... 
611
612
h2. Build Handbrake Git Build
613
614
Steps for building Handbrake using AOCC:
615
616
<pre>
617
$ source /home/dsorber/Downloads/aocc/setenv_AOCC.sh
618
$ export CC=clang
619
$ export CXX=clang++
620
$ export CFLAGS="-g -O3 -mtune=native"
621
$ export CXXFLAGS=$CFLAGS
622
$ cd ~/Downloads/HandBrake/
623
$ rm -rf build/
624
$ ./configure --prefix=/opt --enable-x265 --enable-fdk-aac --gcc=/home/dsorber/Downloads/aocc/AOCC-1.1-Compiler/bin/clang
625
$ cd build
626
$ make -j17
627
$ sudo make install
628
</pre>
629
630
----
631
632
Regular build (18.04 and later):
633
<pre>
634
$ rm -rf build/
635
$ ./configure --prefix=/opt/local --enable-x265 --enable-fdk-aac
636
$ cd build
637
$ make -j17
638
$ sudo make install
639
</pre>
640
641
h2. Politically Correct Linux
642
643
* https://entertainment.slashdot.org/comments.pl?sid=11493671&cid=55759997
644
645
h2. This guy gets it
646
647
Regarding software purist ideology vs pragmatism
648
649
* https://linux.slashdot.org/comments.pl?sid=11156367&cid=55256437
650
651
h2. "Rotate" Video Playback via Metadata
652
653
<pre>
654
$ ffmpeg -i input.mp4 -c copy -metadata:s:v:0 rotate=90 output.mp4
655
</pre>
656
657
658
h2. Ubuntu Remove Old Kernels Oneliner
659
660
<pre>
661
$ sudo apt-get purge $(for tag in "linux-image" "linux-headers"; do dpkg-query -W -f'${Package}\n' "$tag-[0-9]*.[0-9]*.[0-9]*" | sort -V | awk 'index($0,c){exit} //' c=$(uname -r | cut -d- -f1,2); done)
662
</pre>
663
664
* [[https://askubuntu.com/questions/2793/how-do-i-remove-old-kernel-versions-to-clean-up-the-boot-menu/571360#571360|Sauce]]
665
666
h2. Remove New Lines (command line)
667
668
For a file:
669
<pre>
670
$ tr -d '\n' < yourfile.txt
671
</pre>
672
673
Or for output of a command (e.g.):
674
<pre>
675
$ find . -type f -name '*.txt' | tr -d '\n'
676
</pre>
677
678
h2. Convert from .mp4 to .mkv Container
679
680
Use `avconv` to convert container without re-encoding:
681
<pre>
682
$ sudo apt-get install libav-tools
683
684
$ avconv -i filme.mp4 -c copy filme.mkv
685
</pre>
686
687
h2. Remove String From Many File Names
688
689
On Ubuntu use Perl rename utility, e.g.:
690
691
<pre>
692
$ rename 's/ \(1920x1080\) \[WaifuKenny\]//' *.mp4
693
</pre>
694
695
h2. Change Default Text Editor
696
697
I always have to Google this...
698
699
<pre>
700
$ sudo update-alternatives --config editor
701
</pre>
702
703
h2. Linux View System RAM Speed
704
705
View RAM speed (actual) on Debian/Ubuntu/Mint:
706
707
<pre>
708
$ sudo lshw -short -C memory
709
H/W path                      Device      Class          Description
710
====================================================================
711
/0/0                                      memory         64KiB BIOS
712
/0/b                                      memory         32GiB System Memory
713
/0/b/0                                    memory         [empty]
714
/0/b/1                                    memory         16GiB DIMM Synchronous 2134 MHz (0.5 ns)
715
/0/b/2                                    memory         [empty]
716
/0/b/3                                    memory         16GiB DIMM Synchronous 2134 MHz (0.5 ns)
717
/0/d                                      memory         768KiB L1 cache
718
/0/e                                      memory         4MiB L2 cache
719
/0/f                                      memory         16MiB L3 cache
720
</pre>
721
722
h2. Linux Memory Schtuff
723
724
* [[https://github.com/jbert/exmap|exmap]]
725
* https://jameshunt.us/writings/smaps.html
726
* https://techtalk.intersec.com/2013/07/memory-part-2-understanding-process-memory/
727
* http://bmaurer.blogspot.com/2006/03/memory-usage-with-smaps.html
728
729
* https://github.com/torvalds/linux/blob/master/Documentation/filesystems/proc.txt
730
731
* From: http://stackoverflow.com/questions/24484481/entry-in-proc-meminfo
732
<pre>
733
  2. Active(file), Inactive(file) has file back-end which means its original file is in disk but to use it faster it was loaded on RAM.
734
</pre>
735
736
737
* From: http://unix.stackexchange.com/questions/56879/tracking-down-missing-memory-usage-in-linux
738
739
  The "memory used by a process" is not a clear cut concept in modern operating systems. What can be measured is the size of the address space of the process (SIZE) and resident set size (RSS, how many of the pages in the address space are currently in memory). Part of RSS is shared (most processes in memory share one copy of glibc, and so for assorted other shared libraries; several processes running the same executable share it, processes forked share read-only data and possibly a chunk of not-yet-modified read-write data with the parent). On the other hand, memory used for the process by the kernel isn't accounted for, like page tables, kernel buffers, and kernel stack. In the overall picture you have to account for the memory reserved for the graphics card, the kernel's use, and assorted "holes" reserved for DOS and other prehistoric systems (that isn't much, anyway).
740
741
  The only way of getting an overall picture is what the kernel reports as such. Adding up numbers with unknown overlaps and unknown left outs is a nice exercise in arithmetic, nothing more.
742
743
 * [[http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html|Understanding memory usage on Linux]]
744
745
 * https://linux-mm.org/LinuxMM
746
747
h2. Reinstall grub on UEFI System
748
749
Reinstalling grub on a UEFI system is slightly different than on a traditional legacy BIOS system:
750
751
<pre>
752
# Mount the primary drive root partition and the boot EFI partition
753
sudo mount /dev/sda# /mnt            # Mount root (/) partition
754
sudo mount /dev/sda# /mnt/boot       # Mount boot (/boot) partition (if separate from root partition; typically not)
755
756
sudo mkdir -p /mnt/boot/efi          # Create EFI partition mount point
757
sudo mount /dev/sda1 /mnt/boot/efi   # Mount EFI partition
758
759
# Mount your virtual filesystems:
760
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
761
762
# Chroot
763
sudo chroot /mnt
764
</pre>
765
766
Now, if you have networking you'll need DNS. If using `resolvconf` (for recent versions of Ubuntu):
767
768
# Edit ` /etc/resolvconf/resolv.conf.d/head` and add the following line (OpenDNS server).  Then save and exit:
769
<pre>
770
add nameserver 208.67.222.222
771
</pre>
772
# Next enable updates and update:
773
<pre>
774
sudo resolvconf --enable-updates
775
sudo resolvconf -u
776
</pre>
777
# Now you should have DNS. Test by pinging something.
778
779
Finally, back to fixing grub. Note that the grub install should run smoothly with no errors or warnings. If you see any something is probably wrong.
780
<pre>
781
apt-get install grub-efi-amd64  # Install grub EFI bootloader (this should be all you need to do)
782
783
784
# manual steps if you need them for some reason
785
grub-install --recheck --no-floppy --force /dev/sda1  # Install grub bootloader in EFI partition
786
787
#####
788
echo "configfile (hd0,gpt#)/boot/grub.cfg" > /boot/efi/ubuntu/grub.cfg # Tell grub to load grub.cfg from /boot
789
790
update-grub                          # Create grub menu list
791
#####
792
793
exit                                 # Exit chroot
794
</pre>
795
796
Reboot and you should be back in business.
797
798
h2. Convert flac to VBR mp3 using ffmpeg/lame
799
800
<pre>
801
for file in *.flac; do name=$(echo $file | sed "s/\.flac//g"); ffmpeg -i "$file" -codec:a libmp3lame -qscale:a 0 "$name".mp3; done
802
</pre>
803
804
h2. Create UEFI/legacy BIOS Bootable ISO
805
806
* http://askubuntu.com/questions/625286/how-to-create-uefi-bootable-iso
807
808
h2. Getting rEFInd to work on Mac OS 10.11
809
810
* http://mattjanik.ca/blog/2015/10/01/refind-on-el-capitan/
811
812
h2. Convert DTS 5.1 to FLAC
813
814
<pre>
815
sudo apt-get install libdca-utils ffmpeg sound-juicer gnome-terminal easytag vlc 
816
817
for file in *.wav; do name=$(echo $file | sed "s/\.wav//g"); dcadec -o wavall "$file" > "$name"_decoded.wav; ffmpeg -i "$name"_decoded.wav "$name".flac; rm -f "$file" "$name"_decoded.wav; done
818
</pre>
819
820
Source: http://ubuntuforums.org/archive/index.php/t-1849260.html
821
822
h2. Windows Utils
823
824
* http://windirstat.info/download.html
825
* https://www.raymond.cc/blog/safely-delete-unused-msi-and-mst-files-from-windows-installer-folder/
826
827
h2. SSH Security
828
829
https://stribika.github.io/2015/01/04/secure-secure-shell.html
830
831
h2. Windows 10
832
833
* http://ultimateoutsider.com/downloads/ - GWX Control Panel to disable GWX (Windows 10 update nagging)
834
* [[https://www.safer-networking.org/spybot-anti-beacon/|Spybot Anti-Beacon]] - Disable Micro$oft "telemetry" data gathering from Windows 10, 8.x, and 7
835
836
<pre>
837
The newest version of the KB3035583 update includes a background process which scans the 
838
system's Windows Registry twice a day to see if the values for the four aforementioned registry 
839
inputs were manually edited to disable the upgrade prompt. If they were, the process will alter 
840
the values, silently re-download the Windows 10 installation files (about 6 GB in total), and 
841
prompt the user to upgrade.
842
</pre>
843
844
845
h2. gpg-agent
846
847
* http://www.infrastructureanywhere.com/documentation/additional/mirrors.html
848
849
These instructions are geared toward reprepro but should be useful in general for setting up `gpg-agent`.
850
851
852
h2. Resolve DNS While VPN Connected
853
854
How to configure dnsmasq for DNS overrides while using a VPN connection: https://chawlasumit.wordpress.com/2014/06/15/linux-mint-openconnect-vpn-dns-issues/
855
856
h2. Pretty Print Python Traceback
857
858
<pre>#!python
859
import traceback
860
861
 ...
862
863
try: 
864
    with open('/dev/null', 'w') as void:
865
        rc = not bool(subprocess.call('modprobe -r {:s}'.format(mod_name), 
866
                                      shell=True, stdout=void, stderr=void))
867
except Exception as e:
868
    print_failure_status()
869
    exc_type, exc_value, exc_traceback = sys.exc_info()
870
    print('\n')
871
    traceback.print_exception(exc_type, exc_value, exc_traceback)
872
    print('\n')
873
</pre>
874
875
h2. Generating Random Data Files for Testing
876
877
One approach is to use /dev/urandom (non-blocking pseudorandom device):
878
<pre>
879
$ dd if=/dev/urandom bs=32M count=32 of=data_1GB.bin
880
</pre>
881
Unfortunately /dev/urandom is a bit slow. However, you can alternatively use openssl to generate pseudorandom numbers a bit faster:
882
<pre>
883
 $ openssl rand 1073741824 > data_1GB.bin
884
 $ for run in {1..30}; do echo $run; openssl rand 1073741824 >> data_30GB.bin; done
885
</pre>
886
887
h2. Cloning HDDs
888 8
889 1
When configuring multiple chassis it is necessary to clone an HDD. There are all sorts of disk imaging tools out there but it's hard to beat the trusty dd command. The pv (pipe viewer) portion isn't strictly necessary but it prints out a very useful textual status bar. The back ticked blockdev command reports the size of the drive in bytes, which pv then uses to determine overall progress. The bs argument to dd should correspond to the cache size of the drive for optimum performance (32MB is a sane default for most drives these days).
890
891
To clone a single drive to another identical drive (assuming sda is the source and sdb is the destination):
892
<pre>
893
 $ sudo dd if=/dev/sda bs=32M | pv -s `sudo blockdev --getsize64 /dev/sda` | sudo dd of=/dev/sdb bs=32M
894
</pre>
895
To clone to multiple drives all at once (assuming sda is the source and sdb, sdc are destinations):
896
<pre>
897
 $ sudo dd if=/dev/sda bs=32M | pv -s `sudo blockdev --getsize64 /dev/sda` | tee >(sudo dd of=/dev/sdb bs=32M) | sudo dd of=/dev/sdc bs=32M
898
</pre>
899
It is entirely possible to clone more drives by adding additional `>(sudo dd of=/dev/sdX bs=32M)` arguments to the tee command. Note that tee outputs to stdout so it is necessary to pipe the output of tee to the final dd command as shown above. If you don't do this then tee will spew the raw contents of the source HDD to your screen, which will make the clone take forever and look especially ugly!
900
901
For some reason RedHat/CentOS do not have the pv command or even a package for it in their repos!!! Therefore, boot from a Debian-based OS in order to clone.
902
903
h2. Generating ISOs
904
905
<pre>
906
 $ genisoimage -R -J -o <output.iso> <some directory>
907
</pre>
908
To deal with long file names:
909
<pre>
910
 $ genisoimage -R -J -l -D -joliet-long -o <output.iso> <some directory>
911
</pre>
912
913 2
h2. BIOS/grub
914 1
915 2
* http://forums.linuxmint.com/viewtopic.php?f=46&t=119832
916
* http://www.gnu.org/software/grub/manual/html_node/BIOS-installation.html
917
* https://wiki.archlinux.org/index.php/GRUB2
918
* http://unix.stackexchange.com/questions/28443/does-grub2-support-putting-boot-on-a-raid5-partition
919 1
920
h3. Creating a BIOS Boot Partition on a GPT system
921
922
<pre>
923
$ sudo parted /dev/sda
924
(parted) mkpart primary 0 1024k
925
(parted) set 2 bios_grub on
926
</pre>
927
928 2
h2. Actiontec Router
929
930
* http://transition.fcc.gov/oet/ea/fccid/
931
* http://opensource.actiontec.com/mi424wref.html
932 1
933
h2. Temp
934
935
https://www.grumpyland.com/blog/183/installing-software-raid-on-centos-567-via-ssh/
936
<pre>
937
# swap is on /dev/md1
938
/dev/md1 none            swap    sw              0       0
939
940
# storage is on /dev/md0
941
/dev/md0        /storage        xfs     noatime,barrier=0 0 0
942
//faramir/production/sw /sw     cifs    username=samba,password=w00tw00t!,file_mode=0666,dir_mode=0777  0       0
943
</pre>
944
945
----
946
[[../|Back home]]