Skip to content

Instantly share code, notes, and snippets.

View j2labs's full-sized avatar

The Ghost Of J2 Labs j2labs

View GitHub Profile
@j2labs
j2labs / gist:5892515
Created June 29, 2013 20:21
Example of using Python's csv module with DictReader
#!/usr/bin/env python
import csv
import json
# Get graffiti_locations.csv from:
# https://nycopendata.socrata.com/Social-Services/Graffiti-Locations/2j99-6h29?
filename = 'graffiti_locations.csv'
@j2labs
j2labs / gist:5892509
Created June 29, 2013 20:18
Basic example of using Python's csv module
#!/usr/bin/env python
# Try putting this data in a file called 'band.csv'
# James,Dennis,Drums,punk
# Rob,Spectre,Guitar,punk
import csv
import json

Subject: Round 24: My BLT drive just went AWOL

(Have a complaint about this email? Want to make it better, fix a typo, or add more info? Fork the gist on GitHub! Or, click through to read a rendered version.)

Hello Hackers-

@j2labs
j2labs / password_maybe.py
Created May 20, 2013 16:01
Password field for Schematics
>>> from schematics.models import Model
>>> from schematics.serialize import whitelist, blacklist
>>> from schematics.types import BaseType, StringType
>>> from schematics.exceptions import ValidationError
>>> import hashlib
>>> import random
>>>
>>> class PasswordType(BaseType):
... ALGORITHM = 'MD5'
... def __init__(self, **kw):
>>> class ModelMeta(type):
... def __new__(cls, name, bases, attrs):
... for base in reversed(bases):
... print 'Base:', base
... return type.__new__(cls, name, bases, attrs)
...
>>>
>>> class A(object):
... def __init__(self):
... print 'A'
@j2labs
j2labs / validation_min.py
Created May 16, 2013 11:40
Testing the plain-vanilla Schematics branch.
#!/usr/bin/env python
import hashlib
from schematics.models import Model
from schematics.serialize import whitelist, blacklist
from schematics.types import MD5Type, StringType
from schematics.exceptions import ValidationError
>>> class ModelOptions(object):
... def __init__(self, klass, namespace=None, roles={}):
... self.klass = klass
... self.namespace = namespace
... self.roles = roles
...
>>> mo1 = ModelOptions('foo')
>>> mo2 = ModelOptions('bar')
>>> mo1.roles['foo'] = 'foooooooo'
>>> mo2.roles
>>> from schematics.models import Model
>>> from schematics.types import StringType, IntType, DateTimeType, BooleanType
>>> from schematics.types.compound import ModelType, ListType
>>> from schematics.exceptions import ValidationError
>>> from schematics.serialize import whitelist
>>> class Game(Model):
... opponent_id = IntType(required=True)
...
>>> class Player(Model):
... total_games = IntType(min_value=0, required=True)
@j2labs
j2labs / gist:5081768
Last active December 14, 2015 11:48
>>> from schematics.models import Model
>>> from schematics.types.base import StringType, DateTimeType, IntType, BooleanType
>>> from schematics.types.compound import ListType, ModelType
>>>
>>> class ProtoStep(Model):
... step_type = StringType(required=True) # enum type?
... deadline = DateTimeType()
...
>>> class DocumentStep(ProtoStep):
... doc_name = StringType()
@j2labs
j2labs / gist:4022076
Created November 6, 2012 02:05
Sarah Palin joke inside Schematics.
# Remove rogue fields
if len(class_fields) > 0: # if accumulation is not disabled
palins = data_fields - set(class_fields)
for rogue_field in palins:
del values[rogue_field]