Skip to content

Instantly share code, notes, and snippets.

View rufuspollock's full-sized avatar
🌎
Nothing, nowhere and all of it

Rufus Pollock rufuspollock

🌎
Nothing, nowhere and all of it
View GitHub Profile
@rufuspollock
rufuspollock / annotator-openshakespeare-example.js
Created June 10, 2011 11:36
Example of using Annotator in OpenShakespeare.org
jQuery(function ($) {
var elem = $('#text-to-annotate');
var account_id = '39fc339cf058bd22176771b3e3036609';
var annotator_store = '/annostore' + '/api';
var userid = '';
var options = {};
options.permissions = {};
options.permissions.user = {
'name': '194.104.70.73'
};
@rufuspollock
rufuspollock / ckan-data-preview-sample-dataset
Created October 9, 2011 11:23
CKAN Data Preview Sample Dataset
import ckanclient
base_location = 'http://localhost:5000/api'
api_key = 'tester'
client = ckanclient.CkanClient(base_location, api_key)
pkg = dict(
name='test-ckanext-datapreview',
title='Test CKANext Data Preview',
resources=[
dict(
@rufuspollock
rufuspollock / userstories.py
Created November 7, 2011 19:05
Get user stories out a spreadsheet and into mediawiki syntax
# Get user stories out a spreadsheet and into mediawiki syntax
#
# Designed for this set here
# https://docs.google.com/spreadsheet/ccc?key=0Aon3JiuouxLUdFhMVEVFWXhxWXRKaU04LUF2ZTVsTVE&hl=en_GB#gid=0
# Pass it link to gdocs csv as argument on command line
# E.g.
#
# python userstories.py "https://docs.google.com/spreadsheet/pub?hl=en_GB&hl=en_GB&key=0Aon3JiuouxLUdFhMVEVFWXhxWXRKaU04LUF2ZTVsTVE&single=true&gid=0&output=csv"
#
import urllib
@rufuspollock
rufuspollock / openspending-local-load-step-by-step.rst
Created November 11, 2011 14:36
OpenSpending local dataset load from command line

Test model (dimensions and mapping):

ostool cfg.ini csvimport --model=model.json --dry-run --raise-on-error --max-lines=1 data.csv

Dry run:

ostool cfg.ini csvimport --model=model.json --dry-run data.csv
@rufuspollock
rufuspollock / ckan-es-webstore-test-full.py
Created February 28, 2012 08:20
CKAN ES Webstore Test Full (Read/Write)
'''This is a test using the real setup with elasticsearch.
It requires you to run nginx on port 8088 with config as per
https://github.com/okfn/elastic-proxy/blob/master/elasticproxy plus,
obviously, elasticsearch on port 9200.
'''
import json
import paste.fixture
import paste.proxy
@rufuspollock
rufuspollock / resource-view-demo-data.py
Created February 28, 2012 08:24
Script to Create Demo Resources for Testing Resource Viewer
'''Simple script for creating demo data in CKAN
Requires existence of a tester user. You can create this by doing::
paster create-test-data user
'''
import ckanclient
base_location = 'http://localhost:5000/api'
api_key = 'tester'
@rufuspollock
rufuspollock / ckan-datastore.py
Created March 1, 2012 15:39
CKAN DataStore client
#!/usr/bin/env python
import urlparse
import mimetypes
import os
import ConfigParser
import urllib2
import json
import csv
import time
import csv
import json
import geojson
fp = 'data/US_Rendition_FOIA.csv'
fpout = 'data/US_Rendition_FOIA.geojson.csv'
jsonout = 'data/US_Rendition_FOIA.geojson.json'
jsondata = []
def convert():
@rufuspollock
rufuspollock / world-bank-pop-sample-xml.xml
Created May 24, 2012 09:35
World Bank Population - Sample XML data
<?xml version="1.0" encoding="utf-8"?>
<Root xmlns:wb="http://www.worldbank.org">
<data>
<record>
<field name="Country or Area" key="ARB">Arab World</field>
<field name="Item" key="SP.POP.TOTL">Population, total</field>
<field name="Year">1960</field>
<field name="Value">96388069</field>
</record>
<record>
@rufuspollock
rufuspollock / note-load.js
Created June 2, 2012 11:30
Time/Geo notes and script to parse notes and save to file or load to ElasticSearch
// Parse a summary to extract title, tags, location and start and end
parseNoteSummary = function(text) {
var result = {
title: '',
tags: []
};
var ourtext = text;
regex = / #([\w-\.]+)/;
while(ourtext.search(regex)!=-1) {
var out = ourtext.match(regex)[1];