Skip to content

Instantly share code, notes, and snippets.

View davidchambers's full-sized avatar

David Chambers davidchambers

View GitHub Profile
@jethrolarson
jethrolarson / _usage.js
Last active April 25, 2016 01:10
xface - Functional Interface library for typed common apis
//Some fantasy implementations
const Just = require('./just')
const Cant = require('./cant')
const List = require('./list')
//Spec file that defines what arguments are used for type identification
const fantasy = require('./fantasy')
//The magic.
const {chain, map, index} = require('../../src/xface')(fantasy, [Just, Cant])
@raine
raine / index.js
Last active September 23, 2015 05:58
const { Future, IO } = require('ramda-fantasy');
const join2 = curryN(2, require('path').join);
const npa = require('npm-package-arg');
const ALIAS = /:([^!]+)/;
const EXTEND = /!$/;
const parseAlias = pipe(
S.match(ALIAS), chain(nth(1)));
const parseExtend = pipe(
S.match(EXTEND), map(T));
@Avaq
Avaq / combinators.js
Last active June 7, 2024 20:31
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 S_ = f => g => x => f (g (x)) (x)
const S2 = f => g => h => x => f (g (x)) (h (x))
@Avaq
Avaq / placeholder.md
Last active April 15, 2019 16:04
Exploring an alternative placeholder implementation

I published a library which implements this idea; furry.

# From To Normal Alternative
1 a → b → c a → c f(_, b)(a) f(_, b)(a)
2 a → b → c b → a → c nope f(_)(b, a)
3 a → b → c → d b → d f(a, _, c)(b) f(a, _, c)(b)
4 a → b → c → d a → b → d f(_, _, c)(a, b) f(_, _, c)(a, b)
5 a → b → c → d a → c → d f(_, b)(a, c) f(_, b, _)(a, c)
--dropWhereRepeated [1, 2, 2, 3, 3, 5, 7, 10]
--[1,5,7,10]
dropWhereRepeated :: (Eq a) => [a] -> [a]
dropWhereRepeated [] = []
dropWhereRepeated [x] = [x]
dropWhereRepeated (x : y : xs)
| x == y = dropWhereRepeated (dropWhile (== x) (xs))
| otherwise = x : dropWhereRepeated (y : xs)
@safareli
safareli / Array.chainRec.js
Last active December 27, 2016 01:03
Implementation of ChainRec from Fantasy Land specification for Array
var flatten = Function.prototype.apply.bind([].concat, [])
Array.prototype.chain = function(f) {
return flatten(this.map(f))
}
var stepNext = function (x) { return {value: x, done: false }; };
var stepDone = function (x) { return {value: x, done: true }; };
Array.chainRec = function _chainRec(f, i) {
var todo = [i];
var res = [];
@Avaq
Avaq / dangerous-promises.js
Last active October 12, 2021 04:13
Dangerous Promises
//
// utils
//
const thrush = x => f => f(x);
const indexBy = k => xs => xs.reduce((index, x) => {
if(index[x[k]] != null) index[x[k]].push(x);
else index[x[k]] = [x];
return index;
const after = t => x => cont => {
const id = setTimeout (cont, t, x)
return () => clearTimeout (id)
}
const map = f => run => cont => run(x => cont (f (x)))
const chain = f => run => cont => run(x => f (x) (cont))
const run = chain (x => after (2000) (`${x}C`))
(map (x => `${x}B`)
@bbqtd
bbqtd / macos-tmux-256color.md
Last active June 1, 2024 11:51
Installing tmux-256color for macOS

Installing tmux-256color for macOS

  • macOS 10.15.5
  • tmux 3.1b

macOS has ncurses version 5.7 which does not ship the terminfo description for tmux. There're two ways that can help you to solve this problem.

The Fast Blazing Solution

Instead of tmux-256color, use screen-256color which comes with system. Place this command into ~/.tmux.conf or ~/.config/tmux/tmux.conf(for version 3.1 and later):

@sindresorhus
sindresorhus / esm-package.md
Last active June 10, 2024 11:23
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.