Software Cheatsheet

Git #

Re-apply a .gitignore #

git rm -r --cached .
git add .

*Nix #

Create a self signed cert #

openssl genrsa -aes256 -passout pass:gsahdg -out server.pass.key 4096
openssl rsa -passin pass:gsahdg -in server.pass.key -out server.key
rm server.pass.key
openssl req -new -key server.key -out server.csr
openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt

Enable ufw on docker hosts #

sudo vim /etc/default/docker
sudo reboot now

Reinstall packages in linux #

# Create a backup of what packages are currently installed:
dpkg --get-selections > ~/dotfiles/apt_packages.txt
git commit -am "Updated apt packages"
git push
# Then (on another system) restore installations from that list:
dpkg --clear-selections
sudo dpkg --set-selections < list.txt

Create a Desktop file #

# Create a file under ~/.local/share/applications/
# Example file here:
[Desktop Entry]
Name=Deus Ex: Game of the Year Edition
Comment=Play this game on Steam
Exec=steam steam://rungameid/6910

Find process using port #

sudo lsof -i :5432

Disk usage + Sort #

du -sh -- * | sort -h

Use specfic version of apt source #

sudo apt -t experimental my-cool-dep

Add a cronjob #

# list cronjobs
crontab -l
# edit cronjob
crontab -e
# add one and quit, example here
*/5 * * * * /usr/bin/offlineimap >/dev/null 2>&1
# remove cronjob
crontab -r

Put together multipart rar #

unrar x -e first-par-01.rar

macOS #

Delete a disk from the command line #

diskutil list
diskutil eraseDisk ExFAT USB64 /dev/disk4

SourceGraph #

export SRC_HOST=http://localhost:7080
export SRC_ACCESS_TOKEN=8a645e36dd9c620ec9f97cff31933164b0599f84

docker run --publish 7080:7080 --publish \
       --publish \
       --rm \
       --volume ~/.sourcegraph/config:/etc/sourcegraph \
       --volume ~/.sourcegraph/data:/var/opt/sourcegraph \
       --volume ~/dotfiles/self-signed-cert:/etc/nginx \

Docker #

General #

# Remove all images
docker system prune -a --volumes
# Connect to a running system
docker exec -it <container-id> bash
# Disconnect

Create postgres docker-compose file #

version: "3"
        image: "postgres"
            - database.env
            - database-data:/var/lib/postgresql/data


Copy folder from host to container #

docker cp ~/code/iOS-Trainline 02eb85ead1b4:/code

Jupyter #

python3 -m pip install virtualenv
python3 -m virtualenv jupyterenv
source jupyterenv/bin/activate
pip install jupyter
jupyter notebook

Postgres #

Find users #

SELECT usename AS role_name,
WHEN usesuper AND usecreatedb THEN
CAST('superuser, create database' AS pg_catalog.text)
WHEN usesuper THEN
CAST('superuser' AS pg_catalog.text)
WHEN usecreatedb THEN
CAST('create database' AS pg_catalog.text)
CAST('' AS pg_catalog.text)
END role_attributes
FROM pg_catalog.pg_user
ORDER BY role_name desc;

Create table #

create table users (
user_id 					serial primary key,
email 						text not null unique,
password_digest 	text not null

CREATE TABLE bookmark (
bookmark_id     text CONSTRAINT firstkey PRIMARY KEY,
title						text not null,
date						date,
user_id					integer,

foreign key (user_id) references users(user_id)

Insert into table #

insert into users (email, password_digest) values ('', 'changeme');
insert into bookmark (bookmark_id, title, url, date, user_id) values (1, 'what I am up to now - martin fowler', '', NOW(), 1)

Update a table #

alter table bookmark
add column url text;

Jq #

Given some json, turn result into an array, create a new json with fields headers, body and create that from all the fields that contain a header with value matching “”

cat facebook.json | jq '[.[] | {headers: .request.header.headers, body: .request.body} | select(.headers[].value | match("")) ]'