Skip to content

Instantly share code, notes, and snippets.

const trace = (x, y) => {
console.log(x)
return y
}
const trace1 = x => trace(x, x)
const id = x => x
const swap = ([x, y]) => [y, x]
const trace = (x, y) => {
console.log(x)
return y
}
const trace1 = x => trace(x, x)
const id = x => x
Promise.prototype.map = function(f) {
return this.then(x => {
const wrap1 = (arrow, before, after, f) =>
arrow.arr(before).pipe(arrow.arrM(f)).pipe(arrow.arr(after))
const wrap12 = (arrow, before, after, f) => new arrow(x => {
let b = arrow.arr(before).run(x)
let y = arrow.id.pipe(arrow.arrM(f)).run(b)
return arrow.id.pipe(arrow.arr(after)).run(y)
})
class Func {
const timeIt = R.curry((report, f) => (...args) => {
const t0 = Date.now()
const nArgs = R.init(args)
const callback = R.last(args)
nArgs.push((...args) => {
const t1 = Date.now()
callback(...args)
report(t1 - t0, ...args)
const trace = (msg, x) => {
console.log(msg)
return x
}
const serviceCall = x =>
Math.random() > 0.5
? Promise.resolve(x)
: Promise.reject(`not lucky ${x}`)
const trace = (msg, x) => {
console.log(msg)
return x
}
const serviceCall = x =>
Math.random() > 0.5
? Promise.resolve(x)
: Promise.reject(`not lucky ${x}`)
var stream = require("stream");
var rstream = (function() {
var i = 0;
var rstream = new stream.Readable();
rstream._read = function(){
return this.push(++i > 2 ? "" : ["hello","world"][i-1]);
};
return rstream
})();
var wstream = new stream.Writable();
// utility range function, creates a list of [0, 1, 2, ..., i]
const range = i => [...Array(i).keys()]
// fixed point, Y combinator (proof at the end of the code)
const fix = f =>
(g => z => f(g(g))(z)) (g => z => f(g(g))(z))
// open recursive definition of factorial funciton
// note that x is a funciton
@homam
homam / secure-nc-message.sh
Created April 13, 2016 07:00
encrypt messages from server to client with nc
# server
while true; do read ui; echo $ui | openssl enc -aes128 -a -k PaSSw; done | nc -vl 192.168.1.2 1300
# client
nc 192.168.1.2 1300 | while read so; do decoded=`echo "$so" | openssl enc -d -a -aes128 -k PaSSw`; echo "$decoded"; done;
@homam
homam / client.ls
Last active April 7, 2016 12:31
RxJS from-web-socket example
from-web-socket = require \./ws
ws = from-web-socket 'ws://'
.filter ({name}) -> name == \all-campaigns
.map ({data}) -> JSON.parse data
.subscribe do
(x) ->
console.log x
#ws.dispose!
(ex) ->