Skip to content

Instantly share code, notes, and snippets.

@binarymatt
binarymatt / gist:4536149
Last active December 11, 2015 03:09
cornice with sqlalchemy
from cornice.resource import resource
def dbresource(**kw):
"""Class decorator to declare CRUD classes.
"""
def wrapper(klass):
setattr(klass, kw.pop('mapping'))
setattr(klass, kw.pop('session'))
setattr(klass, kw.pop('match_key', 'id'))
setattr(klass, kw.pop('primary_key', 'id'))
@view_config(route_name='my-route')
def my_view(request):
# here i want to know if path-1 or path-2 was taken, preferably via a var n matchdict?
if request.matched_route.name == 'my-route2':
# do extra work
config.add_route('my-route', '/path-1/view')
config.add_route('my-route2', '/path-2/view')
class AccountEvent(object):
def __init__(self, request, user):
self.user = user
self.request = request
class SignupEvent(AccountEvent):
pass
class LoginEvent(AccountEvent):
pass
@binarymatt
binarymatt / gist:5978228
Created July 11, 2013 19:00
python is awesome
import collections
def extract_top_ten(str):
return collections.Counter(str.split()).most_common(10)
@binarymatt
binarymatt / gist:6814187
Last active December 24, 2015 14:39
check for iphone 5s
import requests
parts = {
'GRAY': 'ME344LL/A',
'SILVER': 'ME345LL/A'
}
url_template = 'http://store.apple.com/us/retail/availabilitySearch?parts.0={}&zip={}'
def send_notice():
pass
@binarymatt
binarymatt / tariff.py
Last active January 2, 2016 12:39
factory method
from .base import AbstractTariff
from .us import USTariff
from .ca import CATariff
def factory(name):
mod = sys.modules[__name__]
classname = '{}Tariff'.format(name)
return getattr(mod, classname, None)

Keybase proof

I hereby claim:

  • I am binarydud on github.
  • I am mattg (https://keybase.io/mattg) on keybase.
  • I have a public key whose fingerprint is 84F7 580E 24CE 33D1 8B49 2F29 DC60 0858 4A6F 5CB2

To claim this, I am signing this object:

#!/usr/bin/python
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford ([email protected])
# The author disclaims copyright to this source code.
# Quickly and dirtily modified by Mustafa Al-Bassam ([email protected]) to test
# the Alexa top X.
# Modified by Matt George (mgeorge@gmail) to test arbitrary domains

Keybase proof

I hereby claim:

  • I am binarydud on github.
  • I am mattg (https://keybase.io/mattg) on keybase.
  • I have a public key whose fingerprint is E61B 4499 CE2A 932A 35F7 BF84 8D45 DFEE 618B 520A

To claim this, I am signing this object:

from hypothesis.testdecorators import given
def me(x,y):
if x < y:
raise Exception('this is an error')
return True
def test_answer():
assert me(5,3) == True
@given(int, int)