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
var myClosure = function() { | |
var secret = 42, getSecret, inc; | |
getSecret = function() { return secret; }; | |
inc = function() { secret += 1; }; | |
return { | |
getSecret: getSecret, | |
inc: inc |
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
// Chap 1 | |
function splat(fun) { | |
return function(array) { | |
return fun.apply(null, array); | |
}; | |
} | |
var addArrayElements = splat(function(x, y) { return x + y }); | |
addArrayElements([1, 2]); |
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
Promise.resolve().then(function() { | |
console.log('starting'); | |
return 123; | |
}).then(function(val) { | |
console.log(val); | |
return val + 1; | |
}).then(function(val) { | |
console.log('starting second step...'); | |
return new Promise(function(resolve) { | |
setTimeout(function() { |
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 Y = (f) => { | |
const something = x => f(v => x(x)(v)); | |
// const something = x => f(x(x)); // actually it's this, but will cause stask overflow | |
return something(something); | |
}; | |
const factorial = Y(function f(fac) { | |
return function almost(n) { | |
return (n == 0 ? 1 : n * fac(n - 1)); |
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
// Dependencies | |
// _ | |
// Some helper functions to be used in composition, inspired by Ramda | |
window.r = (function(_) { | |
var curry, | |
flip2, | |
invoke, | |
split, | |
map, |
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
var R = require('ramda'); | |
var log = console.log; | |
var Maybe = function(val) { | |
this.__val = val; | |
} | |
Maybe.of = (val) => new Maybe(val); | |
Maybe.prototype.map = function(fn) { |
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
defmodule Funcs do | |
def greet(name) do | |
"Hola #{name}" | |
end | |
def test do | |
# functions as target of pipe | |
IO.puts test_1() | |
IO.puts test_2() | |
IO.puts test_3() |
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
// using v0.24.1 | |
const R = require('ramda'); | |
// adjust | |
// [a -> a] -> Number -> [a] -> [a] | |
const arr = [1, 2, 3]; | |
let result = R.adjust(R.add(1), 1, arr); | |
console.log('adjust: ', result); // [1, 3, 3] | |
// update |
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
--- | |
version: '2' | |
services: | |
zk1: | |
image: confluentinc/cp-zookeeper:3.0.1 | |
ports: | |
- "22181:22181" | |
environment: | |
ZOOKEEPER_SERVER_ID: 1 | |
ZOOKEEPER_CLIENT_PORT: 22181 |
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 Text.Printf | |
import System.Process | |
-- Downloads free PragPub issues from 2009.07 to 2013.07 from https://pragprog.com/magazines | |
-- relies on 'wget' command for downloading | |
-- run `processAll` to download | |
-- constants | |
savePath = "/Users/Dapeng/Downloads/PragPub/" |