Instantly share code, notes, and snippets.

Bran van der Meer branneman

View GitHub Profile
@branneman
branneman / fp.js
Last active Feb 15, 2019
JavaScript functional programming library
View fp.js
const { curryN, curry } = require('./curry') // https://gist.github.com/branneman/4ffb7ec3fc4a2091849ba5d56742960c
// Array
const nth = curry((key, list) => list[key])
const slice = curry((from, to, list) => list.slice(from, to))
const head = nth(0)
const init = slice(0, -1)
const tail = slice(1, Infinity)
const last = slice(-1, Infinity)
const reverse = list => list.slice().reverse()
@branneman
branneman / curry.js
Last active Feb 14, 2019
Higher order auto curry function
View curry.js
const curryN = (fn, arity, accIn = []) => (...args) => {
const len = args.length
const accOut = accIn.concat(args)
if (len + accIn.length >= arity) {
return fn.apply(this, accOut)
}
return curryN(fn, arity, accOut)
}
const curry = fn => curryN(fn, fn.length)
@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) {
@branneman
branneman / index.js
Last active Sep 5, 2018
Updates a DNS record via Gandi's API
View index.js
#!/usr/bin/env node
const fetch = require('node-fetch')
const ip = require('ip')
const os = require('os')
const env = require('./.env.json')
const endpoint = 'https://dns.api.gandi.net/api/v5/'
const newip = `${ip.address()}`
const domain = env.domain
@branneman
branneman / salt-hash-password.js
Last active Jul 13, 2018
Node.js: Create salted hashed password
View salt-hash-password.js
const crypto = require('crypto')
const { promisify } = require('util')
const pbkdf2 = promisify(crypto.pbkdf2)
module.exports = { createHashPasswordFn, isPasswordCorrect }
/**
* @typedef {Object} HashPassword
* @property {String} hash
* @property {String} salt
@branneman
branneman / recursive-binary-search.js
Last active Feb 13, 2018
JavaScript: Recursive Binary Search algorithm
View recursive-binary-search.js
const indexOf = node => list => {
const guess = (min, max) => {
const index = Math.floor((max - min) / 2) + min
if (list[index] === node) {
return index
} else if (list[index] < node) {
min = index + 1
} else {
max = index - 1
}
@branneman
branneman / vscode-settings.md
Last active Oct 9, 2018
Visual Studio Code: My setup
View vscode-settings.md

Visual Studio Code: My setup (macOS)

Global settings

git clone git@github.com:branneman/dotfiles.git ~/.dotfiles
ln -s ~/.dotfiles/vscode-settings.json "~/Library/Application Support/Code/User/settings.json"

Run from terminal

  • Open the Command Palette ( + + P)