Skip to content

Instantly share code, notes, and snippets.

View robcowie's full-sized avatar

Rob Cowie robcowie

  • Recycleye
  • Leeds/London, United Kingdom
View GitHub Profile
@robcowie
robcowie / cal.html
Created January 21, 2011 16:51
calendar.HTMLCalendar subclass that adds class='today' to the appropriate <td>. Also an example html doc with styling.
<html>
<head>
<title>untitled</title>
<style>
#calendar {
border: 1px solid grey;
width: 310px;
background-color: #5C9DB7;
border-radius: 5px;
-moz-border-radius: 5px;
@robcowie
robcowie / mysqldb_query_generator.py
Created February 7, 2011 16:05
Memory-efficient, streaming query generator with MySQLdb
from MySQLdb.cursors import SSDictCursor
def iterate_query(query, connection, arraysize=1):
c = connection.cursor(cursorclass=SSDictCursor)
c.execute(query)
while True:
nextrows = c.fetchmany(arraysize)
if not nextrows:
break
@robcowie
robcowie / substrings.py
Created February 14, 2011 16:56
Substrings in order, left to right
def substrings(s):
length = len(s)
for i in range(length):
for ii in range(i, length):
yield s[i:ii+1]
@robcowie
robcowie / syntax_highlighter.py
Created February 28, 2011 22:37
Write highlighted python code to console
"""
$ pip install pygments
"""
import sys
from pprint import pformat
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import TerminalFormatter
@robcowie
robcowie / mailing_list.rst
Created March 13, 2011 18:38
Outline for a lamson-bsaed email mailing list app

Mailing List App

  • Web UI
  • Create lists
  • View mails
  • Per-list config
    • Recipients
    • Signatures
    • Temporary blocks on recipients
    • Attachment handling (disallowreplace with url)
@robcowie
robcowie / countries.csv
Created April 4, 2011 14:05
Create a table of Countries with ISO codes
alpha2 alpha3 numeric name
AF AFG 004 Afghanistan
AX ALA 248 Åland Islands
AL ALB 008 Albania
DZ DZA 012 Algeria
AS ASM 016 American Samoa
AD AND 020 Andorra
AO AGO 024 Angola
AI AIA 660 Anguilla
AQ ATA 010 Antarctica
@robcowie
robcowie / currency.sql
Created April 4, 2011 14:13
Create a table of currencies with symbols
CREATE TABLE `currency` (
`code` varchar(4) NOT NULL,
`name` varchar(64) NOT NULL,
`major_symbol` char(3) DEFAULT NULL,
`minor_symbol` char(3) DEFAULT NULL,
PRIMARY KEY (`code`)
) DEFAULT CHARSET=utf8;
INSERT INTO `currency` (`code`,`name`,`major_symbol`,`minor_symbol`)
VALUES
@robcowie
robcowie / greenway.kml
Created April 4, 2011 18:50
Route of The Greenway, London
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<name>Greenway.kml</name>
<Style id="sh_ylw-pushpin">
<IconStyle>
<scale>1.3</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
@robcowie
robcowie / uk_marine_weather.py
Created April 17, 2011 15:54
Pull latest readings from Met Office marine stations
# -*- coding: utf-8 -*-
"""
# Pull latest 24 hour data every x hours
# 46 locations, 402,960 data points per year
marine.find({'location':'aberporth'})
marine.find({'location':'aberporth', 'day':19, 'month':3, 'year':2011})
marine.find({'location':'aberporth', 'datetime': datetime(19, 3, 2011, 21, 0)})
marine.find({'datetime': datetime(19, 3, 2011, 21, 0)})
@robcowie
robcowie / zalgo.py
Created May 4, 2011 16:14
Port of the Zalgo translator at http://eeemo.net
# -*- coding: utf-8 -*-
"""Port of the Zalgo translator at http://eeemo.net/
To invoke the hive-mind representing chaos.
Invoking the feeling of chaos.
With out order.
The Nezperdian hive-mind of chaos. Zalgo.
He who Waits Behind The Wall.
ZALGO