Skip to content

Instantly share code, notes, and snippets.

Gregor Aisch gka

Block or report user

Report or block gka

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gka
gka / App.svelte
Last active Mar 6, 2019
svelte 3 lazyload example
View App.svelte
<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 / .block
Last active Sep 13, 2019
summer-heat
View .block
license: mit
@gka
gka / index.js
Created Dec 11, 2018
Quick demo of using only parts of chroma.js
View index.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 Oct 5, 2018
Returns the area of a simple polygon given in [ [x,y], ...] pairs
View polygonArea.js
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 Oct 5, 2018
Returns all possible combinations of the elements in a given array
View combinations.js
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 Aug 21, 2018
adblock plus rules for frontpage ads on new nytimes.com site
View gist:c6892ebd0c1e5732e628efef1ee00950
! 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 Sep 17, 2018
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)
View _cryptocrash-scaper.md
@gka
gka / prevent-overlap.js
Created Oct 17, 2017
prevent vertical overlapping of labels in charts
View prevent-overlap.js
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 Sep 29, 2017
rollup-pipe (with commonjs)
View rollup-pipe.js
#!/usr/bin/env node
const rollup = require('rollup');
const commonjs = require('rollup-plugin-commonjs');
const inputOptions = {
input: process.argv[2],
plugins: [commonjs()],
onwarn: () => {}
};
You can’t perform that action at this time.