Skip to content

Instantly share code, notes, and snippets.

@bassjacob
bassjacob / actionlist.vim
Created August 13, 2019 02:24 — forked from zchee/actionlist.vim
IdeaVim actionlist
--- Actions ---
$Copy <M-C>
$Cut <M-X> <S-Del>
$Delete <Del> <BS> <M-BS>
$LRU
$Paste <M-V>
$Redo <M-S-Z> <A-S-BS>
$SearchWeb <A-S-G>
$SelectAll <M-A>
$Undo <M-Z>
@bassjacob
bassjacob / immutable.js
Created October 9, 2017 22:30
immutable 3.x.x flowtype binding
/**
* This file provides type definitions for use with the Flow type checker.
*
* An important caveat when using these definitions is that the types for
* `Iterable.Keyed`, `Iterable.Indexed`, `Seq.Keyed`, and so on are stubs.
* When referring to those types, you can get the proper definitions by
* importing the types `KeyedIterable`, `IndexedIterable`, `KeyedSeq`, etc.
* For example,
*
* import { Seq } from 'immutable'
@bassjacob
bassjacob / stdlib.js
Last active September 28, 2017 00:27
Stdlib example
// in your library
const ArrayImpl = {
sum: els => els.reduce((p, c) => p + c),
};
const ObjectImpl = {
map: (f, obj) => Object.keys(obj).reduce((p, c) => Object.assign(p, { [c]: f(obj[c]) }), {}),
};
module.export = {
@bassjacob
bassjacob / promises.md
Created September 9, 2017 10:21
Promise, Async Await and Cats

My issue with async/await specifically, and promises generally is that it blurs the line between a value and a value object. If you think about Promise { value } it becomes very important whether a function returns a value or a promise wrapped value. Unfortunately, JS promises don't behave like category theory objects (so much for the myriad of Promises are Monads blogposts) and will resolve nested values until done or rejected. This can make reasoning about their behaviour tricky and makes writing types for their functions tougher as well.

Let's start with my ideal in JS, just using promises:

/* pretend these functions are network calls, hence the promise.resolve */
const producesA = () => Promise.resolve(1);
const producesB = a => Promise.resolve(a + 1);
const doSomething = (a, b) =&gt; Promise.resolve(a + b);
open Containers;
external pow : float => float => float = "Math.pow" [@@bs.val];
external requestAnimationFrame : (unit => unit) => unit = "window.requestAnimationFrame" [@@bs.val];
module rec AudioContext: {
type destination;
type t = Js.t {
.
destination : destination,
open Containers;
type destination;
type pitch = C | Cs | D | Eb | E | F | Fs | G | Gs | A | Bb | B;
module Pitches = Map.Make({ type t = pitch; let compare = compare; });
let pitches = Pitches.fromList
[
(C, 16.35),
(Cs, 17.32),
open ReasonJs;
open Dom;
open Document;
type ctx;
type canvas;
external pi : float = "Math.PI" [@@bs.val];
external sin : float => float = "Math.sin" [@@bs.val];
external cos : float => float = "Math.cos" [@@bs.val];
@bassjacob
bassjacob / failing.js
Created April 20, 2017 02:47
a simple shim for ava's it.failing function
function failing (ctx, name, fn) {
const error = () => { throw new Error('remove the failing bit') };
if (fn.length > 0) {
return ctx(name, function (done) {
fn(function(err) {
if (!err) {
return done(error());
}
return done();
function one (x) {
console.log(x);
}
function two (x, cb) {
setTimeout(function () {
console.log(x);
cb(x);
}, 1000);
}