Skip to content

Instantly share code, notes, and snippets.

Copyright 2010 Aaron Bycoffe. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
import Image
import sys
def make_image(color, filename, dimensions=(1,1)):
"""Create a solid-color image."""
im = Image.new('RGB', dimensions, color)
im.save(filename)
if __name__ == '__main__':
# Testing goat. Via http://valkyrie.kwister.com/home/ascii/mygoat.html
______._
/ / \ \
/ / / /
\ \
\ \____.
/ / \\
/ @ \ / \,
/ \/ \___ _______
\____/ \ `--------' `-,
# http://xkcd.com/710/
# An iterator for showing the Collatz Conjecture
"""
>>> [x for x in Collatz(6)]
[3, 10, 5, 16, 8, 4, 2, 1]
>>> [x for x in Collatz(11)]
[34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
>>> len([x for x in Collatz(27)])
@bycoffe
bycoffe / ncaa_basketball_scores.py
Created March 19, 2010 17:14
Script to allow viewing of scores of in-progress college basketball games on the command line
#!/usr/bin/env python
"""
Python script to allow viewing of scores of in-progress college basketball games
on the command line. Scores come from Yahoo Sports.
Requirements:
BeautifulSoup
"""
import re
import urllib2
def datechunk(start, end, days):
"""
Create a generator of (start_date, end_date) tuples
where the difference between start_date and end_date
is the number of days given.
>>> list(datechunk(datetime.date(2010, 01, 01), datetime.date(2010, 08, 20), 30))
[(datetime.date(2010, 1, 1), datetime.date(2010, 1, 31)),
(datetime.date(2010, 2, 1), datetime.date(2010, 3, 3)),
(datetime.date(2010, 3, 4), datetime.date(2010, 4, 3)),
class FixedWidthParser(object):
"""A parser for fixed-width data files. Pass in a data file and
a list of field names and lengths, and get back a dictionary
for each row.
Useful for converting a fixed-width file to a CSV.
See tests.py for a usage example.
"""
#!/usr/bin/python
'''
Python-based gift exchange randomizer.
Step through a list of people and, for each member of that list,
select someone else to be a recipient of their gift. That recipient:
A) Must not be themselves (no self-gifting)
B) Must not already have been assigned as a recipient
@bycoffe
bycoffe / fapiis_scraper.py
Created April 20, 2011 13:33
First pass at scraping the FAPIIS site, just to see if it's possible.
"""
First pass at scraping the FAPIIS site, just to see if it's possible.
This seems to work, but it's impossible to know whether the data it's
returning will be accurate since FAPIIS doesn't currently contain any
data.
This method requires knowing the company's DUNS number, though it's
likely possible to back this up a step to allow for searching by name.
"""
import urllib
@bycoffe
bycoffe / google-charts.coffee
Created September 9, 2011 16:23
Basic Google Charts API wrapper in CoffeeScript
class window.GoogleChart
constructor: ->
@width = 0
@height = 0
@encoded = []
@data = []
simpleEncoding: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
extendedMap: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.',