Skip to content

Instantly share code, notes, and snippets.

"""
Broken example.
"""
from cassandra.cluster import Cluster
from multiprocessing import Pool
size = 4
keyspace = 'system'
@tkaemming
tkaemming / gist:21b26cee2788939399c4
Last active August 29, 2015 14:11
zookeeper asynchronous child retrieval
def children(zookeeper, path):
get_child_path = functools.partial(posixpath.join, path)
return [
(name, zookeeper.get_async(get_child_path(name)))
for name in zookeeper.get_children(path)
]
import atexit
import time
from threading import (
Event,
Lock,
Thread,
)
(6fbda187737cc2cd)ted@aventador-3 % python remove-consumer.py --zookeeper $ZOOKEEPER tkaemming
/consumers/tkaemming (created 1 day, 3:21:37.186777 ago, modified 1 day, 3:21:37.186777 ago, version 0)
/consumers/tkaemming/offsets (created 1 day, 3:21:27.186777 ago, modified 1 day, 3:21:27.186777 ago, version 0)
/consumers/tkaemming/offsets/activity-metrics (created 1 day, 3:21:27.186777 ago, modified 1 day, 3:21:27.186777 ago, version 0)
/consumers/tkaemming/offsets/activity-metrics/3-1 (created 1 day, 3:21:26.186777 ago, modified 0:31:03.186777 ago, version 1293)
/consumers/tkaemming/offsets/activity-metrics/3-0 (created 1 day, 3:21:26.186777 ago, modified 0:31:03.186777 ago, version 1293)
/consumers/tkaemming/offsets/activity-metrics/1-1 (created 1 day, 3:21:26.186777 ago, modified 0:31:03.186777 ago, version 1293)
/consumers/tkaemming/offsets/activity-metrics/1-0 (created 1 day, 3:21:26.186777 ago, modified 0:31:03.186777 ago, version 1293)
/consumers/tkaemming/offsets/ac
import itertools
def pager(size):
for i in itertools.count():
if i % size == 0:
print 'fetching page:', i / size
yield i
def readahead(iterable, size=100):
actual, ahead = itertools.tee(iterable)
@tkaemming
tkaemming / Dockerfile
Created June 10, 2015 06:32
nginx-push-stream dockerfile
FROM buildpack-deps:jessie
RUN NGINX_VERSION=1.9.1 && \
PUSHSTREAM_VERSION=0.5.1 && \
curl -LO https://github.com/wandenberg/nginx-push-stream-module/archive/$PUSHSTREAM_VERSION.tar.gz && \
tar xvf $PUSHSTREAM_VERSION.tar.gz && \
curl -LO http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz && \
tar xvf nginx-$NGINX_VERSION.tar.gz && \
cd nginx-$NGINX_VERSION && \
./configure --add-module=../nginx-push-stream-module-$PUSHSTREAM_VERSION && \
2015-08-12 23:30:25,127 DEBUG MainThread:140495276758784 - Checking cluster version...
2015-08-12 23:30:25,128 DEBUG MainThread:140495276758784 - Remote version: 0.3.0.dev0
2015-08-12 23:30:25,129 DEBUG MainThread:140495276758784 - Connecting to databases: postgresql:///destination
2015-08-12 23:30:25,133 DEBUG MainThread:140495276758784 - Checking if postgresql:///destination has been configured...
2015-08-12 23:30:25,134 INFO MainThread:140495276758784 - postgresql:///destination has not been configured for use, setting up now...
2015-08-12 23:30:25,134 INFO MainThread:140495276758784 - Beginning prepared transaction 0_cGdzaG92ZWw6c2V0dXAtZGF0YWJhc2U=_MWI5ZDQ2ZjI0MTRhMTFlNWI1YzIwMjQyYWMxMTAwODA= on postgresql:///destination...
2015-08-12 23:30:25,135 INFO MainThread:140495276758784 - Creating PgQ extension (if it does not already exist)...
2015-08-12 23:30:25,172 INFO MainThread:140495276758784 - Creating (or updating) plpythonu language...
2015-08-12 23:30:25,183 INFO MainTh
# .zshrc
# created by tkaemming on 2009-04-08
alias lstree="ls -R | grep \":$\" | sed -e 's/:$//' -e 's/[^-][^\/]*\//–/g' -e 's/^/ /' -e 's/-/|/'"
export PATH="/usr/local/php5/bin:/usr/local/mysql/bin:$PATH"
autoload colors zsh/terminfo
if [[ "$terminfo[colors]" -ge 8 ]]; then
colors
@tkaemming
tkaemming / jquery.inlineformset.js
Created June 17, 2009 19:53
Simple inlineformset plugin for jQuery and Django. This is a work in progress and not ready for a production environment, but a good starting point for forks to add additional functionality.
;(function($){
$.inlineformset = {
defaults: {
extra: 3,
formSelector: '.form',
formsetSelector: '.formset',
hideOnDeletion: true,
},

Creating Video Thumbnails with FFmpeg

Assuming you have FFmpeg (http://ffmpeg.org/) installed, you should be able to run the following command. (It helps to have ffmpeg on your path, or call it absolutely from your script.)

ffmpeg -y -i ./path/to/video.mpg -f mjpeg -ss 00:00:05 -vframes 1 ./path/to/thumbnail.jpg

Hints:

  • The -f flag forces the output to "mjpeg". You can view a list of available formats by with "ffmpeg -formats".
  • The -ss flag denotes the position in the video (HH:MM:SS[.xxx] format). I'm sure there's a way to get the total length of the video (if you're doing video conversions before this, you should be able to get it by parsing STDERR).