Skip to content

Instantly share code, notes, and snippets.

@chrisfarms
chrisfarms / shell.nix
Created June 2, 2014 09:46
Minimal shell.nix with ruby package
let
pkgs = import <nixpkgs> {};
stdenv = pkgs.stdenv;
in
{
developmentEnv = stdenv.mkDerivation rec {
name = "developmentEnv";
version = "nightly";
src = ./.;
buildInputs = [
{ config, pkgs, ... }:
let
srcDir = builtins.toString ./.;
dataDir = "/var/data/";
mysqlpass = "v3rys3cr3t";
in {
system.activationScripts.uploadsDir = ''
mkdir -p "${dataDir}"
chown -R wwwrun:wwwrun "${dataDir}"
@chrisfarms
chrisfarms / host1guests.nix
Created June 13, 2014 00:42
Example config for 4 machines on 2 serperate seperate vlans
{config, pkgs, ...}:
{
imports = [
../virtualisation/guests.nix
];
virtualisation.guests = {
red1 = {
ffmpeg -y -i $input_file$ -pass 1 -passlogfile $private_tmp_path$/$record_id$_2pass -s $width$x$height$ -vcodec libx264 -b 192k -bt 192k -flags +loop -cmp +chroma -partitions 0 -me_method epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 30 -sc_threshold 40 -i_qfactor 0.71 -maxrate 10M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 4:3 -acodec libfaac -ar 22050 -an $private_tmp_path$/$record_id$_pass1.mp4
ffmpeg -y -i $input_file$ -pass 2 -passlogfile $private_tmp_path$/$record_id$_2pass -s $width$x$height$ -vcodec libx264 -b 192k -bt 192k -flags +loop -cmp +chroma -partitions +parti4x4+partp4x4+partp8x8+partb8x8 -me_method umh -subq 7 -trellis 2 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 30 -sc_threshold 40 -i_qfactor 0.71 -maxrate 10M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 4:3 -acodec libfaac -ar 22050 -an $private_tmp_path$/$record_id$_noqt.mp4
qt-faststart $private_tmp_p
def nearly_eq(value,target_value,off_by):
"""
an equality function with a margin for error (off_by)
"""
return target_value-off_by < value < target_value+off_by
def make_transparent(blob, threshold=210, tolerance=30):
r = png.Reader(bytes=blob)
(width,height,pixels,meta) = r.asRGBA8()
w = png.Writer(
@chrisfarms
chrisfarms / xmpplogging.py
Created March 12, 2011 23:35
Python logging handler to send error logs via XMPP/Jabber
from google.appengine.api import xmpp
import logging
import logging.handlers
import os
DEFAULT_FROM_JID = 'logs@%s.appspotchat.com' % os.environ['APPLICATION_ID']
class XmppLogHandler(logging.Handler):
def __init__(self, jid, from_jid):
def main():
from lib.xmpplogging import XmppLogHandler
XmppLogHandler.add('your@jabber.id')
run_wsgi_app(application)
@chrisfarms
chrisfarms / each.py
Created March 22, 2011 15:54
Function to map over all entities in a GAE query
from google.appengine.ext import db
def each(query, batch_size=100):
"""yields each entity in the query over the whole dataset in batches"""
entities = query.fetch(batch_size)
while entities:
for entity in entities:
yield entity
# if the query was keys only then the entity IS a key
if hasattr(entities[-1],"key"):
@chrisfarms
chrisfarms / basemodel.py
Created March 22, 2011 19:50
GAE base model class with to_json serialisation
SIMPLE_TYPES = (int, long, float, bool, dict, basestring, list)
class BaseModel(db.Model):
def to_json_friendly_value(self, v):
if v is None or isinstance(v, SIMPLE_TYPES):
value = v
elif isinstance(v, datetime.date):
# Convert date/datetime to ms-since-epoch ("new Date()").
ms = time.mktime(v.utctimetuple()) * 1000
@chrisfarms
chrisfarms / sencha-multiple-dv.js
Created May 3, 2011 11:14
Issue with multiple DataViews with one store
// Create a model (with any proxy)
Ext.regModel('Car', {
fields: ['id', 'name', 'sports'],
proxy: {
type: 'localstorage',
id : 'cars'
}
});
// Create a store to access the records