Skip to content

Instantly share code, notes, and snippets.

View gka's full-sized avatar
🐢

Gregor Aisch gka

🐢
View GitHub Profile
@gka
gka / textWidth.js
Created November 14, 2013 15:58
Approximate text width based on estimated character widths...
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-tile-urls.py
Last active August 26, 2022 06:27
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
gka / colorizer.json
Last active April 8, 2022 09:44
us states
[{
"file": "results",
"data": {
"AL": {
"fill": "#cc3d3d",
"stroke": false
},
"AK": {
"fill": "#cc3d3d",
"stroke": false
@gka
gka / USA-sat.svg
Created November 22, 2011 12:25
Map of US cities and state poverty levels
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 December 3, 2021 02:02
used this script to prepare the data for this chart https://www.datawrapper.de/_/Wa2Ci/
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)
@gka
gka / multi-crowbar.js
Last active April 29, 2021 21:44
like svg-crowbar, but for multiple svg elements!
var multiCrowbar = (function() {
/*
* SVG Export
* converts html labels to svg text nodes
* will produce incorrect results when used with multi-line html texts
*
* Author: Gregor Aisch
* based on https://github.com/NYTimes/svg-crowbar/blob/gh-pages/svg-crowbar-2.js
*/
@gka
gka / App.svelte
Last active March 22, 2021 15:56
svelte 3 lazyload example
<h1>lazyload example</h1>
{#each [0,1,2,3,4,5,6,7,8,9] as i}
<p>Scroll down to load the images. Quo et qui laboriosam rerum. Animi et quia consequuntur quas sit eaque molestias. Accusamus voluptate nulla eligendi. Dolores labore ea asperiores ut voluptas dolorem. Cupiditate in enim quibusdam. Quas quae aliquam sed repellat laboriosam inventore est.</p>
<img alt="random image" use:lazyload src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAQAAABeK7cBAAAAC0lEQVR42mNkAAIAAAoAAv/lxKUAAAAASUVORK5CYII=" data-src="https://picsum.photos/500/300/?image={i}" />
{/each}
<script>
import { lazyload } from './lazyload.js';
</script>
@gka
gka / zip2nuts.py
Created December 13, 2011 23:37
This script tries to map European zip codes to NUTS2 regions by point-in-polygon checking the zip coordinate against a shapefile of NUTS regions..
#!/usr/bin/env python2.7
import csv, shapefile, Polygon, Polygon.IO, math
# shapefile comes from here:
# http://epp.eurostat.ec.europa.eu/cache/GISCO/geodatafiles/NUTS_10M_2006_SH.zip
shpsrc = "eu-nuts-2.shp"
# zip code database comes from here:
# http://www.clearlyandsimply.com/files/2010/10/european_cities_and_postcodes_us_standard.zip
@gka
gka / _.md
Last active October 24, 2020 10:53
SVG der deutschen Landkreise
@gka
gka / index.html
Last active September 28, 2020 19:48
external tooltips
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="noindex, nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet href="https://cdn.jsdelivr.net/npm/bulma@0.9.0/css/bulma.min.css">