This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import inspect | |
class Bracketless(object): | |
def __getattribute__(self, name): | |
try: | |
attr = object.__getattribute__(self, name) | |
if callable(attr): | |
args, __, __, __ = inspect.getargspec(attr) | |
if len(args) == 1: # 1 for `self` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Queue | |
import threading | |
def do_work(*args): | |
# Do something with args | |
pass | |
number_of_workers = 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/** | |
* getValues(array('a' => 1, 'b' => 2), array('b', 'c')); # => array('b' => 2) | |
*/ | |
function getValues($data, $fields) | |
{ | |
return array_intersect_key($data, array_flip($fields)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Schema and import for Yahoo GeoPlanet data into a PostgreSQL database. | |
CREATE TABLE places ( | |
woe_id VARCHAR(15) PRIMARY KEY, | |
iso VARCHAR(6), | |
name TEXT, | |
language VARCHAR(6), | |
place_type VARCHAR(15), | |
parent_woe_id VARCHAR(15) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Example output: http://www.flickr.com/photos/sneeu/5448646680/ | |
""" | |
import hashlib | |
RULES = { | |
4: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def counter(start=0, increment=1) | |
i = start - increment # Smells | |
lambda do | |
i += increment | |
end | |
end | |
result = counter(10, 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def counter(start, increment): | |
while True: | |
yield start | |
start += increment | |
result = counter(10, 2) | |
for __ in xrange(0, 5): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppServer | |
attr_accessor :port, :admin_password | |
end | |
class Configuration | |
attr_reader :app_server | |
attr_accessor :tail_logs, :max_connections, :admin_password | |
def app_server(&block) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def qsort(l): | |
""" | |
>>> qsort([]) | |
[] | |
>>> qsort([-1]) | |
[-1] | |
>>> qsort([1, 2, 3, 4]) | |
[1, 2, 3, 4] | |
>>> qsort([4, 3, 2, 1]) | |
[1, 2, 3, 4] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------------------------------ | |
/usr/local/bin/pip run on Tue May 10 12:46:14 2011 | |
Downloading/unpacking virtualenv | |
Getting page http://d.pypi.python.org/simple/virtualenv | |
URLs to search for versions for virtualenv: | |
* http://d.pypi.python.org/simple/virtualenv/ | |
Getting page http://virtualenv.openplans.org | |
Getting page http://www.virtualenv.org | |
Analyzing links from page http://d.pypi.python.org/simple/virtualenv/ | |
Found link http://d.pypi.python.org/packages/source/v/virtualenv/virtualenv-0.8.2.tar.gz#md5=241f157e92dd9052b5a4b43efcef8035 (from http://d.pypi.python.org/simple/virtualenv/), version: 0.8.2 |