Skip to content

Instantly share code, notes, and snippets.

View adambene's full-sized avatar

Adam Bene adambene

View GitHub Profile
@adambene
adambene / index.js
Last active August 29, 2015 14:19
requirebin sketch
var sample = "// hey";
var bluebird = require('bluebird');
var pogoscript = require('pogo');
var $ = require('jquery');
var CodeMirror = require('codemirror');
$(function () {
$('body').css({
@adambene
adambene / index.html
Last active December 5, 2016 18:29
Default File Input
<input type="file" />
@adambene
adambene / exception-handling-in-es6.es5.js
Created January 3, 2017 15:38
Exception handling in ES6 - Transpiled to ES5
// transpiled to ES5
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
var someAsyncOperation = function () {
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(path) {
@adambene
adambene / pattern-matching-map.hs
Created January 13, 2017 21:56
Pattern Matching in JavaScript - Haskell map
map _ [] = []
map f (x:xs) = f x : map f xs
@adambene
adambene / pattern-matching-map.js
Last active January 13, 2017 22:14
Pattern Matching in JavaScript - JavaScript map
const map = (f, [x, ...xs]) => (
(x === undefined && xs.length === 0) ? []
: [f(x), ...map(f, xs)]
);
@adambene
adambene / currying-in-javascript-es6-papply.js
Last active January 20, 2017 01:23
Currying in JavaScript ES6 - papply
multiply = (n, m) => n * m
multiply(3, 4) === 12 // true
triple = (m) => multiply(3, m)
triple(4) === 12 // true
@adambene
adambene / currying-in-javascript-es6-properties.js
Created January 20, 2017 01:28
Currying in JavaScript ES6 - properties
add = (a, b) => a + b
curriedAdd = a => b => a + b
add(5,6) === 11
curriedAdd(5)(6) === 11
uncurry(curry(add))(5,6) === 11
curry(uncurry(curriedAdd))(5)(6) === 11
@adambene
adambene / exception-handling-in-es6.js
Last active January 22, 2017 13:38
Exception handling in ES6
// define an async operation that rejects if the path is not a string
const someAsyncOperation = async (path) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (typeof path === 'string') {
resolve(`Hello Panda! Path is = ${path}`);
} else {
reject(new Error(`Path is not a string. Path (${typeof path}) = ${path}`));
}
}, 1000);
@adambene
adambene / currying-in-javascript-es6-curry.js
Last active May 24, 2017 02:32
Currying in JavaScript ES6 - curry
multiply = (n, m) => (n * m)
multiply(3, 4) === 12 // true
curryedMultiply = (n) => ( (m) => multiply(n, m) )
triple = curryedMultiply(3)
triple(4) === 12 // true
@adambene
adambene / currying-in-javascript-es6-uncurry.js
Last active May 24, 2017 02:32
Currying in JavaScript ES6 - uncurry
curryedMultiply = (n) => (m) => n * m
curryedMultiply(3)(4) === 12 // true
multiply = (n, m) => curryedMultiply(n)(m)
multiply(3, 4) === 12 // true