Skip to content

Instantly share code, notes, and snippets.

import sys
def bad_line(line, index):
if line[index] != 'U':
return True
def process_file(f, index):
index = int(index)
bad_records = []
for i,line in enumerate(f):
if line.strip():
@binarymatt
binarymatt / s3stream.py
Created June 5, 2012 16:28
stream upload to s3
import sys, StringIO
import argparse
from boto.s3.connection import S3Connection
def read_in_chunks(file_object, chunk_size=1024):
"""Lazy function (generator) to read a file piece by piece.
Default chunk size: 1k."""
while True:
data = file_object.read(chunk_size)
if not data:
break
@binarymatt
binarymatt / gist:3030583
Created July 2, 2012 02:33
pyres decorator
from pyres import ResQ
def job(queue, resq=ResQ(),debug=False):
def wrapper(func):
def enqueue(*args):
if not debug:
class_name = '%s.%s' % (func.__module__, func.__name__)
resq.enqueue_from_string(class_name, queue, *args)
else:
return func(*args)
def lookup(records, zipcode):
new_list = []
for item in record:
new_list.append(item/global_lookup(zipcode))
return new_list
map(lookup, [array of lists],[zipcode for range(len([array of lists])))
@binarymatt
binarymatt / gist:3084475
Created July 10, 2012 16:29
raffle chooser
import random
f = open('raffle_recipients.txt')
recipient_list = set([i.strip() for i in f.readlines()])
chooser = random.SystemRandom()
print chooser.sample(recipient_list, 2)
@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
@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: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: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 / 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)