Skip to content

Instantly share code, notes, and snippets.

@billyshambrook
billyshambrook / timer.py
Created March 30, 2015 16:58
Context statement timer
import time
class Timer(object):
def __enter__(self):
self.start = time.clock()
return self
def __exit__(self, *args):
self.end = time.clock()
@billyshambrook
billyshambrook / is_url.py
Created March 24, 2015 14:22
Check if string is a URL or not
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')
@billyshambrook
billyshambrook / test_skip_if.py
Last active August 29, 2015 14:11
Example of py.test skip if
import pytest
def is_connected():
import socket
try:
host = socket.gethostbyname("www.google.com")
socket.create_connection((host, 80), 2)
return True
except:
pass
@billyshambrook
billyshambrook / ffmpeg_build.sh
Last active September 23, 2022 07:15
Build FFMPEG, x264 and FDK-AAC
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
@billyshambrook
billyshambrook / arguments_in_decorator.py
Last active August 29, 2015 13:56
Passing around arguments in decorators
"""
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
@billyshambrook
billyshambrook / .zshtheme.sh
Last active August 29, 2015 13:55
ZSH Theme
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 '○'
}
@billyshambrook
billyshambrook / retry_decorator_example.py
Last active December 28, 2015 06:09
Example usage for the retry decorator.
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')
@billyshambrook
billyshambrook / parse_detect_interlacing_output.py
Created November 13, 2013 17:39
Parse FFMPEG detect interlacing filter output in python
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)
@billyshambrook
billyshambrook / detect_interlacing_output.txt
Created November 13, 2013 17:37
FFMPEG: Detect interlacing output
[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
@billyshambrook
billyshambrook / detect_interlacing.sh
Last active December 28, 2015 05:49
FFMPEG: Detect interlacing.
ffmpeg -t 00:01:00 -i input.mpg -map 0:0 -vf idet -c rawvideo -y -f rawvideo /dev/null