Skip to content

Instantly share code, notes, and snippets.

View xnoder's full-sized avatar

Paul Stevens xnoder

View GitHub Profile
@xnoder
xnoder / rerouter.sh
Created March 3, 2017 12:15
A ZSH script to rebuild my macos routing table for whichever network I am on so that I can run my FortiClient VPN permanently without having all traffic tunnelled up the utun1 interface by the VPN config
#!/bin/zsh
usage() {
print "Usage: sudo rerouter -n network"
exit 1
}
while getopts ':n:' arg; do
case $arg in
n)
@xnoder
xnoder / setup.py
Created January 13, 2017 11:20
Falcon unit testing post on xnode.co.za
import imp
from os import path
from setuptools import find_packages, setup
VERSION = imp.load_source('version', path.join('.', 'samplex', 'version.py'))
VERSION = VERSION.__version__
REQUIRES = ['falcon>=1.1.0', 'bcrypt>=3.1.1', 'gunicorn>=19.6.0']
@xnoder
xnoder / lsof.sh
Created December 19, 2016 07:40
Zap a deleted file handle holding into disk space
# These commands will help you find and truncate a deleted file handle that is holding onto disk space. Why do my servers
# always fuck with me during the holidays?
# Run this to find files that have one link, which should equal a (deleted) file
$ lsof -nP +L1
# Now, search through /proc to find these deleted files
$ find /proc/*/fd -ls | grep '(deleted)'
/proc/5225/fd/3 -> /var/log/ceph/ceph-mon.st1.log.1\ (deleted)
@xnoder
xnoder / pyenv_command.sh
Created November 28, 2016 09:31
pyenv cheat sheet
# List all available versions
$ pyenv versions
system
# Install Python3 on machine as full binary
$ pyenv install 3.5.2
# Create virtualenv out of 3.5.2
$ pyenv virtualenv 3.5.2 developer
$ pyenv activate developer
@xnoder
xnoder / hashpw.py
Created November 24, 2016 05:23
Hash a password with bcrypt and Python 3
import bcrypt
# Need to supply the password as a byte
hashed = bcrypt.hashpw(b'somepassword', bcrypt.gensalt())
print(hashed)
#>> b'$2b$12$rbsEiL/dJymbH3453Tbhs.kEljGWNKTmp23s5iG71adGxv5jFj72S'
# To check the same password against the hashed value, use checkpw()
# The password you're testing comes first, the hashed value second.
# Getting it the other way around results in an Invalid Salt error.
@xnoder
xnoder / randomstring.py
Created November 18, 2016 06:54
Create a 32-char random string in Python
import random
import string
randomish = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(32))
print(randomish)