Skip to content

Instantly share code, notes, and snippets.

@chooper
chooper / brokenrng.py
Created March 8, 2011 13:34
A 'broken' Random Number Generator. Always throws 2 after 6
#!/usr/bin/env python
from random import randint
class BrokenRNG():
"""A 'broken' Random Number Generator. Always throws 2 after 6"""
last_state = None
def __iter__(self):
@chooper
chooper / group_by_letter.py
Created June 28, 2011 04:45
Group words by their first letter
#!/usr/bin/env python
"""Group words by their first letter"""
from collections import defaultdict
def group_by_letter(words):
buckets = defaultdict(lambda:[])
for word in words:
buckets[word[0].lower()].append(word)
@chooper
chooper / merge_lists.py
Created June 29, 2011 20:11
Merging list of lists in Python using reduce()
#!/usr/bin/env python
"""Merging list of lists in Python using reduce()"""
def merge_lists(list_of_lists):
return reduce(lambda x,y: x+y, list_of_lists)
if __name__ == '__main__':
my_big_list = [ [1,2,3], [3,4,5], [6,7,8], ]
print merge_lists(my_big_list)
@chooper
chooper / sslwrap.py
Created January 21, 2012 16:24
SSL Socket Context Manager
#!/usr/bin/env python
__author__ = 'Charles Hooper <charles.hooper@dotcloud.com>'
import socket, ssl
socket.setdefaulttimeout(3)
class EasySSLWrap(object):
"""Connect over TCP+SSL using a context manager.
Usage:
@chooper
chooper / statsd_instrument.py
Created March 11, 2012 22:04
Decorator to quickly add statsd (graphite) instrumentation to Celery task functions.
"""Decorator to quickly add statsd (graphite) instrumentation to Celery
task functions.
With some slight modification, this could be used to instrument just
about any (non-celery) function and be made abstract enough to customize
metric names, etc.
Stats reported include number of times the task was accepted by a worker
(`started`), the number of successes, and the number of times the task
raised an exception. In addition, it also reports how long the task took
@chooper
chooper / zerorpc_client_with_retry.py
Created August 25, 2012 04:19
Automatically retry failed zerorpc requests
class ClientWithRetry(zerorpc.Client):
"""Wrapper of zerorpc.Client to automatically retry failed
requests."""
def __init__(self,retry_attempts,retry_delay,*args,**kwargs):
self._retry_attempts = retry_attempts
self._retry_delay = retry_delay
zerorpc.Client.__init__(self,*args,**kwargs)
def __call__(self,*args,**kwargs):

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discussions around concrete examples, not handy-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discussions around concrete examples, not handy-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@chooper
chooper / door-irb-output.log
Created November 1, 2013 20:53
Just some playing around with a state machine representing a door that can lock, with "locked" being a separate state from "closed"
sub@asdf:~/projects/fsm$ irb -I
irb(main):001:0> require './door.rb'
=> true
irb(main):002:0> front_door = Door.new
=> #<Door:0x00000001913ab0 @state="closed">
irb(main):003:0> front_door.open_
Transition: closed => open
=> true
irb(main):004:0> front_door.close
Transition: open => closed
@chooper
chooper / Gemfile
Last active August 29, 2015 13:56 — forked from jimdanz/customer_fetch.rb
source "http://rubygems.org"
gem "stripe"