Skip to content

Instantly share code, notes, and snippets.

View Flushot's full-sized avatar
👀

Chris Lyon Flushot

👀
View GitHub Profile
@Flushot
Flushot / jinja2_linebreaks.py
Created June 14, 2013 23:23
Jinja2 filter that mimicks PHP's nl2br
import re
from jinja2 import evalcontextfilter, Undefined, Markup, escape
paragraph_re = re.compile(r'(?:\r\n|\r|\n){2,}')
@app.template_filter()
@evalcontextfilter
def linebreaks(eval_ctx, value):
if value is None or isinstance(value, Undefined):
return ''
@Flushot
Flushot / app.js
Last active December 18, 2015 17:39
Backbone RequireJS boilerplate
require(['module', 'gevents'], function(module, gevents) {
var userView = new module.UserView();
var commentsView = new module.CommentsView({ el: $('#comments'), collection: [] });
var chris = new module.User({
first_name: 'Chris',
last_name: 'Lyon',
email: '[email protected]',
comments: [
@Flushot
Flushot / fact.py
Created October 4, 2013 01:53
factorial in python
fact = lambda n: n * fact(n - 1) if n > 0 else 1
@Flushot
Flushot / loggedonuser.sh
Created November 14, 2013 00:07
Get user logged into graphical desktop (OSX and Linux)
#!/bin/bash
os=`uname`
user=
if [ "$os" == "Darwin" ]; then
# osx
user=`stat -f '%Su' /dev/console`
elif [ "$os" == "Linux" ]; then
# linux
user=`who -s | awk '/^[^\s]+? :0 / { print $1 }' | head -n1`
fi
@Flushot
Flushot / mov2gif.sh
Last active December 28, 2015 17:49
Creates a file output.gif from input file $1
#!/bin/sh
out_file=output.gif
cut_in="00:00:00.000"
cut_out="00:00:10.000"
[ -f $out_file ] && rm -f $out_file
ffmpeg -ss $cut_in -i $1 -vf scale=320:-1 -r 10 -f image2pipe -vcodec ppm -t $cut_out - | convert -delay 5 -loop 0 -layers optimize - $out_file
@Flushot
Flushot / mov2flv.sh
Last active December 28, 2015 17:59
Convert movie file $1 to flash
#!/bin/sh
out_file=output.gif
cut_in="00:00:00.000"
cut_out="00:00:10.000"
[ -f $out_file ] && rm -f $out_file
ffmpeg -ss $cut_in -i $1 -qmax 10 -vb 400k -ar 22050 -ab 32 -f flv -r 15 -s 320x240 -aspect 4:3 -t $cut_out $out_file
@Flushot
Flushot / ones_complement.py
Last active August 29, 2015 14:06
One's complement in Python
def ones_complement(x):
return x ^ ((1 << x.bit_length()) - 1)
@Flushot
Flushot / php_emit.php
Last active August 29, 2015 14:10
Keeps a clean separation between legitimate content and error messages
#!/usr/bin/env php
<?php
$_emit_shutdown_function_registered = false;
/**
* Emits (using echo()) the return value of a closure function.
* Keeps a clean separation between legitimate content and error messages.
*
* If any type of fatal error or Exception was encountered during evaluation,
#!/usr/bin/env python
import re
primePat = re.compile(r'^1?$|^(11+?)\1+$')
# http://primes.utm.edu/lists/small/1000.txt
primes = [int(x.strip()) for x in '''
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113