Skip to content

Instantly share code, notes, and snippets.

@lambdaydoty
lambdaydoty / bridge_host_tunnel_to_container.sh
Created July 8, 2020 02:27
How to access host port from a docker container
## `How to access host port from a docker container`
## `Access host's ssh tunnel from docker container`
## `Prevent from using --net=host`
## ...
# +-------------------+
# | |
# | |
# | local container |
# | +---+
# +-------------------+ |172.10.0.1
;(function () {
const { S, F } = require ('./src/utils/sanctuary') ()
const control = F.coalesce (_ => S.Nothing) (S.Just)
const fut = F.go (function * () {
// const book1 = yield F.resolve ('Python')
const book1 = yield control (F.reject ('?network error'))
const book2 = yield control (F.resolve ('JavaScript'))
return {
book1,
book2,
function foldr (c, h) {
return ([a, ...x]) => (a === undefined)
? c
: h (a) (foldr(c, h)(x))
}
function foldl (c, h) {
return ([a, ...x]) => (a === undefined)
? c
: foldl (h(c)(a), h) (x)
@lambdaydoty
lambdaydoty / sanc.js
Created March 27, 2020 05:03
Package of sanctuary.js-based library
const uncurry =
f =>
(...args) =>
args.reduce((p, c) => p(c), f)
const curryN =
n =>
fn =>
(n === 0) ? fn()
: /* otherwise */ x => curryN(n - 1)(fn.bind(null, x))
const R = require('ramda')
const yaff =
R.cond([
[R.equals(0), R.always(1)],
[R.equals(1), R.always(1)],
[R.T, x => yaff(x - 1) + yaff(x - 2)],
])
const fib =
@lambdaydoty
lambdaydoty / example.js
Created February 29, 2020 10:35 — forked from briancavalier/example.js
Infinite "lists" in es6 using generators and yield
// Requires traceur
import { iterate, take, map, foldl } from './list-out-of-yield';
// Sum of squares of integers 1..100
var values = take(100, iterate(x => x + 1, 1));
var result = foldl((x, y) => x + y, 0, map(x => x * x, values));
console.log(result);
@lambdaydoty
lambdaydoty / dfs-bfs.js
Last active February 28, 2020 04:54
(Recursive) Depth First Search & Breadth First Search
function dfs (x) {
x.visited = true
adjacent(x)
.forEach(y => y.visited || dfs(y))
}
// :: List Node -> List Node
function bfs0 (xs) {
xs.forEach(x => { x.visited = true })
return (!xs.length)
const uncurry =
fn =>
ar =>
ar.reduce((f, x) => f(x), fn)
const curryN =
n =>
fn =>
(n === 0) ? fn()
/* otherwise */ : x => curryN(n - 1)(fn.bind(null, x))
@lambdaydoty
lambdaydoty / reader.js
Created February 25, 2020 14:41 — forked from dypsilon/reader.js
Example usage of the reader monad.
/**
* This short program will encrypt the user password
* and insert a new record into a mock database.
*/
const Reader = require('fantasy-readers');
const R = require('ramda');
const crypto = require('crypto');
// our mock database
const database = [
@lambdaydoty
lambdaydoty / combinators.js
Created February 23, 2020 16:41 — forked from Avaq/combinators.js
Common combinators in JavaScript
const I = x => x;
const K = x => y => x;
const A = f => x => f(x);
const T = x => f => f(x);
const W = f => x => f(x)(x);
const C = f => y => x => f(x)(y);
const B = f => g => x => f(g(x));
const S = f => g => x => f(x)(g(x));
const P = f => g => x => y => f(g(x))(g(y));
const Y = f => (g => g(g))(g => f(x => g(g)(x)));