Skip to content

Instantly share code, notes, and snippets.

@huntcsg
huntcsg / parse_csv.py
Created October 10, 2019 14:58
A csv parsing pattern
import csv
class validator:
VALIDATORS = {}
@classmethod
def validate(cls, key, value):
return cls.VALIDATORS.get(key, lambda x: x)(value)

Keybase proof

I hereby claim:

  • I am huntcsg on github.
  • I am hsenftgrupp (https://keybase.io/hsenftgrupp) on keybase.
  • I have a public key ASBgrWC4Qjfc31_su-avYtrJH3Duuh8lzg06T-aPo0--4wo

To claim this, I am signing this object:

@huntcsg
huntcsg / lazy.py
Last active January 14, 2018 17:48
This defines a decorator and a class representing a very simple implementation allowing for making functions lazy, and chaining those functions (within the recursion limit).
from functools import wraps
class LazyFunction:
def __init__(self, fn, args, kwargs):
self.fn = fn
self.args = args
self.kwargs = kwargs
@huntcsg
huntcsg / return_val.py
Created June 14, 2017 16:19
Getting the return value from a generator
def get_data_with_return():
for i in range(5):
yield i
return "I finished my task."
data = get_data_with_return()
while True:
try:
print("In iteration: {}".format(next(data)))
except StopIteration as e:
@huntcsg
huntcsg / spyre app multi site
Last active August 29, 2015 14:16
Adding Multi site capabilities to the spyre app
######################################################################
# This is how to use the server.Site class
######################################################################
site = server.Site(SimpleSineApp)
# You can change the top of the tree by passing your app class definition to the .addRoot method. I think a best practice would be
# to define this when you initilize your server.Site object. However, if for some reason you need to set the root at a different
# time, this is the method to do so.
#site.addRoot(SimpleSineApp)