This file contains hidden or 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
Number.prototype.map = (istart, istop, ostart, ostop) => { | |
return ostart + (ostop - ostart) * ((this - istart) / (istop - istart)); | |
}; | |
const map = (value, istart, istop, ostart, ostop) => { | |
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart)); | |
}; |
This file contains hidden or 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 sleep = async ms => new Promise( | |
resolve => setTimeout(() => { | |
console.log('~~~ Slept for', ms, 'ms') | |
resolve() | |
}, ms) | |
) | |
const of = async range => { | |
for (const ms of range) { | |
await sleep(ms) |
This file contains hidden or 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
// utils | |
// unit test - assert 2 values are equal | |
const assert = (assertion, actual, expected) => { | |
console.log('~~~', assertion, ':', actual === expected); | |
}; | |
// clone a value | |
// objects are only shallow cloned | |
const clone = (val) => { |
This file contains hidden or 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
#!/bin/bash | |
function ctrl_c() { | |
for process in "${PROCESSES[@]}"; do | |
local pid=$(get_pid $process) | |
if [ ! -z $pid ]; then | |
kill $pid | |
fi | |
done |
This file contains hidden or 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
import { merge, mergeWith } from 'lodash-es'; | |
const history = []; // history of all states | |
let timePeriod = 0; // index for history, used to timewarp throughout the history | |
let state = Object.freeze({}); // current state | |
/** | |
* Recursively merges all objects, and overwrites | |
* all other values. | |
* @param {*} destObj Current state |
This file contains hidden or 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
import jQuery from 'jquery'; | |
export const attachEvents = someStr => { | |
jQuery(document).ready(e => { | |
// do something cool with someStr | |
}); | |
}; |
This file contains hidden or 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
// anonymous function call stack test | |
// tested and works in chrome, ff, safari, node 4.2.2 | |
// does not work in ie9 or ie11 | |
var f = function f() { g(); }; | |
var g = function g() { h(); }; | |
var h = function h() { console.log(x) }; | |
try { | |
f(); | |
} catch (e) { |
This file contains hidden or 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
# First: | |
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done | |
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.* | |
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following: | |
#go to /usr/local/lib and delete any node and node_modules | |
cd /usr/local/lib | |
sudo rm -rf node* |
This file contains hidden or 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
'use strict'; | |
var fs = require('fs'); | |
var globule = require('globule'); | |
var path = require('path'); | |
var bowerComponents = globule | |
.find('bower_components/**/bower.json') | |
.map(function (fileName) { | |
var bowerJson = fs.readFileSync(fileName); |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/three.js/r67/three.min.js"></script> | |
</head> | |
<body> | |
<script id="mandelbrot-vertex" type="x-shader/x-vertex"> | |
precision highp float; | |
uniform float zoom; | |
varying vec2 pos; |
NewerOlder