Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢

Gregor Aisch gka

🐢
View GitHub Profile
@gka
gka / sqlite3-example.py
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.
View sqlite3-example.py
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)')
conn.commit()
@gka
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
gka / make-animated-gifs-using-ffmpeg.md
Last active Nov 10, 2022
how to make a nice GIF from png frames
View make-animated-gifs-using-ffmpeg.md

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
gka / _readme.md
Created Jan 24, 2013
PHP Endpoint for Github Webhook URLs
View _readme.md

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 http://example.com/github.php
@gka
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
// script.name = 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
clipScan()
@gka
gka / make-tile-urls.py
Last active Aug 26, 2022
python script to generate a list of projected tiles
View make-tile-urls.py
#
# 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
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
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
gka / approval-ratings.R
Last active Dec 3, 2021
used this script to prepare the data for this chart https://www.datawrapper.de/_/Wa2Ci/
View approval-ratings.R
needs(dplyr, tidyr, readr, jsonlite)
trump_ratings <- read_csv('https://projects.fivethirtyeight.com/trump-approval-data/approval_topline.csv') %>%
filter(subgroup=='All polls') %>%
mutate(date=as.Date(modeldate, format='%m/%d/%Y'),
approve=as.numeric(approve_estimate),
disapprove=as.numeric(disapprove_estimate)) %>%
select(date, approve, disapprove, president)