This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""My Python port of Zack Holman's spark shell script: https://github.com/holman/spark | |
This: | |
you@computer:~$ python spark.py 100 20 80 40 60 | |
Should return this: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"d":[ | |
{"NameOfBeach":"Bayfront Beach","OpenClosed":"CLOSED","DateofSampling":"2011-08-17","Group":"Hamilton Harbour"}, | |
{"NameOfBeach":"Pier 4 Beach","OpenClosed":"CLOSED","DateofSampling":"2011-08-17","Group":"Hamilton Harbour"}, | |
{"NameOfBeach":"Binbrook Conservation","OpenClosed":"Open","DateofSampling":"2011-08-17","Region":"Conservation Authority Beaches"}, | |
{"NameOfBeach":"Christie Conservation","OpenClosed":"Open","DateofSampling":"2011-08-17","Region":"Conservation Authority Beaches"}, | |
{"NameOfBeach":"Valens Conservation","OpenClosed":"Open","DateofSampling":"2011-08-17","Region":"Conservation Authority Beaches"}, | |
{"NameOfBeach":"Beach Boulevard","OpenClosed":"Open","DateofSampling":"2011-08-17","Region":"Lake Ontario"}, | |
{"NameOfBeach":"Van Wagners","OpenClosed":"CLOSED","DateofSampling":"2011-08-17","Region":"Lake Ontario"}, | |
{"NameOfBeach":"Confederation Park","OpenClosed":"Open","DateofSampling":"2011-08-17","Region":"Lake Ontario"} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
This script contains functions that: | |
* convert tabular data from the City's crossing guards web page [1] into a nested list; | |
* use the Google Maps API to get geocoding data for each location; and | |
* convert the whole thing into an SQL insert statement. | |
[1] http://www.hamilton.ca/CityDepartments/PlanningEcDev/Divisions/ParkingBylawServices/SchoolCrossing/SchoolCrossingGuardLocations.htm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib2 | |
try: | |
import json | |
except: | |
import simplejson as json | |
def short_url(long_url='http://raisethehammer.org') | |
""" | |
Takes a long URL and returns a short URL. | |
Uses the Google URL Shortener API: http://code.google.com/apis/urlshortener/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
__title__ = 'Google Beatbox GUI' | |
__version__ = 0.1 | |
""" | |
This program provides a simple GUI interface to create Google Beatbox beats. | |
Original idea here: http://news.ycombinator.com/item?id=1952356 | |
Drum Sounds defined: http://news.ycombinator.com/item?id=1952531 | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Grabs election data from the City of Hamilton's GEMS election data pages, converts it into a json object and an sql insert statement. | |
Yeah, I know: the code is seriously ugly-ass and inelegant. What the hell, it works. | |
Update: The City changed their election results pages and this script no longer works. I'm working on updating it. | |
Very Important Note: this code breaks on ward 14, where Rob Pasuta is acclaimed and there are no ward results on the web page. | |
Instead of fixing it in the code, for now I just fixed the SQL statement manually by removing the trustees from the results. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | |
<html> | |
<head> | |
<title>RTH Elections Site: Using JSON in PHP</title> | |
</head> | |
<body> | |
<h1>RTH Elections Site: Using JSON in PHP</h1> | |
<?php | |
$url = 'http://elections.raisethehammer.org/api/election/1'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib | |
import urllib2 | |
candidates = ['David Sweet', 'James W. Byron', 'Brad Clark', 'Terry Anderson', 'Stephen E. Brotherston', 'Dave Braden', 'Annie Tennier', 'Michelle Stockwell', 'Marie Bountrogianni', 'Nancy MacBain', 'David Christopherson', 'Wayne Marston', 'Chris Charlton', 'Peter Ormond', 'Karen Burson', 'David Hart Dyke', 'Dean Allison', 'Stephen Henry Bieda', 'David Heatley', 'Bryan Jongbloed', 'Jim Enos', 'Michael James Baldasaro', 'Jamile Ghaddar', 'Anthony Giles', 'Lisa Nussey', 'Wendell Fields', 'Bob Green Innes', 'Bob Mann', 'Greg Pattinson', 'Henryk Adamiec', 'Sid Frere', 'Gord Hill'] | |
url_template = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={{q}}&key={{key}}&userip={{userip}}' | |
key = 'YOUR-GOOGLE-API-KEY' | |
referer = 'http://your.domain.com' | |
userip = '127.0.0.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
def prepare(blob): | |
""" | |
Cleans up the City of Hamilton's blob of text from its candidates page and turns it into a list of dictionaries. | |
Here's the URL: http://www.hamilton.ca/CityDepartments/CorporateServices/Clerks/MunicipalElection/Nominated+Candidates.htm | |
We grabbed the source code for the candidates, minus the rest of the HTML boilerplate from the page, and added an octothorpe # before each ward heading to make the ward sections easier to parse. | |
""" | |
blobs = blob.split('\n# ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prepare(blob): | |
""" | |
Cleans up the City of Hamilton's blob of text from its candidates page and turns it into a list of dictionaries. | |
Here's the URL: http://www.hamilton.ca/CityDepartments/CorporateServices/Clerks/MunicipalElection/Nominated+Candidates.htm | |
""" | |
blobs = blob.split('\n# ') | |
wards = [] | |
for blob in blobs: | |
title = blob.split('\n')[0] |