IT notes

macOs catalina & python

Reinstall openssl: brew reinstall openssl And then: export DYLD_LIBRARY_PATH=/usr/local/opt/openssl/lib:$DYLD_LIBRARY_PATH Or create the link manually: cd /usr/local/lib sudo ln -s /usr/local/opt/openssl/lib/libssl.dylib libssl.dylib sudo ln -s /usr/local/opt/openssl/lib/libcrypto.dylib libcrypto.dylib Reinstall python: brew reinstall python Upgrade pip packages: pip install -U --user $(pip freeze | awk -F'[=]' '{print $1}')

Resume Tar

To resume a terminated pr If while extracting a file, the process gets terminated you may be available to resume it with: tar -xvkf file.tgz -k (x mode only) Do not overwrite existing files. In particular, if a file appears more than once in an archive, later copies will not overwrite earlier copies.

convert svg

Convert svg to png having transparent background: $ convert -background none -density 1200 in.svg out.png brew install imagemagick librsvg

extent

To resize an image and adjust it to fit a fixed canvas with transparent background: $ convert in.png \ -resize 128x128 \ -background none \ -gravity center \ -extent 128x128 \ out.png

mysql CRC32

If need to calculate the CRC32 of a string, using mysql: $ mysql -e "SELECT CRC32('127.0.0.1')" +--------------------+ | CRC32('127.0.0.1') | +--------------------+ | 3619153832 | +--------------------+

grep -H

To find path of a file containing a pattern: $ cd jails $ grep -H 34 */etc/ssh/sshd_config In this example the path of the files containing the number 34 will be printed.

online.net IPv6

Configure IPv6 using dhcp6c for servers from online.net: pkg install dhcp6 Transform the DUID into a binary file (needed for dhcp6c): echo <DUID> | awk '{ gsub(":"," "); printf "0: 0a 00 %s\n", $0 }' | xxd -r > /var/db/dhcp6c_duid Add this in /usr/local/etc/dhcp6c.conf: id-assoc pd { prefix-interface igb0 { }; }; id-assoc na { }; interface igb0 { send ia-pd 0; send ia-na 0; }; Add this to /etc/rc.

Start 2 XS SATA

To install FreeBSD using the rescue system on a Start-2-XS-SATA from online.net: #!/bin/sh -x USER=monkey PASSWORD=secret gpart destroy -F ada0 gpart create -s gpt ada0 gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada0 gpart add -t freebsd-boot -l boot -s 128K ada0 gpart add -t freebsd-swap -l swap -s 4g ada0 gpart add -t freebsd-ufs -l root ada0 gpart set -a active ada0 newfs /dev/gpt/root mount /dev/gpt/root /mnt cd /tmp fetch http://ftp.

Prevent Mac to Sleep

To stop sleep entirely: sudo pmset -a disablesleep 1 To revert, allow sleep again: sudo pmset -a disablesleep 0 To display global power settings: pmset -g

sudo SSH_CONNECTION

When using ssh, if then doing something like sudo -i the environment vars are gone, to preserve modify your sudoers (/usr/local/etc/sudoers or /usr/local/etc/sudoers.d/devops) and add something like: Defaults env_keep += "SSH_TTY SSH_CONNECTION SSH_CLIENT" In this case, it will preserve your SSH environment vars.

vbox headless

To list your vms: $ VBoxManage list vms To run one in headless mode: $ VBoxManage startvm freebsd-server --type headless To shutdown: $ VBoxManage controlvm freebsd-server acpipowerbutton To get the IPv4: $ VBoxManage guestproperty enumerate freebsd-server | awk '/IP/' for this to work you will need the vboxguest tools pkg install virtualbox-ose-additions

ddcctl

To share one monitor, keyboard and mouse between two devices, mac mini and a macbook try: brew cask install barrier Then to avoid changing the input source by using the buttons in the monitor try https://github.com/kfix/ddcctl: cd /tmp git clone https://github.com/kfix/ddcctl.git cd ddcctl make && make install In my case to switch from the mac mini (HDMI) to the laptop via (DP) I use: ddcctl -d 1 -i 15 From the laptop (USB-C -> DP) to HDMI, switch back to the mac mini:

timestamp

To get the current unix timestamp: date +%s To get the date from a timestamp: date -r 1559591041 In Linux: date -d "@1559591041"

docker prune

Docker cleanup:  docker system prune -a

rust docker

Dockerfile to create small rust docker images: FROM clux/muslrust RUN mkdir /source WORKDIR /source COPY . . RUN cargo build --release RUN strip ./target/x86_64-unknown-linux-musl/release/myapp FROM scratch COPY --from=0 /source/target/x86_64-unknown-linux-musl/release/myapp / CMD ["./myapp"] Image compatible with cloud foundry: FROM rust:1.35 WORKDIR /usr/src/myapp COPY . . RUN cargo build --release FROM debian:latest RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y openssl ca-certificates COPY --from=0 /usr/src/myapp/target/release/myapp / CMD ["./myapp"]

mysql pager

To use less command to vie the output of a mysql result you could use: mysql> \P less or mysql> pager less Then run something like: mysql> show engine innodb status\G In some cases you may need to search for something in specific for this grep could be used, for example: mysql> \P grep -A7 "ROW OPERATIONS" PAGER set to 'grep -A7 "ROW OPERATIONS"' Then when running the command it will only return 7 lines after “ROW OPERATIONS”

//+build disable

In go if need to sketch something and end having func main() in two files, you could ignore building one by adding at the top of the file: // +build disable This is a build constraint. A build constraint, also known as a build tag, is a line comment that begins: // +build

delete file

Ways to delete a file starting with a dash / hyphen: rm -- -file The option -- means the end of options for the command. Another option is to indicate where is the file: rm ./-file . is current directory , path to -file is ./-file Using find: find . -type f -exec rm {} \; Finding the inode: ls -li Then using find and the inode it can be removed with:

galera SOS

Check status of cluster: https://nbari.com/post/galera/ Find process list not sleeping: SELECT user, time, state, info FROM information_schema.processlist WHERE command != 'Sleep' AND time >= 2 ORDER BY time DESC, id; Get locked tables: show open tables where in_use > 0; Finding locks: show engine innodb status; At the end: ---TRANSACTION 1135701157, ACTIVE 6768 sec MySQL thread id 5208136, OS thread handle 0x7f2982e91700, query id 882213399 xxxIPxxx 82.235.36.49 my_user cleaning up kill the transaction thread:

pigz

To compress using gzip format but using all your available cores: tar --use-compress-program=pigz -cf archive.tgz /path/to/source Or if you want to pipe it: tar -cf - source | pigz > archive.tgz To decompress use tar -xvf archive.tgz as usual. The output of pigz is compatible with gzip