This file contains 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 sumxyz(x): | |
def sumyz(y): | |
def sumz(z): | |
return x + y + z | |
return sumz | |
return sumyz | |
print sumxyz(5)(4)(3) |
This file contains 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 glob | |
import os | |
class Directory: | |
def __init__(self, path = '/'): | |
self.path = path | |
def __getitem__(self, key): | |
fn = os.path.join(self.path, key) | |
if os.path.exists(fn): |
This file contains 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
<table border=1 cellpadding=5> | |
<tr> | |
<th> </th> | |
<th>Lists</th> | |
<th>Iterators</th> | |
</tr> | |
<tr> | |
<th>Expressive</th> | |
<td> |
This file contains 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 num_ways_to_score(target_score, scores): | |
ways_to_score = 0 | |
counts = [0] * len(scores) | |
while True: | |
score = sum([scores[i] * count for i, count in enumerate(counts)]) | |
if score == target_score: | |
ways_to_score += 1 | |
print counts | |
i = 0 | |
if score > target_score: |
This file contains 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
TESTS = [] | |
def suite(): | |
for test in TESTS: | |
print 'running %s' % test.__name__ | |
test() | |
def test(f): | |
TESTS.append(f) | |
return f |
This file contains 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 Blank(): | |
# this is a hacky way of returning an empty | |
# object that you can set attributes on, without | |
# having to create a class | |
return lambda: None | |
def klass(factory): | |
def init(*args): | |
self = Blank() | |
This file contains 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
Paul Miller asked on Twitter: "Why use MIT license instead of public domain? The only difference is copyright notice inclusion requirement. Is it really needed?" I only know Paul from a few online interactions. His profile says that he is from the Ukraine. I am from the U.S. | |
I mostly agree with the spirit of Paul's question. The license doesn't really grant you many rights that aren't already covered by most modern democracies, whether it's written law or legal precedent. It's only a minor nuisance to include copyright notices from a purely pragmatic standpoint, but it's irksome nonetheless. When I include the MIT license with software that I wrote, I am first annoyed that the lawyers won. More importantly, I feel that including the license reframes the debate about free software in the wrong direction. In my opinion, software should be naturally free, and you would only ever include licenses with non-free software. | |
I would support a law that said all software was implicitly covered by the MIT licen |
This file contains 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 wildcards(path): | |
parts = path.split('/') | |
parts = filter(bool, parts) | |
def generate(parts): | |
if len(parts) == 0: | |
yield [] | |
return | |
head = parts[0] | |
rest = parts[1:] | |
for rest in generate(rest): |
This file contains 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 random | |
import time | |
import os | |
class SmartDir: | |
def __init__(self, path): | |
self.path = path | |
self.buckets = 50 | |
def clear(self): |
This file contains 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
# This is the world's most boring and predictable web server. Its purpose in life is | |
# to facilitate testing of upstream load balancers. The web server is light, so you can | |
# deploy a bunch of them. If you hit any instance of this web server in a browser | |
# (presumably via a load balancer, then the page will always tell you who's listening.) | |
# There's also a simple back door to kill it. It doesn't serve any actual content. | |
import time | |
import sys | |
import re | |
import os |