User Tools

Site Tools


linux:scribble

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
linux:scribble [2013/11/02 14:53] – [Puppet] even more strange stuff styblalinux:scribble [2022/07/06 17:27] (current) – setfont stybla
Line 111: Line 111:
 </code> </code>
  
 +==== Exercises =====
 +
 +[[https://www.codingunit.com/category/programming-algorithms|Programming algorithms at CodingUnit]].
 +
 +===== Change keyboard layout in console =====
 +
 +''loadkeys /usr/share/keymaps/i386/qwerty/us.kmap.gz''
 +
 +Don't forget about ''setfont''
  
 ===== Cisco IOS notes ===== ===== Cisco IOS notes =====
Line 154: Line 163:
 </code> </code>
  
 +===== ffmpeg =====
 +
 +Note that these were scraped from various sites and forums and I take no credit.
 +
 +==== Fix colour profile/convert to BT709 ====
 +
 +BT709(and nothing else) is supported by some TVs. Therefore one has to reencode video with BT709 colour profile. Note that this command can be used to extract(unpack) MKV(Matroska video file), although just I/O without reencoding is faster, and re-encodes audio to ACC 44.1kHz 128kbit bit rate!
 +
 +<code>
 +ffmpeg \
 +    -i input_file.suffix \
 +    -color_primaries 1 \
 +    -color_trc 1 \
 +    -colorspace 1 \
 +    -vf scale=out_color_matrix=bt709 \
 +    -color_primaries bt709 \
 +    -color_trc bt709 \
 +    -colorspace bt709 \
 +    # RE-ENCODE AUDIO TO AAC - unnecessary, can be removed
 +    -acodec aac \
 +    -strict -2 \
 +    -ab 128K \
 +    -ar 44100 \
 +    # Remove metadata - unnecessary, can be removed
 +    -map_metadata -1 \
 +    output_file.suffix
 +</code>
 +
 +==== Convert BT601 to BT709 ====
 +
 +Just in case ...
 +
 +<code>
 +ffmpeg -i input.mp4 -vf "scale=in_color_matrix=bt601:out_color_matrix=bt709" output.mp4
 +</code>
 +
 +
 +===== Git =====
 +
 +99.9999% scraped from Intranets.
 +
 +==== New branch from tag ====
 +
 +''git checkout -b newbranch v1.0''
 +
 +==== Fetch remote branch ====
 +
 +''git checkout --track origin/daves_branch''
 +
 +
 +===== Go =====
 +
 +Aka golang
 +
 +==== JSON ====
 +
 +Remember that struct attributes/members must begin with capital letter/character. Otherwise you'll get an empty JSON. It took me very long time to figure this one out :-(
 +
 +<file golang json_test.go>
 +package main
 +
 +import (
 +  "encoding/json"
 +  "fmt"
 +)
 +
 +// Attributes, eg. Name, must begin with capital letter/character, otherwise it won't work.
 +// Also, JSON mapping is shown.
 +type Message struct {
 +    Name string `json:"name"`
 +    Body string `json:"body"`
 +    Time int64  `json:"unix_time"`
 +}
 +
 +func main() {
 +  m := Message{"Alice", "Hello", 1294706395881547000}
 +  b, err := json.Marshal(m)
 +  fmt.Println(err)
 +  fmt.Println(string(b))
 +}
 +</file>
  
 ===== iconv ===== ===== iconv =====
Line 161: Line 251:
 <code> <code>
 iconv --from-code=cp1250 --to-code=UNICODE -o $out_file $in_file iconv --from-code=cp1250 --to-code=UNICODE -o $out_file $in_file
 +</code>
 +===== Jenkins =====
 +
 +<code>
 +Jenkins.instance.getItemByFullName("JobName").getBuildByNumber(JobNumber).finish(hudson.model.Result.ABORTED, new java.io.IOException("Aborting build"));
 +</code>
 +
 +<code>
 +Thread.getAllStackTraces().keySet().each() {
 +    if (it.name.contains('YOUR JOBNAME')) {  
 +      println "Stopping $it.name"
 +      it.stop()
 +    }
 +}
 </code> </code>
  
Line 210: Line 314:
 multilibs from time to time), so that might be the issue behind error above. But libvirt  multilibs from time to time), so that might be the issue behind error above. But libvirt 
 is long gone, replaced and forgotten now. is long gone, replaced and forgotten now.
 +
 +===== Move LVM on LUKS to new HDD =====
 +
 +Unfortunately, this is like two years later and all I have are two links - [[https://wiki.deimos.fr/images/f/f1/How_To_Migrate_to_a_full_encrypted_LVM_system.pdf|first]] and [[https://unix.stackexchange.com/questions/379357/best-way-to-move-lvm-on-luks-to-a-new-hdd|second]]. I believe the first one shows how to initialize LUKS at new HDD while the second explains how to move LVM. Shameless copy-paste from the second link. I'm NOT the author of the following:
 +
 +> Ideally, you initialize the new LUKS partition as a LVM PV, add it to your volume group with:
 +
 +<code>vgextend vg1 /path/to/new/LUKS/device</code>
 +
 +> Then use the LVM pvmove command to migrate your data to it like so:
 +
 +<code>pvmove /path/to/old/LUKS/device /path/to/new/LUKS/device</code>
 +
 +> When the data migration is done, be sure to remove the old LUKS partition from the volume group with:
 +
 +<code>vgreduce vg1 /path/to/old/LUKS/device</code>
 +
 +> This can all be done with the system online, although it is marginally safer and probably significantly faster to do it from a LiveCD like SystemRescueCD. Also, if you have a new enough version of LVM, you probably want to use the --atomic option for pvmove, that will ensure that you don't end up with some LV's on the new device and some on the old device if the pvmove command fails.
 +
 +I wish I've documented all the steps I took to move LUKS between HDDs since it might come handy. Also, it's not the first time I did that. Damn!
 +
 +===== loop-AES =====
 +
 +==== Decrypt loopAES encrypted partition =====
 +
 +<code>
 +gpg --decrypt private.gpg | \
 +  cryptsetup loopaesOpen \
 +  /dev/mapper/xxx \
 +  newvolumename \
 +  --key-file=- \
 +  --key-size 128 \
 +  --hash sha256
 +</code>
 +
 +Note that this isn't for ''/etc/fstab''.
 +
 +==== Resize encrypted LVM backed partition =====
 +
 +<code>
 +root@foo:# umount /encrypted
 +
 +root@foo:# lvextend -L +1T /dev/mapper/encrypted
 +
 +root@foo:# losetup -F /dev/loop3
 +Password: 
 +
 +root@foo:# fsck -f /dev/loop3
 +fsck from util-linux 2.22.1
 +e2fsck 1.42.6 (21-Sep-2012)
 +Pass 1: Checking inodes, blocks, and sizes
 +Pass 2: Checking directory structure                                           
 +Pass 3: Checking directory connectivity                                        
 +Pass 4: Checking reference counts                                              
 +Pass 5: Checking group summary information                                     
 +/dev/loop3: 1065215/59539456 files (1.9% non-contiguous), 218308597/238138368 blocks
 +
 +root@foo:# resize2fs /dev/loop3 
 +resize2fs 1.42.6 (21-Sep-2012)
 +Resizing the filesystem on /dev/loop3 to 506573824 (4k) blocks.
 +The filesystem on /dev/loop3 is now 506573824 blocks long.
 +
 +root@foo:# mount /encrypted
 +</code>
 +
 +Funny thing is, it seems much harder to resize encrypted partition via cryptsetup/dm-crypt.
 +
 +===== MySQL =====
 +
 +==== Convert database to UTF-8 encoding ====
 +
 +Originally found at [[https://www.a2hosting.com/kb/developer-corner/mysql/convert-mysql-database-utf-8|a2hosting.com]]
 +
 +Run mysql and check the encoding:
 +
 +<code>
 +SELECT default_character_set_name FROM information_schema.SCHEMATA S WHERE schema_name = "DBNAME";
 +SELECT CCSA.character_set_name FROM information_schema.`TABLES` T,information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA WHERE CCSA.collation_name = T.table_collation AND T.table_schema = "DBNAME" AND T.table_name = "TABLENAME";
 +</code>
 +
 +Change encoding of tables:
 +
 +<code>
 +cat > ~/.my.cnf <<EOF
 +[client]
 +user=USER
 +password=PASSWORD
 +EOF
 +mysql --database=DBNAME -B -N -e "SHOW TABLES" | awk '{print "SET foreign_key_checks = 0; ALTER TABLE", $1, "CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; SET foreign_key_checks = 1; "}' | mysql --database=DBNAME
 +</code>
 +
 +Change encoding of DB itself:
 +<code>
 +ALTER DATABASE DBNAME CHARACTER SET utf8 COLLATE utf8_general_ci;
 +</code>
 +
 +Remove ''~/.my.cnf'' or edit out username and password.
 +
 +
 +===== OpenOffice/LibreOffice =====
 +
 +==== Convert documents to PDF from command line ====
 +
 +Found at [[http://askubuntu.com/questions/226295/libreoffice-command-line-conversion-no-output-file|askubuntu.com]]. Note that LibreOffice didn'
 +like UTF-8 characters in file names, resp. non-ASCI chars(I'm not sure if those actually were in UTF-8 or not). Also, you don't have to specify 
 +full path to document you want to convert. On the contrary, actually.
 +
 +<code>
 +libreoffice --headless --invisible --convert-to pdf --outdir ~/dir  ~/dir/file_to_convert.pptx
 +</code>
  
 ===== Open Sound System (OSS) - license expired ===== ===== Open Sound System (OSS) - license expired =====
Line 285: Line 499:
  
 ===== Puppet ===== ===== Puppet =====
 +
 +==== Generate graph/PNG from dot file ====
 +
 +<code>
 +/usr/bin/dot /tmp/cycles.dot -Tpng -o cycles.png
 +</code>
 +
  
 ==== List all facts on Node ==== ==== List all facts on Node ====
linux/scribble.1383422031.txt.gz · Last modified: 2013/11/02 14:53 (external edit)