Skip to content

Instantly share code, notes, and snippets.

View awagner83's full-sized avatar

Adam Wagner awagner83

View GitHub Profile
@awagner83
awagner83 / nfa_regex.hs
Created April 4, 2012 02:34
Simple NFA regex engine in Haskell
import Control.Monad (join)
data Match = LiteralChar Char | AnyChar deriving (Eq)
data Regex = Step Match Regex
| Split Regex Regex
| MatchEnd
deriving (Eq)
@awagner83
awagner83 / recursive.py
Created March 27, 2012 13:22
Recursive data-structure validation with datatype-0.9a3
from datatype.validation import is_valid, failures
from datatype import named, reference
# note the new
datatype = named('child', {'a': 'str', 'optional b': reference('child')})
# valid
assert is_valid(datatype, {'a': 'some', 'b': {'a': 'foo'}})
assert is_valid(datatype,
{'a': 'foo', 'b': {'a': 'bar', 'b': {'a': 'baz'}}})
@awagner83
awagner83 / gist:1933467
Created February 28, 2012 16:26
Helpful vim things I don't yet have muscle-memory for
" Display
zz " set current line at center of window
" Tabs and windows
^W T " move the current window to a new tab
" Jumping
gd " go to local declaration
^O " go to one position older in jump list
^I " go to one position newer in jump list
@awagner83
awagner83 / var_passing.hs
Created January 2, 2012 20:25
Simple haskell var passing example.
import System.IO
main :: IO ()
main = do
val <- getLine -- "val" here belongs to main's scope.
putStrLn (myfun val) -- pass the val to myfun, since it's out
-- of it's scope.
myfun :: String -> String
myfun a = "My value is " ++ a -- myfun knows nothing of 'val', as it
@awagner83
awagner83 / functionmock.py
Created October 24, 2011 15:29
FunctionMock example
import inspect
from mock import Mock, patch
def myfun(a, b, c):
print "fire zee missiles!"
def test_myfun():
@awagner83
awagner83 / php_benchmark_generator.py
Created October 6, 2011 18:21
Generate ridiculous php files to test docblock runtimes
templates = {
"docblock": """
/**
* My Docblock
*/
class MyClass%s {}
""",
"nodocblock": """
/*-
* My Docblock
@awagner83
awagner83 / idme.hs
Created August 1, 2011 06:03
Simple id server snippet
import Control.Concurrent
import System.IO
import Network
type NodeId = String
type IdSequence = [String]
-- Char dividing incrementing-id from node-id
idNodeDelim :: Char
idNodeDelim = '.'
@awagner83
awagner83 / zsh completions made easy
Created January 18, 2011 15:07
simple zsh creation for my 'activate virtualenv' shell function
_virtual_envs() {
if [[ -n $words[1] ]]; then
compadd `ls -d ~/VirtualEnv/*/ | cut -d/ -f5`
fi
}
compdef _virtual_envs venv
#!/bin/bash
gunicorn path.to.app &
MASTER_PID=$!
trap "kill $MASTER_PID; exit" INT TERM EXIT
while true
do
sleep 1