Skip to content

Instantly share code, notes, and snippets.

View zachwill's full-sized avatar

Zach Williams zachwill

View GitHub Profile
@zachwill
zachwill / fabfile.py
Created April 8, 2011 23:08
Hello World Examples for the Python fabric framework
#!/usr/bin/env python
from fabric.api import local
def hello(name='world'):
print('\n\n')
print('Hello %s!' % name)
print('\n\n')
@zachwill
zachwill / bittorrent_challenge.py
Created May 24, 2011 22:32
Python solution to the BitTorrent Developer Challenge
#!/usr/bin/env python
"""
My solution to the BitTorrent Developer Challenge -- takes forever to run.
You have 40 bowls, all placed in a line at exact intervals of 1 meter. You
also have 9 oranges. You wish to place all the oranges in the bowls, no
more than one orange in each bowl, so that there are no three oranges A, B,
and C such that the distance between A and B is equal to the distance
between B and C. How many ways can you arrange the oranges in the bowls?.
def category(request, model, tag):
"""
Given a lowercase model name and tag, search for all models linked to
the given tag. The model is obtained by looking through a dictionary of
available models.
"""
available_models = {'apps': App, 'data': Data, 'ideas': Idea}
try:
actual_model = available_models[model]
except KeyError:
#!/usr/bin/env python
"""Looking up environment variables through `vars`."""
def ohai():
"""A simple function."""
print 'ohai'
class Foo(object):
#!/usr/bin/env python
"""Looking up environment variables through `vars`."""
def ohai():
"""A simple function."""
print 'ohai'
class Foo(object):
"""Just showing off timeit to tell the difference between operations."""
from timeit import Timer
# We'll run each one a thousand times.
print Timer("[0] * 7000").timeit(1000)
print Timer("bytearray(7000)").timeit(1000)
#!/usr/bin/env python
"""For ctbarna."""
list_of_dicts = [
{'key_1': 'value_1', 'key_2': 'value_2'},
{'key_1': {'inception_key': 'inception_value'}, 'key_2': 'value_2'},
{'key_1': 'value_1', 'key_2': 'value_2'},
]
#!/usr/bin/env python
"""For ctbarna."""
list_of_dicts = [
{'key_1': 'value_1', 'key_2': 'value_2'},
{'key_1': {'inception_key': 'inception_value'}, 'key_2': 'value_2'},
{'key_1': 'value_1', 'key_2': 'value_2'},
]
// An example of mixing colors using the Less CSS parser.
// This specific example warms the color #222 with a yellow.
var parser = new(less.Parser);
function print_tree(event, tree) {
console.log(tree.toCSS());
}
parser.parse('@dark: #222; @yellow: #fcd20a; .my{ color: mix(@yellow, @dark, 6%); }', print_tree);
Last login: Wed Sep 28 01:53:45 on ttys010
zachwill:~ ✩ DYLD_LIBRARY_PATH="/Users/zachwill/Downloads/GP.app/Contents/Resources/PARI2/lib:$DYLD_LIBRARY_PATH"; '/Users/zachwill/Downloads/GP.app/Contents/Resources/PARI2/bin/gp'
dyld: Library not loaded: /Users/chris/Downloads/pari-2.5.0/~/PARI/lib/libpari.dylib
Referenced from: /Users/zachwill/Downloads/GP.app/Contents/Resources/PARI2/bin/gp
Reason: image not found
Trace/BPT trap: 5
zachwill:~ ✩