Project

General

Profile

Miscellaneous » History » Version 17

Anonymous, 02/28/2024 05:10 PM
adding note

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