Skip to content

Instantly share code, notes, and snippets.

View mbarkhau's full-sized avatar
💭

mbarkhau

💭
  • Cyberspace
View GitHub Profile
@mbarkhau
mbarkhau / proc_example.coffee
Created March 19, 2011 11:51
processing example script
# Example code adapted from http://processingjs.org/learning
delay = 10
X = width / 2
Y = height / 2
# Setup the Processing Canvas
setup = ->
strokeWeight( 10 )
def getattr_sub(obj, attrs, default='__default__'):
"""
>>> getattr_sub(int, '__class__.__name__', None)
'type'
>>> getattr_sub(int, '__cleese__.__name__', 'missing')
'missing'
"""
if type(attrs) == str:
attrs = attrs.split('.')
@mbarkhau
mbarkhau / simple_sprites.py
Created May 19, 2011 07:34
Makes a sprite and css file for png images in a directory.
#!/usr/bin/env python
import os, sys
import subprocess
import Image
from collections import namedtuple
min_css = lambda (s): s.replace(" ", "").replace("\n", "") + "\n"
@mbarkhau
mbarkhau / vimrc
Created May 26, 2011 09:10
my vimrc
"" zi : toggle folding
""
call pathogen#runtime_append_all_bundles()
set spl=en spell
set tag=/home/koloss/workspace/tags
set ruler
set number
set wrap
set tabstop=4
@mbarkhau
mbarkhau / gorun.sh
Created November 28, 2011 01:16
command to compile and run go files
#!/usr/bin/env bash
if [ "$1" ]; then
$GOBIN/gofmt -w -s=true $1
$GOBIN/gofix $1
$GOBIN/6g -o $1.6 $1
$GOBIN/6l -o $1.bin $1.6
$PWD/$1.bin
fi
@mbarkhau
mbarkhau / defer.js
Created January 14, 2012 23:16
Minimalist defer() function
// Adapted mostly from https://github.com/unscriptable/promises/blob/master/src/Tiny.js
// There are a few major problems with this promise that keep it from
// being useful outside of a constrained environment:
// 1. It modifies it's own public API:
// The then(), resolve(), and reject() methods are rewritten when the promise
// is completed (i.e. resolved or rejected). There's nothing inherently wrong
// with this unless some other code is overriding or hijacking the public
// methods (in which case, they'd be overriding the obsolete methods).
// 2. It doesn't distinguish between the "front end" API and the "back end" API:
// If some other code decided to call our reject() method, it could. We would
@mbarkhau
mbarkhau / youtube_transcribe.py
Created April 30, 2012 23:52
Convert googles audio transcription xml to sbv
#!/usr/bin/env python
# encoding: utf-8
import sys
import os.path
import HTMLParser
from xml.sax.saxutils import unescape
from xml.dom import pulldom
@mbarkhau
mbarkhau / filepaths.py
Last active December 15, 2015 03:09
Iterate over all filenames in a directory tree
import os
def filepaths(rootdir, ext_filter=None):
if isinstance(ext_filter, basestring):
_filter = lambda p: p.endswith(ext_filter)
elif isinstance(ext_filter, tuple):
_filter = lambda p: os.path.splitext(p)[1] in ext_filter
else:
_filter = ext_filter
@mbarkhau
mbarkhau / redict.py
Last active December 18, 2015 12:49
Limited size dictionar with Random Eviction
from random import randint
class REDict(dict):
def __init__(self, maxsize, *args, **kwargs):
self._maxsize = maxsize
self._keys = []
self._evict_cb = kwargs.pop('_evict_cb', None)
dict.__init__(self, *args, **kwargs)
@mbarkhau
mbarkhau / freshfile.py
Last active December 20, 2015 15:59
Class which will always give the fresh contents of a file
import codecs
from os.path import getmtime
from time import time
class FreshFile(object):
def __init__(self, filename, mode='r', encoding='utf-8', process_func=None,
max_age=0):
self._filename = filename