Skip to content

Instantly share code, notes, and snippets.

View thisfred's full-sized avatar

eric casteleijn thisfred

View GitHub Profile
# given this decorator:
def my_decorator(function):
"""A decorator that does nothing."""
return function
# this code:
@my_decorator
def my_function():
pass
@thisfred
thisfred / seeding.py
Created October 14, 2018 16:06
seeding script + input and output
from pprint import pprint
import random
import csv
seed = 'then'
random.seed(seed)
with open('tournament.csv', 'r', newline='') as f:
players = []
for row in csv.reader(f):
Player name,ELO
HijabiKathy,887
Ugo Flickerman,1099
Rinderteufel,1134
N3rdicus,1241
SilkyZ,1259
Lyrelda,1266
GFX47,1353
Paragod,1452
The Great Eye,1792
from itertools import izip
def main():
original = izip(range(10), range(10))
counts = [0]
def counting(wrapped):
for i in wrapped:
counts[0] += 1

Tech Books I'd Recommmend

Test Driven Development by Example, Kent Beck

This book is the best introduction to TDD I've seen, and for such a tiny book, has a surprising amount of depth. The examples are in Python, but are simple enough that they'd be easily translated into any language. I've gotten new things out of it every time I've reread it, and it's one of the few tech books I have actually gone back and reread.

Refactoring, Martin Fowler

A classic, and with good reason. It's a great reference to have around, but it also includes some more general chapters that are well worth reading. If you like this book, I also recommend 'Refactoring to Patterns', by Joshua Kerievsky, which is a similar catalog of refactorings, but to (and equally importantly, away from) some of the design patterns in the Gang of Four book.

{
"name": "Dorkwood",
"author": "Eric Casteleijn",
"color": [
"#615d44",
"#9c656a",
"#c9c7a5",
"#bea474",
"#305e53",
"#c5a2ab",
"""Module to demonstrate an error."""
def main():
"""Function to demonstrate an error."""
val = False
if val:
first = 42
for _ in []:
second = 42
print first, second
KeyError('cache-dir',)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/neovim/msgpack_rpc/session.py", line 177, in handler
rv = self._request_cb(name, args)
from mymodule import my_add
def test_adds_up_correctly():
assert my_add(2, 2) == 4
from math import log
l = [1,23,456]
total = 0
x = 0
for n in reversed(l):
total += n * 10 ** x
x = int(log(total, 10)) + 1