Skip to content

Instantly share code, notes, and snippets.

@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 / 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)
class AccountEvent(object):
def __init__(self, request, user):
self.user = user
self.request = request
class SignupEvent(AccountEvent):
pass
class LoginEvent(AccountEvent):
pass
@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')
@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'))
@binarymatt
binarymatt / field.py
Created November 28, 2012 20:57 — forked from commadelimited/field.py
Widget form field
trial_length = forms.IntegerField(widget=forms.TextInput(attrs={'size': '3', 'maxlength': '2'}), label='Number of days in Trial period', required=False)
@binarymatt
binarymatt / gist:3362648
Created August 15, 2012 19:06
broken setup.py
import os
from setuptools import setup, find_packages
version=__import__('django_pyres').__version__
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
setup(
name='django-pyres',
version=version,
description='django pyres integration',
long_description=read('README.md'),
@binarymatt
binarymatt / gist:3188630
Created July 27, 2012 15:22
Postgis on a mac

Developer Setup

  1. Setup homebrew:

    /usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
    

    Then:

@binarymatt
binarymatt / gist:3183924
Created July 26, 2012 19:17
Developer Setup

Developer Setup

  1. Download Xcode from the mac app store

  2. Setup homebrew_:

    /usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
    
@binarymatt
binarymatt / gist:3102435
Created July 13, 2012 03:08
pyramid all in one route defintion
import venusian
class route(object):
venusian = venusian
def __init__(self, name, url):
self.name = name
self.url = url