This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Read https://en.wikipedia.org/wiki/Otsu%27s_method (added this since JS examples in wikipedia didn't work) | |
function otsu(histData /* Array of 256 greyscale values */, total /* Total number of pixels */) { | |
let sum = 0; | |
for (let t=0 ; t<256 ; t++) sum += t * histData[t]; | |
let sumB = 0; | |
let wB = 0; | |
let wF = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
</head> | |
<body> | |
<script> | |
// Christmas light hack for Web Audio Hack Day 2016 | |
// with vanilla JS tested on chrome and the LaunchPad | |
let device; | |
let stop = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<script> | |
const video = document.createElement('video'); | |
document.body.appendChild(video); | |
video.autoplay = true; | |
video.src = 'videos.mp4'; | |
video.playbackRate = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.glitch { | |
width: 100% | |
} | |
.hero-wrap .glitch:after, | |
.hero-wrap .glitch:before { | |
content: attr(data-text); | |
position: absolute; | |
width: 100%; | |
top: 0; | |
color: #222222; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Movements | |
Esc - F (Forward a word) | |
Esc - B (Back a word) | |
Ctrl - A (Start of line) | |
Ctrl - E (End of line) | |
Ctrl - F (Next line) | |
Ctrl - B (Previous line) | |
Deletions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GenericCache { | |
constructor() { | |
this.cache = new Map(); | |
} | |
set(key, promise, options) { | |
if (typeof promise === 'function') { | |
promise = promise(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { EventEmitter } = require('events'); | |
// const jumphash = require('jumphash'); | |
const _jumphash = require('@ceejbot/jumphash'), | |
crypto = require('crypto'); | |
function jumphash(key, buckets, algo='md5') { | |
const buffer = crypto | |
.createHash(algo) | |
.update(key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Also see https://github.com/tj/node-blocked/blob/master/index.js and https://stackoverflow.com/questions/28563354/how-to-detect-and-measure-event-loop-blocking-in-node-js | |
const blocked = require('blocked'); | |
blocked(function(ms) { | |
console.log("Blocked", ms); | |
}, { threshold: 10 }); | |
var blockDelta = 1; | |
var interval = 500; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Counter { | |
constructor() { | |
this.map = new Map(); | |
} | |
add(key) { | |
this.map.set(key, this.map.has(key) ? this.map.get(key) + 1 : 1); | |
} | |
print() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function draw(path, current) { | |
const navs = [ | |
elm('h5', { class: 'nav-group-title' }, `${path.join('/')} ${format(current.value)}`, { | |
onclick: () => State.navigateTo(path.slice(0, -1)) | |
}) | |
] | |
// let str = '----------\n' | |
const nodes = current._children || current.children || [] |