Skip to content

Instantly share code, notes, and snippets.

View anderser's full-sized avatar

Anders Eriksen anderser

View GitHub Profile
@n1k0
n1k0 / gist:1501173
Created December 20, 2011 10:44 — forked from fbuchinger/gist:1501115
PhantomJS: Capturing single dom elements as png files
var page = new WebPage(),
address, output, size;
//capture and captureSelector functions adapted from CasperJS - https://github.com/n1k0/casperjs
capture = function(targetFile, clipRect) {
var previousClipRect;
var clipRect = {top: 0, left:0, width: 40, height: 40};
if (clipRect) {
if (!isType(clipRect, "object")) {
throw new Error("clipRect must be an Object instance.");
@bsweger
bsweger / useful_pandas_snippets.md
Last active April 19, 2024 18:04
Useful Pandas Snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

@jaywilliams
jaywilliams / csv_to_array.php
Created April 30, 2010 23:18
Convert a comma separated file into an associated array.
<?php
/**
* Convert a comma separated file into an associated array.
* The first row should contain the array keys.
*
* Example:
*
* @param string $filename Path to the CSV file
* @param string $delimiter The separator used in the file
* @return array
@dokterbob
dokterbob / admin.py
Created February 15, 2011 20:00
InlineAdmin mixin limiting the selection of related items according to criteria which can depend on the current parent object being edited.
class LimitedAdminInlineMixin(object):
"""
InlineAdmin mixin limiting the selection of related items according to
criteria which can depend on the current parent object being edited.
A typical use case would be selecting a subset of related items from
other inlines, ie. images, to have some relation to other inlines.
Use as follows::
@pwenzel
pwenzel / git-log-to-tsv.sh
Created June 6, 2012 20:53
Git Log to Tab-Delimited CSV File
# Local Dates:
git log --date=local --pretty=format:"%h%x09%an%x09%ad%x09%s" > commits.local.tsv.txt
# ISO Dates:
git log --date=iso --pretty=format:"%h%x09%an%x09%ad%x09%s" > commits.iso.tsv.txt
@rosskarchner
rosskarchner / export.py
Created February 21, 2011 22:48
extract tiles from an mbtiles file
import sqlite3, os
conn = sqlite3.connect('Mills1860.mbtiles')
results=conn.execute('select * from tiles').fetchall()
for result in results:
zoom, column, row, png= result
try:
os.makedirs('%s/%s/' % (zoom, row))
@davemo
davemo / README.md
Created September 13, 2011 22:59
A simple Backbone.js powered Slideshow, with pause/play controls and jump-to controls.

#A simple Slideshow module wrapped in a Backbone View

  • Dependencies ** underscore.js ** backbone.js

Viewable in action in this jsfiddle

@palewire
palewire / LOCATING_THE_STORY.textile
Created January 30, 2012 23:59
Locating the story: The latest in mapping.

Locating the story: The latest in mapping

A collection of links for a NICAR 2012 presentation. It will suggest broad themes for the past year, and try to support them with examples from work in the field. This is a work in progress. Feel free to crap on it, or add your own ideas.

Escape from Google Maps

  • Google changed the rules of the game. There are now usage limits. Read about them here
  • TileMill, custom tiles, need examples
  • Links to ranty blog posts from Nestoria guy and others
  • One replacement is simple line maps drawn using HTML5 technologies like SVG, Canvas and VML. You saw this example a lot in election maps during the GOP primaries, like NYT, WaPo, HuffPo, LAT
@lucasallan
lucasallan / install_postgis_osx.sh
Created September 6, 2011 21:03 — forked from klebervirgilio/install_postgis_osx.sh
Installing PostGIS on Mac OS X and Ubuntu
# Some good references are:
# http://russbrooks.com/2010/11/25/install-postgresql-9-on-os-x
# http://www.paolocorti.net/2008/01/30/installing-postgis-on-ubuntu/
# http://postgis.refractions.net/documentation/manual-1.5/ch02.html#id2630392
#1. Install PostgreSQL postgis and postgres
brew install postgis
initdb /usr/local/var/postgres
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
-- http://overpass-turbo.eu/
-- https://gist.github.com/atlefren/60234fb68d8299136c05
-- http://www.norkart.no/produkt/datavarehus/
-- toalett og kommunekart
SELECT
f.cartodb_id,
f.the_geom_webmercator,
f.the_geom,