Skip to content

Instantly share code, notes, and snippets.

View awagner83's full-sized avatar

Adam Wagner awagner83

View GitHub Profile
@awagner83
awagner83 / base.html
Created June 23, 2012 16:00
Django template blocks example
<!-- See: https://docs.djangoproject.com/en/1.1//topics/templates/#template-inheritance for more information -->
<html>
<head>
<link href="main_styles.css" media="screen" rel="stylesheet" type="text/css" />
{% block extra_header_stuff %}
{% endblock %}
<head>
<body>
<!-- Body content goes here -->
</body>
RED, GREEN, YELLOW, BLUE = range(1, 5)
def as_color(color, text):
COLOR_SEQ = "\033[%dm"
return "%s%s%s" % (COLOR_SEQ % (30 + color), text, COLOR_SEQ % 0)
print "FOO"
print as_color(RED, "AHH!")
@awagner83
awagner83 / .vimrc
Created May 30, 2012 18:18
Starter vimrc
set ruler
set lazyredraw
set mouse=a
set number
set expandtab
set hlsearch
set incsearch
set shiftwidth=4
set smartindent
set smarttab
@awagner83
awagner83 / nfa.py
Created May 10, 2012 01:27
Python NFA evaluation example
from itertools import ifilter
class Step(object):
"""Sequential step in nfa. for branch to continue, the match
defined here must be successul at this point in the string."""
__slots__ = 'match', 'nfa'
def __init__(self, match, nfa=None):
@awagner83
awagner83 / generic_mongo_indexes.py
Created May 7, 2012 21:30
Generic indexes in mongo test
from functools import partial
from pprint import pprint
from pymongo import Connection, ASCENDING
DATABASE_NAME = 'index_test'
def setup():
@awagner83
awagner83 / sort_by_many.hs
Created April 27, 2012 23:55
Fun with monoids! (Ordering Monoid instance)
import Data.List (sortBy)
import Data.Monoid (mconcat)
import Data.Ord (comparing)
-- | Our very own multiSort, in two words!
sortByMany :: [a -> a -> Ordering] -> [a] -> [a]
sortByMany = sortBy . mconcat
-- Now let's see it in action!
myList = [('a', 3), ('a', 2), ('b', 1), ('b', 0)]
@awagner83
awagner83 / binary_tree_foldl.hs
Created April 25, 2012 00:03
Using reduce to build a binary search tree in python (& haskell)
data Tree a = Empty
| Node a (Tree a) (Tree a)
deriving (Show)
-- | Add a value to our binary search tree. (Hard work is done here)
addValue :: Ord a => Tree a -> a -> Tree a
addValue t@(Node v left right) x
| x < v = Node v (addValue left x) right
| x > v = Node v left (addValue right x)
@awagner83
awagner83 / cassandra.py
Created April 19, 2012 20:14
Cassandra model
"""Mock cassandra object. A poor-man's model of it's interface."""
class ColumnFamily(object):
def __init__(self, name):
self.name = name
self.data = {}
def get_row(self, row_id):
@awagner83
awagner83 / reduce.py
Created April 16, 2012 17:00
Explanation of Python's reduce "by example"
# Here are some functions we'd like to simplify (find the abstraction)
def sum(numbers):
result = numbers.pop(0)
for x in numbers:
result += x
return result
def min(numbers):
result = numbers.pop(0)
@awagner83
awagner83 / http_haskell.hs
Created April 13, 2012 19:28
Simple http interactions with HTTP-4000
-- You'll need to "cabal install http" before this will work
import Network.Browser
import Network.HTTP
main = do
result <- getPage "http://www.google.com/"
putStrLn result
getPage url = do