Łukasz Wieczorek's blog A slice of programmer's life

Random findings

Secure GPG key generation using gpg:

gpg2 --gen-key
gpg2 --list-keys
gpg2 -K --keyid-format long --with-colons --with-fingerprint
gpg2 --export -a $ID

Other useful GPG commands;

gpg2 --delete-secret-key $email
gpg2 --delete-key $email
gpg --armor --export $email > "${email}.asc"

Long ssh key generation using ssh-keygen:

ssh-keygen -b 16384

Setting fedora docker directories permission using chcon:

sudo chcon -Rt svirt_sandbox_file_t /var/lib/docker/volumes/
chcon -Rt svirt_sandbox_file_t $volume_dir

Burning Ubuntu to USB using dd:

lsblk -f
umount /dev/sdb1
dd if=ubuntu-16.04.2-desktop-amd64.iso of=/dev/sdb bs=4M status=progress
sync

Ignoring changes for file in git:

git update-index --(no-)assume-unchanged

Removing project containers using docker-compse:

docker-compose down --rmi all --remove-orphans

Rebuilding project containers using docker-compose:

docker-compose up --build

Updating all globally installed gems using gem and cut:

sudo gem update `gem list | cut -d ' ' -f 1`

Upgrading to Fedora 26 using system-upgrade:

dnf upgrade --refresh
dnf install --assumeyes dnf-plugin-system-upgrade
dnf system-upgrade download --refresh --releasever=26
dnf system-upgrade reboot

uWSGI maximum scoket connections

Were you ever wondering why are you getting HTTP 502 responses from your uWSGI on high connection count?

Setting net.core.somaxconn might help.

Temporarily:

$ cat /proc/sys/net/core/somaxconn
# echo 4096 > /proc/sys/net/core/somaxconn

Temporarily with sysctl:

# sysctl -w net.core.somaxconn=1024
# echo 'net.core.somaxconn=1024' >> /etc/sysctl.conf

Reload kernel parameters after changes:

# sysctl -p

Change uWSGI settings for vassal:

cat /etc/uwsgi/vassals/vassal.ini
echo 'listen = 1024' >> /etc/uwsgi/vassals/vassal.ini

Restart uwsgi:

service uwsgi restart

Debugging Django code

Ever tried debugging Django code in the CLI offered by manage.py shell or shell_plus?

It gets nasty when you need to write more than few lines of code to run something.

Here’s what you can do instead:

import os

import django


os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
django.setup()


def main():
    print 'Hello world!'


if __name__ == '__main__':
    main()