Project

General

Profile

Miscellaneous » History » Version 20

Anonymous, 04/28/2024 05:29 PM
updating example

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