Skip to content

Instantly share code, notes, and snippets.


Johan Sundström johan

View GitHub Profile
johan /
Last active Jan 16, 2020
Solar Analemmas Anywhere

Hourly solar analemmas (ignoring daylight savings time) as seen from anywhere in the world in 2014.

johan / index.html
Last active Jan 16, 2020
Vacation Day Planner
View index.html
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<base href=";m1=05&amp;y1=2018&amp;d2=9&amp;m2=7&amp;y2=2018&amp;">
<title>Vacation Day Planner</title>
const sumUp = (td) => { const t = td.parentNode.parentNode, r = t.rows[t.rows.length-1], c = r.cells[r.cells.length-1]; c.textContent = Array.from(t.querySelectorAll('td')).filter(c => c.classList.contains('hl-b') || c.classList.contains('hl')).length; = '#000'; }
document.onclick = (e) => { if ( === 'TD') { const t =, cl = t.classList; cl.contains('hl-b') || cl.contains('hl') ? cl.remove('hl-b', 'hl') : cl.add('hl'); sumUp(t); } };
const pad = (n) => (n < 10 ? '0' : '') + n;
const date = (t) => t.getFullYear() + '-' + pad(t.getMonth() + 1) + '-' + pad(t.getDate());
const ONE_DAY = 864e5;
const ghostThePast = () => {
johan /
Last active Jan 10, 2020 — forked from johan/autofork.js
(Re)fork any gist, including your own

Want to fork your own gists? No fork button? No problem! Install this user script by clicking refork.user.js' "raw" link down below: ⇓

johan /
Last active Dec 6, 2019
A micro-library (4k minified) for DRY:ing up the boring boilerplate of user scripts.


The fun part of user scripting is deciding what happens. The boring part is scavenging the DOM for bits of templated data, or elements you want to mod.

Have on.js do it for you!

johan /
Last active Sep 26, 2019
LocalStorage Cross-window notifications

Take a website with some kind of notifications system showing the user a count of their unread notifications or similar. (Facebook, Google+, GMail et c.)

Now perform an action in one browser tab, that changes or clears the count. Does this immediately propagate to all other tabs you have open on the site?

If not – this example is for you!

As it happens, this is really easy to do in

johan / d3.v2.min.js
Last active Aug 23, 2019
National Conventions Word Usage
View d3.v2.min.js
(function(){function e(e,t){try{for(var n in t)Object.defineProperty(e.prototype,n,{value:t[n],enumerable:!1})}catch(r){e.prototype=t}}function t(e){var t=-1,n=e.length,r=[];while(++t<n)r.push(e[t]);return r}function n(e){return}function r(){}function i(e){return e}function s(){return this}function o(){return!0}function u(e){return typeof e=="function"?e:function(){return e}}function a(e,t,n){return function(){var r=n.apply(t,arguments);return arguments.length?e:r}}function f(e){return e!=null&&!isNaN(e)}function l(e){return e.length}function c(e){return e==null}function h(e){return e.trim().replace(/\s+/g," ")}function p(e){var t=1;while(e*t%1)t*=10;return t}function d(){}function v(e){function t(){var t=n,r=-1,i=t.length,s;while(++r<i)(s=t[r].on)&&s.apply(this,arguments);return e}var n=[],i=new r;return t.on=function(t,r){var s=i.get(t),o;return arguments.length<2?s&&s.on:(s&&(s.on=null,n=n.slice(0,o=n.indexOf(s)).concat(n.slice(o+1)),i.remove(t)),r&&n.push(i.set(t,{on:r})),e)}
johan /
Created Oct 28, 2011
User script to view SVG files both as image and text at

Click "raw" below to install. Requires Google Chrome, Firefox + Greasemonkey, or some other browser supporting user scripts / content scripts / user javascript.

johan / octocat.svg
Created Jun 4, 2011
Github octocat avatar, SVG format
View octocat.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
johan / grep.js
Created May 9, 2013
Use grep to find direct/inherited properties of an object or function, or grep.own for direct properties only. (Great for Chrome 29's devtools' Script snippets panel.)
View grep.js
/* Examples:
Use grep with two arguments to find inherited or direct properties of an object:
> grep(document, 'get') // see all properties case insensitively matching *get*:
{ getCSSCanvasContext: function getCSSCanvasContext() { [native code] }
, getElementById: function getElementById() { [native code] }
, getElementsByClassName: function getElementsByClassName() { [native code] }
, getElementsByName: function getElementsByName() { [native code] }
, getElementsByTagName: function getElementsByTagName() { [native code] }
johan / Makefile
Created Jan 24, 2017
Makefile of the steps in Mike Bostock's command-line cartography tutorial, parts 1-4
View Makefile
# request one at and paste it below
# a factor 1609.34 squared
# npm install -g shapefile # 0.6.1
# npm install -g d3-geo-projection # 1.2.1
# npm install -g ndjson-cli # 0.3.0
You can’t perform that action at this time.