Skip to content

Instantly share code, notes, and snippets.

View bryder's full-sized avatar

Bill Ryder bryder

View GitHub Profile
Ref: http://pep8.readthedocs.org/en/latest/intro.html#error-codes
E124 (^) closing bracket does not match visual indentation
E127 (^) continuation line over-indented for visual indent
E128 (^) continuation line under-indented for visual indent
On the slave (python string)
"select pg_last_xlog_receive_location(), pg_last_xlog_replay_location(), "
"EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp()) AS seconds_since_last_replay, "
"pg_xlog_location_diff(pg_last_xlog_receive_location(), pg_last_xlog_replay_location()) "
"AS replay_receive_xlog_pos_delta;
On the master
use pg_xlog_location_diff with the extracted positions from the slave to do something similar
@bryder
bryder / version_check_module.py
Created December 3, 2015 04:00
Check module version in python is a minimum
from distutils.version import LooseVersion
if LooseVersion(thing.__version__) < LooseVersion('1.11.1'):
exit("Use the right version dude")
@bryder
bryder / dirname_basename_fullpath_of_script.bash
Last active January 12, 2017 21:53
get dirname/basename and full path of a script in bash
# This will work even with spaces in the directory name or the script name
# or even if the script is sourced
script_basename=${BASH_SOURCE[0]##*/}
# on osx you need to brew install coreutils - then you get greadlink not readlink as in linux
script_fullpath=$( (greadlink -f "${BASH_SOURCE[0]}" || readlink -f "${BASH_SOURCE[0]}" ) 2> /dev/null)
script_dirname=${script_fullpath%/*}
echo basename \'${script_basename}\'
echo fullpath \'${script_fullpath}\'
@bryder
bryder / gist:9af775bad4342ba97490
Created October 21, 2015 03:19
Simulating less memory using tmpfs
sudo mkdir /mnt/tmpfs
sudo mount -t tmpfs -o size=16g /dev/shm /mnt/tmpfs
dd if=/dev/zero bs=1024k count=4096 of=/mnt/tmpfs/bigfile
@bryder
bryder / get_script_pathname_dirname.py
Created September 7, 2015 21:32
get fully qualified forms of name of the currently running python script
script_path = os.path.realpath(__file__)
script_path_no_ext = os.path.splitext(os.path.realpath(__file__))[0]
script_dir = os.path.dirname(script_path)
@bryder
bryder / json_dumps_serialiser_that_should_be_default.py
Last active April 28, 2016 20:15
make json.dumps serialise common things. Doh.
# from stack overflow http://stackoverflow.com/questions/8230315/python-sets-are-not-json-serializable and others
class SerialiseThis(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, set):
return list(obj)
if isinstance(obj, datetime.datetime):
return obj.isoformat()
@bryder
bryder / enable_onscreen_keyboard.ps1
Created June 23, 2015 00:42
Enable on screen keyboard windows 8.1
Set-Service tabletinputservice -Status Running -StartupType Manual
@bryder
bryder / disable_onscreen_keyboard.ps1
Created June 23, 2015 00:41
Disable onscreen keyboard for windows 8.1
Set-Service tabletinputservice -StartupType Disabled
stop-service tabletinputservice
@bryder
bryder / override_bad_cert_go_get
Created June 9, 2015 19:40
handling man in the middle pain for go get etc etc
env HTTPS_PROXY=aproxy:3128 GIT_SSL_NO_VERIFY=true go get -v github.com/jessevdk/go-flags