Project

General

Profile

Miscellaneous » History » Version 19

Anonymous, 04/05/2024 09:02 AM
adding note

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