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
// This is super slow though: http://jsperf.com/summing-objects/2 | |
var sumObj = function (object) { | |
if (Object.keys(object).length) { | |
var firstKey = Object.keys(object)[0]; | |
var clone = Object.assign({}, object); | |
delete clone[firstKey]; | |
return parseInt(object[firstKey]) + sumObj(clone); | |
} |
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
/* | |
* Comparison of methods to list all files in a directory | |
* and subdirectories ("recursive directory walk"). | |
* | |
* gunargessner.com 2015-12-25 | |
* | |
*/ | |
var fs = require('fs'); | |
var fsPath = require('path'); | |
var _ = require('highland'); |
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 myPromise = new Promise((resolve, reject) => { | |
setTimeout(resolve, 1000, 42); | |
}); | |
var cancel; | |
const myCancelator = new Promise((resolve, reject) => { | |
cancel = reject; | |
}); | |
Promise.race([ |
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
// What is your opinion on the use of this function? | |
function rejectIfNil(msg) { | |
return payload => { | |
if (!payload) return Promise.reject(new Error(msg)) | |
return payload | |
} | |
} | |
function update(_id) { | |
return User |
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
/** | |
* Currying Functions with Named Parameters. | |
* @gunar, @drboolean, @dtipson 2016 | |
* | |
* Why does it return a thunk, though? | |
* Because in JS named arguments are opaque. There is no way of getting a function's named arguments list. | |
* e.g. | |
* const foo = function ({ a, b }) { } | |
* console.log(foo.arguments) // Throws. Ideally would return ['a', 'b']. | |
* |
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
/* | |
Gunar C. Gessner | |
@gunar 2016 | |
INSTALL: https://script.google.com/macros/s/AKfycbym7IaTORzJ7LQPcxMx1LV1SQEC6RVGv5tzLOgYS8iQe8XAJxM/exec | |
After installation, the script will, every 10 minutes, search for all files that have duplicates (shift+z) and remove them from the root directory ("My Drive"). | |
This Google Apps Script webapp aims to solve the problem that when transferring ownership of folders & | |
files to another account, duplicate files shown in "My Drive". |
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
// ==UserScript== | |
// @name OSHO.com selectable | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match http://www.osho.com/* | |
// @grant none | |
// ==/UserScript== | |
function addGlobalStyle(css) { |
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
// Inspired by [Brian Lonsdorf - Oh Composable World! - YouTube](https://www.youtube.com/watch?v=SfWR3dKnFIo) | |
// Inspired by [Mostly adequate guide to FP](https://github.com/MostlyAdequate/mostly-adequate-guide) | |
const Box = function(x) { | |
this.__value = x; | |
} | |
Box.of = x => new Box(x) | |
Box.prototype.map = function (f) { | |
return Box.of(f(this.__value)) | |
} |
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
// 1. Using rejections for both exceptions and rejections | |
foo(5) | |
.then(bar) | |
.catch(err => { | |
if (!(err instanceof MyError)) {{ | |
// exception! | |
throw err | |
} | |
// else, process business logic error properly | |
}) |
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' | |
// ref https://en.wikipedia.org/wiki/Cycle_sort | |
const cycleSort = array => { | |
// last item will already be in place | |
for (let cycleStart = 0; cycleStart < array.length-1; cycleStart++) { | |
let item = array[cycleStart] | |
// find where to put the item | |
let pos = cycleStart |
OlderNewer