Skip to content

Instantly share code, notes, and snippets.


Gregor Aisch gka

View GitHub Profile
gka /
Last active Dec 12, 2022
The code below does the same as the example snippet you've just seen: opening a database connection, creating a new table with some columns, storing some data, altering the table schema and adding another row.
import sqlite3
# open connection and get a cursor
conn = sqlite3.connect(':memory:')
c = conn.cursor()
# create schema for a new table
c.execute('CREATE TABLE IF NOT EXISTS sometable (name, age INTEGER)')
gka / textWidth.js
Created Nov 14, 2013
Approximate text width based on estimated character widths...
View textWidth.js
var textWidth = (function() {
function charW(w, c) {
if (c == 'W' || c == 'M') w += 15;
else if (c == 'w' || c == 'm') w += 12;
else if (c == 'I' || c == 'i' || c == 'l' || c == 't' || c == 'f') w += 4;
else if (c == 'r') w += 8;
else if (c == c.toUpperCase()) w += 12;
else w += 10;
return w;
gka /
Last active Nov 10, 2022
how to make a nice GIF from png frames

Make sure ffmpeg is up-to-date:

brew update
brew upgrade ffmpeg

Convert a MOV into frames. Tweak the 2/1 if you want more or fewer frames.

gka /
Created Jan 24, 2013
PHP Endpoint for Github Webhook URLs

PHP Endpoint for Github Webhook URLs

If you love deploying websites using Github, but for some reason want to use your own server, this script might be exactly what you need.

  1. Put github.php somewhere on your PHP-enabled web server, and make it accessible for the outside world. Let's say for now the script lives on
gka / clean_pdf_import.jsx
Last active Oct 24, 2022
Clean PDF import. Removes all clipping masks and ungroups everything..
View clean_pdf_import.jsx
#target Illustrator
// = RemoveClippingMasks.jsx
// script.description = deletes all PageItems being used as clipping masks.
// script.parent = Kenneth Webb // 01/07/2013
// script.elegant = true?
var docRef = app.activeDocument;
var clippingCount = 0
gka /
Last active Aug 26, 2022
python script to generate a list of projected tiles
# you might want to run this first:
# pip install pyproj mercantile
from pyproj import Proj
import mercantile
mercator = Proj('+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +over +no_defs')
albers = Proj('+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=sphere +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +nadgrids=@null')
gka / plot.png
Last active Jul 18, 2022
visualize git logs accross multiple repositories
View colorizer.json
"file": "results",
"data": {
"AL": {
"fill": "#cc3d3d",
"stroke": false
"AK": {
"fill": "#cc3d3d",
"stroke": false
gka / USA-sat.svg
Created Nov 22, 2011
Map of US cities and state poverty levels
View USA-sat.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
gka / approval-ratings.R
Last active Dec 3, 2021
used this script to prepare the data for this chart
View approval-ratings.R
needs(dplyr, tidyr, readr, jsonlite)
trump_ratings <- read_csv('') %>%
filter(subgroup=='All polls') %>%
mutate(date=as.Date(modeldate, format='%m/%d/%Y'),
disapprove=as.numeric(disapprove_estimate)) %>%
select(date, approve, disapprove, president)