Skip to content

Instantly share code, notes, and snippets.

View greglinch's full-sized avatar

Greg Linch greglinch

View GitHub Profile
function menu_order_filter($menu) {
//
// reorder the menu here by operating on $menu
// which is an array with position => 'url';
// separators will appear as
// 'separator1', 'separator2' ... 'separator-last'
//
// example:
// Array
// (
@onyxfish
onyxfish / Advice from #djangocon 2010 Django-in-Journalism open-session
Created September 9, 2010 17:31
Advice from #djangocon 2010 Django-in-Journalism open-session
Suggestions from the 11 hackers at the table:
* Use connection pooling (pgpool).
* Don't expect reporters to get excited until you can show them something. (Find a way to appeal to reporters interests.)
* Only update what's changed. (e.g. on election results: show changes, not raw numbers)
* Use the AP's "dbready" format for election results.
* Use CSV for everything.
* Use pdb with runserver for debugging.
* Beware circular imports when using Haystack.
* Make the case for building news apps with government data. (Niran will provide numbers showing that people look at it.)
@eyeseast
eyeseast / documentcloud.py
Created December 15, 2010 03:00
A simple python wrapper for the DocumentCloud API
import httplib2
import urllib
try:
import json
except ImportError:
import simplejson as json
# create a global Http object so we can reuse connections
http = httplib2.Http('.cache')
<?php
/* use a regular expression to remove inline comments. in this case, everything gets removed if it's inside double at signs. @@so you could CQ this@@ */
function filter_remove_inline_comments($content) {
return preg_replace('/@@.*?@@/', '', $content);
}
add_filter('the_content', 'filter_remove_inline_comments', 5);
?>
var stateToAP = function(state) {
var STATES = [
["Alabama", "AL", "Ala.", 1],
['Alaska', "AK", "Alaska", 2],
["Arizona", "AZ", "Ariz.", 4],
["Arkansas", 'AR', "Ark.", 5],
["California", "CA", "Calif.", 6],
["Colorado", "CO", "Colo.", 8],
["Connecticut", "CT", "Conn.", 9],
["Delaware", "DE", "Del.", "10"],
@kjam
kjam / twitter_example.html
Created July 21, 2011 15:09
Twitter Search
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.getJSON('http://search.twitter.com/search.json?q=earthquake&lang=en&callback=?', function(data) {
var data = data.results;
var html = "<ul>";
for(var i=0; i<data.length; i++) {
html += "<li><a href='http://twitter.com/" + data[i].from_user + "'>@"
@MacMaru
MacMaru / wrap_view.py
Created July 31, 2011 16:59
Override Tastypie wrap_view() to return custom (JSON) response
class YourResource(ModelResource):
def wrap_view(self, view):
"""
Wraps views to return custom error codes instead of generic 500's
"""
@csrf_exempt
def wrapper(request, *args, **kwargs):
try:
@dwillis
dwillis / gist:1189275
Created September 2, 2011 17:46
Who Needs to Write Scrapers?
cd my_download_dir
curl http://apps.sd.gov/applications/ST12ODRS/LobbyistViewlist.asp?start=[1-8101:20] -o "lobby_#1.html"
# get a cup of coffee
cat lobby*.html > master.html # on mac/linux, on windows try copy lobby*.html master.html
-----
Then open master.html in a text editor, do some smart bulk find and replaces, and you'll be in business. After opening the cleaned up file in Excel, you'll need to un-merge the cells and do a little more cleanup, but it works.
@palewire
palewire / dorling.py
Created September 20, 2011 08:26
Takes a GeoDjango queryset and creates a cartogram of circles based on the Dorling algorithm.
import math
from django.contrib.gis.geos import Point
class Cartogram(object):
"""
Takes a GeoDjango queryset and creates a cartogram of circles based on
the Dorling algorithm.
User must provide a queryset and strings pointing to the data attribute
@HarlanH
HarlanH / DSDC-Titles.R
Created September 26, 2011 12:44
Data Science DC Titles Visualization
# Data Science DC Titles Visualization
# Here's how this will work. In a main loop, a parameterized visualization function
# is called every N seconds. Each function gets the source spreadsheet fresh, and
# generates a visual.
# aspects of this code borrowed from Drew Conway:
# https://raw.github.com/drewconway/ZIA/master/R/better_word_cloud/better_word_cloud.R
library(plyr)