Skip to content

Instantly share code, notes, and snippets.

View gka's full-sized avatar
🐢

Gregor Aisch gka

🐢
View GitHub Profile
@gka
gka / index.html
Created January 3, 2012 00:08
alpha-shapes aka concave hulls in d3
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Alpha-Shapes</title>
<script src="http://mbostock.github.com/d3/d3.js"></script>
<script src="http://mbostock.github.com/d3/d3.geom.js"></script>
<style type="text/css">
path {
@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 / page-sitemap.php
Created January 12, 2012 12:11
Wordpress page template for JSON sitemaps
<?php
/*
Template Name: sitemap.json
*/
$args = array();
$args['post_per_page'] = -1;
$args['nopaging'] = true;
query_posts( $args );
@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 / contributions_per_candidate.r
Created February 8, 2012 13:59
Contributions per Candidate
# read csv file
ds <- read.csv('2012-Presidential-Campaign-Finance-Contributors.tsv', sep='\t')
# aggregate by candidate
res <- aggregate(ds$contb_receipt_amt, by=list(ds$cand_nm), FUN=sum, na.rm=TRUE)
X = data.frame(name=res$Group.1, amount=res$x)
# make data columns callable without typing X$ everytime
attach(X)
@gka
gka / app.js
Created February 8, 2012 17:19
Map of Italy
$(function() {
function fmt_amount(a) {
a*=1000000;
if (a > 1000000000) a = Math.round(a/100000000)/10 + ' bio';
else if (a > 1000000) a = Math.round(a/100000)/10 + ' mio';
else if (a > 1000) a = Math.round(a/100)/10 + ' k';
else a = Math.round(a*10)/10;
return '€ '+a;
};
@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" }]