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 time | |
class Timer(object): | |
def __enter__(self): | |
self.start = time.clock() | |
return self | |
def __exit__(self, *args): | |
self.end = time.clock() |
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 urlparse | |
def is_url(str_): | |
""" | |
Returns True if string is a URL. | |
>>> is_url('not a url') | |
False | |
>>> is_url('http://www.example.com') |
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 pytest | |
def is_connected(): | |
import socket | |
try: | |
host = socket.gethostbyname("www.google.com") | |
socket.create_connection((host, 80), 2) | |
return True | |
except: | |
pass |
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
sudo apt-get remove ffmpeg x264 libav-tools libvpx-dev libx264-dev yasm | |
sudo apt-get update | |
sudo apt-get -y install autoconf automake build-essential checkinstall git libass-dev \ | |
libgpac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libspeex-dev \ | |
libtheora-dev libtool libvorbis-dev pkg-config texi2html zlib1g-dev | |
cd | |
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz | |
tar xzvf yasm-1.2.0.tar.gz | |
cd yasm-1.2.0 | |
./configure |
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 |
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
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
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
[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
ffmpeg -t 00:01:00 -i input.mpg -map 0:0 -vf idet -c rawvideo -y -f rawvideo /dev/null |