Skip to content

Instantly share code, notes, and snippets.

Bran van der Meer branneman

Block or report user

Report or block branneman

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
@branneman
branneman / 0-katas.md
Last active Sep 12, 2019
Software Craftsmanship Katas in Clojure
View 0-katas.md

Software Craftsmanship Katas in Clojure

To run these as-is, you'll need to have Clojure and Leiningen with the lein-exec plugin installed. Then run from the terminal:

git clone https://gist.github.com/258926ff07c85b4e6f5cafc4967740ec.git katas-clojure
cd katas-clojure
lein exec fizzbuzz.clj
lein exec leapyears.clj
lein exec rpn-calculator.test.clj
@branneman
branneman / solution1.js
Last active Aug 5, 2019
Declarative asynchonous control flow: promises, observables, futures
View solution1.js
const wrapPromise = fn => (...args) =>
new Promise(resolve => setTimeout(
() => resolve(fn(...args)),
Math.floor(Math.random() * 1500) + 250)
)
const upper = wrapPromise(str => str.toUpperCase())
const underline = str => `__${str}__`
const exclamate = wrapPromise(str => str + '!')
// Util: Create promise chain
@branneman
branneman / coupling.js
Last active Aug 16, 2019
JavaScript examples: No coupling, Loose coupling, Tight coupling
View coupling.js
//
// Tight coupling from A to B => A needs B to be defined, callable and adhere to an interface
// No coupling from B to A => B does not need A in any way (pure fn)
//
function a() { b() }
function b() {}
a()
//
// No coupling from A to B => A and B work independently,
@branneman
branneman / howto.md
Last active Apr 23, 2019
Run Debian as docker container
View howto.md

Run Debian as docker container

Setup

Start a container in detached mode:

docker run -dit --name deb -e "LANG=C.UTF-8" -w "/root" debian:latest bash

Connect to it and do initial setup:

@branneman
branneman / fp.js
Last active Sep 18, 2019
JavaScript functional programming library
View fp.js
const { curryN, curry } = require('./curry') // https://gist.github.com/branneman/4ffb7ec3fc4a2091849ba5d56742960c
// Array higher-order
const map = curry((fn, list) => list.map(fn))
const filter = curry((fn, list) => list.filter(fn))
const foldl = curry((fn, init, list) => list.reduce(fn, init))
const foldr = curry((fn, init, list) => list.reduceRight(fn, init))
const find = curry((fn, list) => list.find(fn))
const sort = curry((fn, list) => list.slice().sort(fn))
const includes = curry((fn, list) => list.includes(fn))
@branneman
branneman / curry.js
Last active Sep 14, 2019
Higher order auto curry function
View curry.js
'use strict'
const curryN = (() => {
const isPlaceholder = x => x['@@functional/placeholder'] === true
const filterPlaceholders = xs => xs.filter(x => isPlaceholder(x))
const filterValues = xs => xs.filter(x => !isPlaceholder(x))
return (arity, fn, accIn = []) => (...args) => {
const accOut = accIn.slice()
@branneman
branneman / validations.js
Created Feb 12, 2019
JavaScript strict type checking functions
View validations.js
export {
isNull,
isUndef,
isBool,
isNum,
isInt,
isStr,
isArr,
isObj,
isFunc,
@branneman
branneman / turing-machine-interpreter.js
Last active Feb 12, 2019
Turing Machine Interpreter in JavaScript
View turing-machine-interpreter.js
/**
* Turing Machine Interpreter
*
* Features:
* - Infinite tape, both ways
* - Uses JS values, anything that matches ==, is a valid symbol
*
* Definition:
* - States (Q): { integer, halt }
* - Input symbols read/write (Σ): any integer or string
@branneman
branneman / philosophy.md
Last active Dec 20, 2018
Hogget language specification - https://hogget.org/
View philosophy.md

Hogget: Philosophy

Elevator pitch

  • Functional programming language
  • Strong typed
  • Dense syntax, everything is an expression
  • Compiles to JavaScript

The Name

A Hogget is a sheep between one and two years of age. Inspired by Ramda, we also like sheep.

@branneman
branneman / _util.js
Created Oct 22, 2018
React + Apollo: Integration test without `await wait(0)` (and the waait dependency)
View _util.js
/**
* This function polls the component's props for Apollo to set `props.data.loading` to `false`
* @example
* await waitDuringLoadingState(testRenderer, TodoContainer)
* @see {@link https://reactjs.org/docs/test-renderer.html}
* @param {TestRenderer} testRenderer
* @param {React.Component} testComponent
* @returns {Promise}
*/
export function waitDuringLoadingState(testRenderer, testComponent) {
You can’t perform that action at this time.