Skip to content

Instantly share code, notes, and snippets.

💭
developing a plugin for atom, rest is mostly garbage

François-Marie de Jouvencel djfm

Block or report user

Report or block djfm

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View couchbase-easier-api.js
const {
Cluster,
N1qlQuery,
MutationState,
} = require('couchbase');
const URL = require('url');
const addQueryParams = params => url => {
const parsed = URL.parse(url);
View chain-do-maybe.js
const just = x => Promise.resolve(x);
const nothing = () => Promise.reject();
chain(
() => just(1),
() => nothing(),
(_, x, y) => just(x / y)
)()
.should.be.rejected;
View chain-do.js
const chainStep = fn => (argSource, history) => {
if (argSource && (typeof argSource === 'object')) {
const then = argSource.then;
if (typeof then === 'function') {
return Promise.all(history).then(
settledHistory =>
then.call(argSource, arg => fn(arg, ...settledHistory))
);
}
}
View increment-ids-check-hakell-fiction.hs
do
a <- makeId "dress"
b <- makeId "dress"
c <- makeId "dress"
return checkOrdered a b c
View increment-ids-check-yuck.js
storage.makeId('dress')
.then(
a =>
storage.makeId('dress')
.then(
b =>
storage.makeId('dress')
.then(
c => {
a.should.be.lessThan(b);
View increment-ids-check.js
chain(
() => storage.makeId('dress'),
() => storage.makeId('dress'),
() => storage.makeId('dress'),
(_, a, b, c) => {
a.should.be.lessThan(b);
a.should.be.lessThan(c);
b.should.be.lessThan(c);
}
)()
View chain-promise.js
const chain = (...fns) =>
initialValue => fns.reduce(
(result, fn) => {
if (result && (typeof result === 'object')) {
const then = result.then;
if (typeof then === 'function') {
return then.call(result, fn);
}
}
return fn(result);
View chain-simple.js
const chain = (...fns) => initialValue =>
fns.reduce((previousOutput, fn) => fn(previousOutput), initialValue);
chain(x => x + 1, x => x / 2)(0).should.equal(0.5);
chain(x => x / 2, x => x + 1)(0).should.equal(1);
// run it: https://jsfiddle.net/s8hwae47/
@djfm
djfm / monad.js
Created Jul 25, 2016
incomplete but fun monad implementation attempt
View monad.js
const chai = require('chai');
chai.should();
const listMonad = {
// make :: a -> m a
// make :: a -> [a]
make: (...args) => args,
// bind :: m a -> (a -> m b) -> m b
// bind :: [a] -> (a -> [b]) -> [b]
bind: someList => listReturningFunction =>
@djfm
djfm / waitForBrowserSide.js
Created Mar 24, 2016
Useful webdriver.io command to wait for things in the browser's JS execution environment
View waitForBrowserSide.js
browser.addCommand('waitForBrowserSide', function waitForBrowserSide (callback) {
return browser
.timeoutsAsyncScript(10000)
.executeAsync(function thisRunsInsideTheBrowser(callback, done) {
setInterval(function () {
if (callback()) {
done();
}
}, 100);
}, callback)
You can’t perform that action at this time.