Skip to content

Instantly share code, notes, and snippets.

View machine.js
const FILTER_TYPE_ERROR_STATES = {
type: "parallel",
states: {
FILTER_TYPE_SVALUE: {
initial: "OFF",
states: {
OFF: {
on: {
CLICK_TYPE_SVALUE: "ON",
},
View machine.js
const FILTER_TYPE_ERROR_STATES = {
type: "parallel",
states: {
FILTER_TYPE_SVALUE: {
initial: "OFF",
states: {
OFF: {
on: {
CLICK_TYPE_SVALUE: "ON"
}
View machine.js
const replMachine = Machine({
id: 'replMachine',
initial: 'repl',
context: {
cursor: 0,
data: [1,2,3,4,5]
},
states: {
repl: {
@herrfugbaum
herrfugbaum / euclid.js
Last active Aug 29, 2017
Euclidean algorithm
View euclid.js
const euclid = (w, h) => h === 0 ? w : euclid(h, w % h)
@herrfugbaum
herrfugbaum / random-pastel-rgba.js
Created Mar 11, 2016
Return a random pastel rgba color.
View random-pastel-rgba.js
/* @param alpha boolean
* if true a random value for the alpha channel is calculated, else alpha channel = 1 (full saturation)
*/
var randomPastelColor = function (alpha) {
var rndm = function (f) { return Math.floor(Math.random() * f)},
pstlfy = function (p) { return Math.round((p + 255) / 2)},
r = pstlfy(rndm(256)),
g = pstlfy(rndm(256)),
b = pstlfy(rndm(256)),
a = alpha ? rndm(11) / 10 : 1