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 fizzbuzz(start=1, end=100, fizzval=3, buzzval=5): | |
"""Implements Reginald Braithwaite's FizzBuzz text.""" | |
for i in range(start, end+1): | |
fizz = 'Fizz' if i % fizzval == 0 else '' | |
buzz = 'Buzz' if i % buzzval == 0 else '' | |
print i if fizz+buzz == '' else fizz+buzz |
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
<textarea style="width: 90%; height: 90%; display: block; margin: 2% auto auto auto;"></textarea> | |
<!-- open this in a modern browser and you have built-in spell checking with no other clutter --> |
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 make_table(data, delim='\t', table_id='make_table', classname=''): | |
""" | |
Converts delimited data into an HTML table. | |
- `data` is a string, with rows delimited by newlines. | |
- Default cell delimiter for each row is a tab. | |
""" | |
output = [] | |
output.append('<table id="%s" class="%s">' % (table_id, classname)) | |
for row in data.strip().split('\n'): | |
cells = row.strip().split(delim) |
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 | |
""" | |
Simple command-line based Rock Paper Scissors game in Python. | |
""" | |
import random | |
vals = 'R P S'.split(' ') | |
msg_win = "You win this round." | |
msg_lose = "You lose this round." | |
msg_tie = "Tie! You both picked " |
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] |
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
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
<!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
#!/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. |