This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class my_error_handling(object): | |
def __enter__(self): pass | |
def __exit__(self, exc_type, exc_val, exc_tb): | |
if issubclass(exc_type, UnicodeError): | |
print "annoying" | |
elif issubclass(exc_type, ValueError): | |
print "hrmm" | |
elif issubclass(exc_type, OSError): | |
print "alert sysadmin" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Global virtualenvwrapper postactivate, lives in $WORKON_HOME/postactivate | |
# Remove virtual env from start of PS1 as it's in RPROMPT instead | |
PS1="$_OLD_VIRTUAL_PS1" | |
PROJECT_DIR="$HOME/projects/$(basename $VIRTUAL_ENV)" | |
if [ -d $PROJECT_DIR ]; then | |
# If we aren't already within the project dir, cd into it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Global virtualenvwrapper postactivate, lives in $WORKON_HOME/postdeactivate | |
if [ $PRE_VENV_ACTIVATE_DIR ]; then | |
cd $PRE_VENV_ACTIVATE_DIR | |
unset PRE_VENV_ACTIVATE_DIR | |
unset CURRENT_PROJECT | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Retry decorator with exponential backoff | |
def retry(tries, delay=3, backoff=2): | |
""" | |
Retries a function or method if exception is raised. | |
delay sets the initial delay in seconds, and backoff sets the factor by which | |
the delay should lengthen after each failure. backoff must be greater than 1, | |
or else it isn't really a backoff. tries must be at least 0, and delay | |
greater than 0. | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -t 00:01:00 -i input.mpg -map 0:0 -vf idet -c rawvideo -y -f rawvideo /dev/null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[idet @ 0x17d10a0] Single frame detection: TFF:32 BFF:0 Progressive:0 Undetermined:42 | |
[idet @ 0x17d10a0] Multi frame detection: TFF:58 BFF:0 Progressive:0 Undetermined:16 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
pattern = "\\[(.*)] Multi (.+):(.+):(?P\\w+) (.+):(?P\\w+) (.+):(?P\\w+) (.+):(?P\\w+)" | |
match = re.search(pattern, output) | |
scan = dict((k, int(v)) for k, v in match.groupdict().iteritems()) | |
scan = max(scan, key=scan.get) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto.sqs | |
""" Defence from brief connection outages """ | |
@retry(10) | |
def connect_to_sqs(): | |
conn = boto.sqs.connect_to_region("us-west-2") | |
return conn.create_queue('myqueue') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function virtualenv_info { | |
[ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') ' | |
} | |
function prompt_char { | |
git branch >/dev/null 2>/dev/null && echo '±' && return | |
hg root >/dev/null 2>/dev/null && echo '☿' && return | |
echo '○' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Create argument within decorator and pass to decorated method. | |
Key things that make this possible is to ensure that your decorated method allows *args and **kwargs to be passed. | |
You then within the decorator append whatever to kwargs and/or args. | |
""" | |
def decorate_my_decorator(f): | |
def function_my_decorator(*args, **kwargs): | |
kwargs['somethings'] = 'hello' | |
return f(*args, **kwargs) | |
return function_my_decorator |
OlderNewer