Skip to content

Instantly share code, notes, and snippets.

View gka's full-sized avatar
🐢

Gregor Aisch gka

🐢
View GitHub Profile
@gka
gka / index.js
Created December 11, 2018 00:03
Quick demo of using only parts of chroma.js
require('chroma-js/src/io/hex');
require('chroma-js/src/io/lab');
const chroma = require('chroma-js/src/chroma');
console.log(chroma('#cc7d8e').lab());
@gka
gka / polygonArea.js
Created October 5, 2018 10:38
Returns the area of a simple polygon given in [ [x,y], ...] pairs
function area(vertices) {
var total = 0;
for (var i = 0, l = vertices.length; i < l; i++) {
var addX = vertices[i][0];
var addY = vertices[i == vertices.length - 1 ? 0 : i + 1][1];
var subX = vertices[i == vertices.length - 1 ? 0 : i + 1][0];
var subY = vertices[i][1];
total += (addX * addY * 0.5);
@gka
gka / combinations.js
Created October 5, 2018 10:37
Returns all possible combinations of the elements in a given array
function combinations(arr) {
var fn = function(active, rest, a) {
if (!active.length && !rest.length)
return;
if (!rest.length) {
a.push(active);
} else {
fn(active.concat(rest[0]), rest.slice(1), a);
fn(active, rest.slice(1), a);
@gka
gka / gist:c6892ebd0c1e5732e628efef1ee00950
Last active August 21, 2018 19:39
adblock plus rules for frontpage ads on new nytimes.com site
! 8/21/2018, 9:27:26 PM https://www.nytimes.com/
www.nytimes.com###app > div:first-child:-abp-has(> div:-abp-has(> div:-abp-contains(Advertisement)))
! 8/21/2018, 9:33:55 PM https://www.nytimes.com/
www.nytimes.com###app > #site-content > div > div > div:-abp-has(> div:-abp-has(> div:-abp-contains(Advertisement)))
@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 / prevent-overlap.js
Created October 17, 2017 22:39
prevent vertical overlapping of labels in charts
define(function(require) {
'use strict';
var d3 = require('d3');
/*
* tries to eliminate vertical label overlappings
* by slightly moving the labels away from each
* other
@gka
gka / rollup-pipe.js
Last active September 29, 2017 22:43
rollup-pipe (with commonjs)
#!/usr/bin/env node
const rollup = require('rollup');
const commonjs = require('rollup-plugin-commonjs');
const inputOptions = {
input: process.argv[2],
plugins: [commonjs()],
onwarn: () => {}
};
@gka
gka / keybase.md
Created September 27, 2017 19:39

Keybase proof

I hereby claim:

  • I am gka on github.
  • I am gka (https://keybase.io/gka) on keybase.
  • I have a public key ASA7zDyyCPDyL7H1V6wrKxH56GOVPeaPm1krL33Bual6Pwo

To claim this, I am signing this object:

@gka
gka / .block
Created September 14, 2017 20:14
regl-hurricane-II
license: mit