Skip to content

Instantly share code, notes, and snippets.

Avatar

Wesley Childs mrchilds

  • Hampshire
View GitHub Profile
@mrchilds
mrchilds / gist:8733191
Last active Aug 29, 2015
Unit Test Helpers - Mock logging
View gist:8733191
# Mock logging
# File - someclass.py
class SomeClass(object):
def method_man(self):
logging.basicConfig(filename='/tmp/somelog.log',
level=logging.INFO,
format='%(asctime)s | %(message)s',
datefmt='%m/%d/%Y %I:%M:%S')
@mrchilds
mrchilds / gist:9099373
Last active Aug 29, 2015
Who has a crontab...
View gist:9099373
cat /etc/passwd | awk -F: '{print "crontab -u "$1" -l"}' |s
@mrchilds
mrchilds / gist:9132599
Created Feb 21, 2014
Custom fabric decorators
View gist:9132599
# To use a custom decoractor with fabric
# the decorator needs @wraps(func) otherwise
from functools import wraps
def lock_hubot_aws_changes_when_running(func):
@wraps(func)
def wrapper(*args, **kwargs):
print 'do something'
result = func(*args, **kwargs)
print 'do something'
@mrchilds
mrchilds / gist:9178139
Created Feb 23, 2014
Machine Setup...
View gist:9178139
#Bash
alias pwgen='env LC_CTYPE=C tr -dc "a-zA-Z0-9-_" < /dev/urandom | head -c 15'
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\[$(tput bold)\]\[$(tput setaf 5)\]⌘ \[$(tput setaf 6)\]\w\[$(tput setaf 3)\]\$(parse_git_branch) \[$(tput sgr0)\]"
# Git config...
@mrchilds
mrchilds / gist:9230933
Created Feb 26, 2014
Vagrant - Build on base box
View gist:9230933
# Package up new box
vagrant package --base /Users/<USER>/VirtualBox VMs/<VM-NAME> --output mybox.box
vagrant box add foobar mybox.box
@mrchilds
mrchilds / gist:1729289
Created Feb 3, 2012
Strip all HTML from string using BeautifulSoup
View gist:1729289
from BeautifulSoup import BeautifulSoup
body = "<p>Dear Everyone,</p><p>This is a test</p><h1>Test Complete</h1>"
plain_text = ' '.join(BeautifulSoup(body).findAll(text=True))
@mrchilds
mrchilds / gist:2020824
Created Mar 12, 2012
MAMP - MySQL server has gone away query
View gist:2020824
MAMP:
/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot
set global net_buffer_length=1000000;
set global max_allowed_packet=1000000000;
/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot < ~/Downloads/DUMP
@mrchilds
mrchilds / gist:2399003
Created Apr 16, 2012
Python and Money
View gist:2399003
Work out total and then round up to 2 decimal places WITHOUT dropping the final zero....
from decimal import *
cost = "12.56896"
cost = Decimal(cost).quantize(Decimal('.01'), rounding=ROUND_UP)
@mrchilds
mrchilds / gist:3061165
Created Jul 6, 2012
Django - basic ajax
View gist:3061165
from django.http import HttpResponse
from django.template.loader import render_to_string
from django.utils import simplejson
def myajax(request):
#Some logic
html = render_to_string(TEMPLATE, context)
return HttpResponse(simplejson.dumps({"html": html}),
content_type="application/json; charset=utf-8")
@mrchilds
mrchilds / gist:3121438
Created Jul 16, 2012
Django South - Quick Help
View gist:3121438
# Convert Existing App
$ python manage.py convert_to_south APP_NAME --settings settings_debug
# Perform model change on development
$ python manage.py schemamigration APP_NAME --auto --settings settings_debug
$ python manage.py migrate APP_NAME --settings settings_debug.py
# Perform change on live server (assumes migration was applied and checked in on development)
You can’t perform that action at this time.