Skip to content

Instantly share code, notes, and snippets.

View luislee818's full-sized avatar

Dapeng Li luislee818

View GitHub Profile

Keybase proof

I hereby claim:

  • I am luislee818 on github.
  • I am dapeng (https://keybase.io/dapeng) on keybase.
  • I have a public key ASC3S3lwpsXhgvCEJWlltt0Di70wwv8RXOMsnzj0OgqCRQo

To claim this, I am signing this object:

@luislee818
luislee818 / download_pragpub.hs
Last active February 8, 2018 18:41
Download free PragPub issues from 2009.07 to 2013.07
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/"
@luislee818
luislee818 / docker-compose.yml
Created December 21, 2017 07:07 — forked from mhowlett/docker-compose.yml
Brings up a kafka cluster using Docker for Mac. Usage: MY_IP=<your ip> docker-compose up
---
version: '2'
services:
zk1:
image: confluentinc/cp-zookeeper:3.0.1
ports:
- "22181:22181"
environment:
ZOOKEEPER_SERVER_ID: 1
ZOOKEEPER_CLIENT_PORT: 22181
@luislee818
luislee818 / ramda_samples.js
Last active October 3, 2022 23:39
Ramda samples
// 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
@luislee818
luislee818 / elixir_function_invocations.exs
Last active March 28, 2018 09:17
Illustrating Elixir's function invocation with pipe operators
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()
@luislee818
luislee818 / io.js
Created April 7, 2016 08:49
Mostly adequate guide experiments
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) {
@luislee818
luislee818 / r.js
Created March 11, 2016 11:15
Poor man's Ramda, dependent on underscore.js
// Dependencies
// _
// Some helper functions to be used in composition, inspired by Ramda
window.r = (function(_) {
var curry,
flip2,
invoke,
split,
map,
@luislee818
luislee818 / es6.js
Created February 10, 2016 22:41
Y Combinator
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));
@luislee818
luislee818 / _general_mixing_sync_and_async.js
Last active January 5, 2016 09:29
JavaScript with Promises examples
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() {
@luislee818
luislee818 / funjs.js
Created January 4, 2016 09:32
Sources of the Functional JavaScript book, combined
// 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]);