Skip to content

Instantly share code, notes, and snippets.

Jacob Bass bassjacob

Block or report user

Report or block bassjacob

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
@bassjacob
bassjacob / actionlist.vim
Created Aug 13, 2019 — forked from zchee/actionlist.vim
IdeaVim actionlist
View actionlist.vim
--- 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 Oct 9, 2017
immutable 3.x.x flowtype binding
View immutable.js
/**
* 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 Sep 28, 2017
Stdlib example
View stdlib.js
// 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 Sep 9, 2017
Promise, Async Await and Cats
View promises.md

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) => Promise.resolve(a + b);
View simple synth
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,
View simple-oscillator.re
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),
View simpleanim.re
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 Apr 20, 2017
a simple shim for ava's it.failing function
View failing.js
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();
View promises examples.js
function one (x) {
console.log(x);
}
function two (x, cb) {
setTimeout(function () {
console.log(x);
cb(x);
}, 1000);
}
You can’t perform that action at this time.