Skip to content

Instantly share code, notes, and snippets.

View gka's full-sized avatar
🐢

Gregor Aisch gka

🐢
View GitHub Profile
@gka
gka / publish-chart.php
Last active August 29, 2015 13:56
Script for publishing Datawrapper charts via command-line
<?php
/*
* This scripts triggers the chart publication process.
* Usage: php publish-chart.php [CHART_ID]
*/
define('ROOT_PATH', '../'); // relative path to your Datawrapper root
define('NO_SLIM', 1);
define('NO_SESSION', 1);

Created by Christopher Manning

Summary

Nodes are linked to nodes in neighboring cells. The cell's color is a function of its area.

The white lines are the Delaunay triangulation and the purple cells are the Voronoi diagram.

Controls

@gka
gka / worldcup-network.gexf
Last active August 29, 2015 14:02
Network of 2014 World Cup teams, their players and the clubs they are playing in. Derived from the FIFA.com player database. Used to make this graphic: http://www.nytimes.com/interactive/2014/06/20/sports/worldcup/how-world-cup-players-are-connected.html?ref=worldcup
<?xml version="1.0" encoding="utf-8"?><gexf version="1.1" xmlns="http://www.gexf.net/1.1draft" xmlns:viz="http://www.gexf.net/1.1draft/viz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance">
<graph defaultedgetype="undirected" mode="static">
<attributes class="node" mode="static">
<attribute id="0" title="country_rank" type="integer" />
<attribute id="1" title="confederation" type="string" />
<attribute id="2" title="team_count" type="integer" />
<attribute id="3" title="country" type="string" />
<attribute id="4" title="premier" type="boolean" />
<attribute id="5" title="type" type="string" />
<attribute id="6" title="rank" type="integer" />
@gka
gka / gist:59918662ff4c15f9c4bf
Created August 26, 2014 18:51
Batch rename a bunch of files
for i in *.php ; do mv "$i" "`basename $i .php`.json" ; done
@gka
gka / git-go.js
Last active September 1, 2015 20:08
#!/usr/bin/env node
var cmds = [];
if (process.argv.length < 3) {
console.log('You need to provide a commit message!');
process.exit(-1);
}
cmds.push('git add -A');
cmds.push('git add -u');
var page = require('webpage').create();
page.viewportSize = { width: 1402*2, height: 800*2 };
page.zoomFactor = 2;
page.open('http://localhost:1337/?forceRetina=1', function() {
var s = 420, z = 2;
page.clipRect = {
top: z * (630-s/2),
left: z * (1402 - s)/2,
width: z * s,
height: z * s
@gka
gka / rm_old.sh
Created September 17, 2015 21:08
Remove everything but five newest files/directories
(ls -t|head -n 5;ls)|sort|uniq -u|xargs rm -Rf
@gka
gka / WikipediaPlainTables
Created August 3, 2011 17:09
Ever tried to copy&paste a table from Wikipedia to your favourite spreadsheet software? You just want the pure data and not all those hyperlinks and embedded images? This script removes unnecessary stuff from the tables. Simply run in firebug console and
// remove all images
$('table img').remove();
// remove all reference links
$('table .reference').remove()
// convert all links to plain text
$('table a').each(function(index, el) { $(el).replaceWith($(el).html()) });
@gka
gka / csv2tsv
Created September 16, 2011 12:20
Converting a comma-separated and quoted file into a tab-separated and unquoted file
#!/usr/bin/env python2.7
"""
No more trouble with comma-separated and quoted CSV files.
"""
import csv, sys
if len(sys.argv) != 3: print 'Usage:\ncsv2tsv fromfile.csv tofile.tsv'
file_in = sys.argv[1]
file_out = sys.argv[2]
@gka
gka / gisutils.py
Created October 6, 2011 14:03
Some GIS utils for Python, like area computation for geo-polygons
"""
implementation taken from
http://forum.worldwindcentral.com/showthread.php?t=20724
algorithm expects a list of [lng,lat] pairs in degrees
"""
def haversine(x):
from math import cos
return ( 1.0 - cos(x) ) / 2.0