Skip to content

Instantly share code, notes, and snippets.

pager less -niSFX
"""
A small Django app I built last year that looked for people on Twitter saying they were sick.
An example of using Twitter search.
"""
# models.py
from django.contrib.gis.db import models
"""
Like cut, but for CSVs. To be used from a shell command line.
Change row[1] to the row index to be printed. row[1] will print the second
item in the row.
"""
python -c 'import sys, csv
for row in csv.reader(sys.stdin):
print row[1]' < filename.csv
@bycoffe
bycoffe / csvcut
Created September 14, 2009 18:19 — forked from JoeGermuska/csvcut
#!/usr/bin/env python
"""
Like cut, but for CSVs. To be used from a shell command line.
Note that fields are zero-based, as opposed to 'cut' where they are 1-based.
Leveraged from/motivated by an example from @bycoffe
Usage:
csvcut foobar.csv
@bycoffe
bycoffe / csvcut
Created September 15, 2009 13:08 — forked from JoeGermuska/csvcut
#!/usr/bin/env python
"""
Like cut, but for CSVs. To be used from a shell command line.
Note that fields are zero-based, as opposed to 'cut' where they are 1-based.
Should use something better than getopt, but this works...
Usage:
csvcut foobar.csv
@bycoffe
bycoffe / count
Created September 25, 2009 13:40
Count the number of occurrences of each line in a file.
#!/bin/bash
# Count the number of occurrences of each line in a file.
#
# Example:
#
# test.txt:
# A
# A
# B
#!/usr/bin/env python
"""
Copyright (c) 2009, 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.
@bycoffe
bycoffe / testcsv.csv
Created October 23, 2009 16:49
Test CSV file for csvtosqlite
City Latitude Longitude
Autauga, AL 32.5791817 -86.4996546
Baldwin, AL 30.6010744 -87.7763333
Barbour, AL 31.8172896 -85.354965
Bibb, AL 32.9562798 -87.1422895
Blount, AL 34.0145152 -86.4996546
Bullock, AL 32.0573536 -85.7256372
Butler, AL 32.091673 -88.221233
Calhoun, AL 33.7701576 -85.80766
Chambers, AL 32.9028048 -85.354965
@bycoffe
bycoffe / csvtosqlite.py
Created October 23, 2009 16:52
Creates a sqlite database and table from a CSV file for easier querying
"""
Copyright (c) 2009, 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
from django.template import Library
register = Library()
@register.filter_function
def html5datetime(date):
"""Format a date or a date and time according to the HTML 5 specifications,
so it may be used as the value for a datetime attribute of a time tag.
Most of the date formatting could be done in the template with the built-in