sqlite3 cheat sheet
- .tables -> show tables
- .schema table_name -> describe table
PostgreSQL on Docker
Running Postgres on Docker is easy. Upgrading major versions is not. Some useful commands:
Running psql docker exec -it postgrespostgres1 psql -U postgres databasename
Dump everything in a gzipped file
Upgrade major version
This is tricky. I use this:
docker run --rm -v /data/postgres:/var/lib/postgresql tianon/postgres-upgrade:14-to-15 --link
You need to have your data in the following stucture: /data/postgres/14/data (old version) /data/postgres/15/data (new version will be linked here)
VIM tips 5
- Use fchar or tchar to move to that char, press ";" to go next, press "," to go back.
- o creates a newline and changes to insert mode, O (capital o) creates a newline above your cursor and changes to insert mode.
- zz centers cursor position
- vi" selects everything between ". Works with ( or < as well.
- CTRL+o (older) or CRTL+i (newer) in normal mode moves between last opened files
VIM tips 4
- C deletes until the end of the line and turns on insert mode
- D deletes until the end of the line
- rx replaces the char under the cursor with x
- CTRL+n autocompletes stuff from any buffer (navigate with CTRL+n/CRTL+p)
Some "g" commands
- g; jumps to your last change (even after reopening)
- ga over a letter shows its ASCII code
- gd jumps to the corresponding definition
- gM jumps to the middle of the line
- gm jumps to the middle of the screen line
- gv reselects the previous visual area
Pacman
When I migrated from Ubuntu to Arch I had a hard time remembering Pacman's (the Arch package manager) commands. Here we go:
- pacman -Sy updates the package lists
- pacman -Su upgrades the system
- pacman -Syu updates and upgrades
- pacman -Ss
searches for installable packages - pacman -R
removes a package - pacman -Rs
removes a package and its dependencies - pacman -Qi
shows info about an installed package - pacman -Ql
list all files of an installed package - pacman -Qm show all installed AUR packages
- pacman -Qo /path/to/filename shows which package a file belongs to
- pacman -Qe lists all packages explicitly installed
- pacman -Qd lists all packages installed as a dependency for another package
- pacman -Qt searches for missed installed orphans / packages that not required by any other packages
- pacman -Fs
searches for a file in installable packages - pacman -Sc clears uninstalled packages from cache
- pacman -Scc clears all cached packages
- pacman -U file:///var/cache/pacman/pkg/package.zst downgrades a package from cache
Consider using yay as a frontend for pacman. Really convernient + fast. Plus you can manage AUR packages with it as well.
Update 2019: Nah.
I use the following aliases/bash functions in .bashrc:
alias upd='sudo pacman -Syu'
alias ins='sudo pacman -Sy'
alias aursearch='curl -s https://aur.archlinux.org/packages.gz
| zgrep'
aurinst () { pushd /home/psic4t/sys/aur &&
git clone https://aur.archlinux.org/"$1".git &&
cd "$1" && makepkg -si && popd; }
GIT for dummys
I use git only occasionally. Here are some basic commands to remember:
- git init # new repo
- git add *.go # add some files
- git commit -a -m "First commit" # make a commit
- git status # check for uncommitted changes
- git log # show commits, "--all" for all
- git diff
# shows changes - git checkout
# checkout different commit - git master # back to master
- git remote add origin git@git.sr.ht:~psic4t/bla # setup remote repo
- git push -u origin master # push to remote repo
- git tag -a "0.8.4" # tag release
- git push origin "0.8.4" # push tag to remote repo
- git clone git@github.com:mygitname/theproject.git --branch 1.0.2 # clone specific release
- git commit --amend # change last commit message
- git revert HEAD # revert last commit but keep that commit in history
vim tips 3
Even more of this.
- c-o which will take you out of insert, letting you do one normal command, and then put you right back into insert.
- alt-keystroke changes to normal mode and executes keystroke
- ZQ is equivalent to :wq!
- mark some text and press ~ to switch case
- ci" removes everything between " in line and changes to insert mode
- :digraphs prints a list of key combos for characters like ©
- c-a increments number under cursor, c-x decrements number under cursor
- c-d removes indentation level in insert mode and c-t adds indentation level in insert mode
- type (partial) word. type c-x c-p for word completion. use c-n or c-p to chose the right one