Project

General

Profile

Miscellaneous » History » Version 13

Anonymous, 08/13/2023 04:23 PM
adding note

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