Instantly share code, notes, and snippets.

View Clustering.js
import chroma from 'chroma-js';
const cluster = (colors, centers) => {
const centerCounts = {};
for(let color of colors) {
let bestCenter = null;
let bestCenterDist = Number.MAX_VALUE;
for(let center in centers) {
const dist = chroma.distance(color, centers[center]);
if(dist < bestCenterDist) {
View redux-pre-thunk.js
// snip for production
const store = createStore(thunk.withExtraArgument({fetch}));
// snip effect
import { createAction } from 'redux-actions';
const createEffect = (name, fun) => (...args) => dispatch => {
const action = createAction(name);
dispatch({ type: `${name}_STARTED` });
View TextTestTest.java
package com.gildedrose;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
View decTime.js
function decTime() {
var date = new Date();
var oldSeconds = date.getSeconds()+date.getMinutes()*60+date.getHours()*60*60+date.getMilliseconds()/1000;
oldSeconds = oldSeconds/(1-0.136);
var hours = Math.floor(oldSeconds / (100*100));
oldSeconds = oldSeconds % (100*100);
var minutes = Math.floor(oldSeconds / 100);
var seconds = oldSeconds % 100;
return hours+':'+minutes+':'+seconds;
View gist:f00b5839096dfd57457c
salias () {
N=$1
F=$ZSH_CUSTOM/aliases.zsh
shift
egrep -v "^alias $N" $F > $F.new
mv $F.new $F
echo "alias $N=\"$*\"" >> $F
source $F
}
View bibtexlet.coffee
if (parts = document.title.split(///\s[-|–]\s///)).length == 2
title = parts[0]
author = parts[1]
else
title = document.title
author = (document.getElementsByName("author")[0])?.content || document.location.host.replace(/^((.+)\.)?([^\.]+\.[^\.]+)$/, '$3')
language = (document.getElementsByTagName("html")[0])?.lang || "en"
pad = ((num) -> if num < 10 then "0"+num else num)
date_part = (date) ->