Skip to content

Instantly share code, notes, and snippets.

View gka's full-sized avatar
🐢

Gregor Aisch gka

🐢
View GitHub Profile
@gka
gka / shape_center.py
Created October 26, 2011 07:58
Computes the center of a shapefile multi-polygon
"""
computes the center of a multi-polygon
"""
def shape_center(shape):
"""
computes the center of gravity of a shapefile multi-polygon
shape must be an instance of shapefile._Shape of the Python Shapefile Library
http://packages.python.org/Python%20Shapefile%20Library/
Polygon class comes from here
http://pypi.python.org/pypi/Polygon/1.17
@gka
gka / eu-disposable-incomes.csv
Created November 22, 2011 18:06
NUTS-2 Map of the European Union
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 3 columns, instead of 1. in line 1.
indic_na,unit,geo\time 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007
AT11 11523.9 11771.1 12318.3 13027.5 13923.5 13937.3 14402.1 15052.7 16057.0 16840.4 17825.5 18470.1
AT12 12871.0 13021.4 13665.6 14525.4 15537.4 15403.4 15765.8 16322.2 16928.0 17831.3 18813.9 19544.9
AT13 14683.3 14857.3 15374.7 16069.4 17056.0 16630.1 16928.8 17261.8 17699.9 18279.5 18977.4 19485.4
AT21 11795.8 11922.2 12421.4 13006.9 14042.2 13967.3 14393.7 14954.2 15521.1 16523.0 17420.1 18127.9
AT22 12031.6 12222.0 12755.1 13429.9 14425.1 14242.8 14685.7 15180.8 15686.9 16638.9 17560.7 18347.0
AT31 12460.4 12643.3 13179.3 13796.6 14869.5 14654.6 15008.0 15522.6 16281.2 17261.5 18266.9 18949.4
AT32 12879.1 12985.2 13544.3 14257.6 15264.9 15007.9 15416.9 15921.1 16505.8 17563.2 18509.2 19289.0
AT33 12029.3 12018.6 12697.8 13400.2 14507.7 14402.3 15030.8 15632.8 16203.9 17043.9 17868.1 18588.3
AT34 12591.4 12620.3 13488.1 14107.7 15568.7 15154.4 15641.8 16167.9 16716.1 17793.2 18803.9 19367.5
@gka
gka / scrape_party_members.py
Created December 26, 2011 22:41
prototype for scraper of german party members from wikipedia
# coding=utf-8
from wikitools import wiki
from wikitools import api
site = wiki.Wiki('http://de.wikipedia.org/w/api.php')
#
# returns a list of categories
#
def getPageCategories(pages):
@gka
gka / parsecss.js
Created January 8, 2012 20:58
CSS parsing in JavaScript
/**
* This is the light version of Danial Wachsstock's jQuery based CSS parser
* http://bililite.com/blog/2009/01/16/jquery-css-parser/#parserdetails
*
* Everything is removed but the core css2object parsing
*
* Usage is straight forward:
*
* $.parseCSS('body { background: red; font-weight: 300 }');
* // returns { 'body': { 'background': 'red', 'font-weight': 300 } }
@gka
gka / ender.loadassets.coffee
Created January 12, 2012 21:57
Ender extension for firing multiple ajax requests at once
Function::bind ?= (scope) ->
_function = this
() ->
_function.apply scope, arguments
$.ender
loadAssets: (opt) ->
data = {}
cnt = 0
for id of opt.assets
@gka
gka / map.svg
Created January 17, 2012 23:16
world map with countries joined to UN regions
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gka
gka / twitter-mvf.py
Created February 2, 2012 22:01
Find most valuable followers on Twitter
from twitter import Twitter, OAuth
import json
auth_token = 'xxxxxxxxxxxxxx'
auth_token_secret = 'xxxxxxxxxxxxxxxx'
consumer_key = 'xxxxxxxxxxxxxxxx'
consumer_secret = 'xxxxxxxxxxxxxxxx'
user = "driven_by_data"
@gka
gka / readme.md
Created February 8, 2012 22:37
chroma.js wiki images
@gka
gka / map.json
Created February 9, 2012 12:38
Map source for NUTS2 SVG map of Italy
{
"proj": {
"id": "satellite",
"up": 23,
"dist": 1.15
},
"layers": [{
"id": "regions",
"src": "italy-nuts2.shp",
"attributes": [{ "src": "NUTS_ID", "tgt": "nuts2" }]
@gka
gka / ucsv.py
Created March 3, 2012 10:57
unicode pimped csv
import csv, codecs, cStringIO
class UTF8Recoder:
"""
Iterator that reads an encoded stream and reencodes the input to UTF-8
"""
def __init__(self, f, encoding):
self.reader = codecs.getreader(encoding)(f)
def __iter__(self):