Cheat Sheet

Some reminders for my future self.

Tmux

Save the current layout, and later set the layout to it.

tmux list-windows

will give you

1: man* (3 panes) [274x62] [layout 5ba8,274x62,0,0{181x62,0,0,0,92x62,182,0[92x31,182,0,48,92x30,182,32,49]}] @0 (active)
...

then

tmux select-layout layout 5ba8,274x62,0,0{181x62,0,0,0,92x62,182,0[92x31,182,0,48,92x30,182,32,49]}

Add a key binding to this command in .tmux.conf.

Git

Database

PostgreSQL

createuser -d -s -r
ALTER TABLE "article" ADD COLUMN "password" character varying(80) NULL;

psql:

List databases:

SELECT datname FROM pg_database
WHERE datistemplate = false;

List tables in the current database:

SELECT table_schema,table_name
FROM information_schema.tables
ORDER BY table_schema,table_name;

(source: How do I list all databases and tables using psql?)

Set password:

ALTER ROLE psusername WITH PASSWORD 'password';

SQLite

.mode column
.headers on

MySQL

create database mydb
create user 'myuser'@'localhost' identified by 'password';
grant all privileges on mydb.* to 'myuser'@'localhost' with grant option;
insert into table_name values ( , , );
update table_name set column1=expr1, column2=expr2 where conditions;

How to export result in CSV:

SELECT order_id,product_name,qty FROM orders
INTO OUTFILE '/tmp/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

(from Save MySQL query results into a text or CSV file)

Shell

Remove .pyc:

find . -name "*.pyc" -delete

curl basic usage:

curl
    url
    -H 'X-Auth-Key: 1234'
    -H 'Content-Type: application/json'
    -X PUT
    -d '{"user": "me"}'
    -F 'username=foo'
    -D - # print header

Unpacking .tar.gz is tar -xvzf. Packing is:

tar -zcvf archive-name.tar.gz directory-name

Remove the first line in pipe:

tail -n +2 -f -
sed 1d
awk 'NR > 1'

Substitute in a file:

sed -i 's/teh/the/g' path/to/file

Delete lines in a file that contains a specific string:

sed -i '/pattern to match/d' path/to/file

Count lines of Haskell code:

find . -type d \( -path './.git' -o -path './.stack-work' \) -prune -o -name '*.hs' | xargs wc -l

Firefox

SSH

Unix

Delete user account:

userdel username

GRUB

wpa_supplicant

sudo systemctl restart wpa_supplicant@wlp1s0.service
wpa_cli -iwlp1s0
list_networks
scan_results

Weechat

Allow self-signed certs:

/set irc.server.example.ssl_verify off

(from Weechat FAQ)

Arch Linux

pacman

Source: pacman - ArchWiki

Clear cache:

The paccache(8) script, provided within the pacman-contrib package, deletes all cached versions of installed and uninstalled packages, except for the most recent three, by default:

paccache -r