Skip to content

Instantly share code, notes, and snippets.

View branneman's full-sized avatar

Bran van der Meer branneman

View GitHub Profile
@branneman
branneman / howto.md
Last active April 23, 2019 08:42
Run Debian as docker container

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 August 2, 2022 05:50
JavaScript functional programming library
const { curryN, curry } = require('./curry') // https://gist.github.com/branneman/4ffb7ec3fc4a2091849ba5d56742960c
// Typechecks
const isUndef = x => typeof x === 'undefined'
const isNull = x => x === null
const isBool = x => typeof x === 'boolean'
const isNum = x => typeof x === 'number' && isFinite(x)
const isInt = x => typeof x === 'number' && isFinite(x) && Math.floor(x) === x
const isStr = x => typeof x === 'string'
const isArr = x => Array.isArray(x)
@branneman
branneman / curry.js
Last active August 2, 2022 05:51
Higher order auto curry function
'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 / type-checks.js
Last active June 28, 2022 15:06
JavaScript strict type checking functions
module.exports = factory
function factory() {
const exports = {
isDef,
isUndef,
isNull,
isBool,
isNum,
isInt,
@branneman
branneman / turing-machine-interpreter.js
Last active February 12, 2019 12:12
Turing Machine Interpreter in JavaScript
/**
* 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 September 16, 2022 17:57
Hogget language specification - https://hogget.org/

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 October 22, 2018 15:40
React + Apollo: Integration test without `await wait(0)` (and the waait dependency)
/**
* 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 September 5, 2018 11:57
Updates a DNS record via Gandi's API
#!/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 March 30, 2022 15:56
Node.js: Create salted hashed password
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 February 13, 2018 10:41
JavaScript: Recursive Binary Search algorithm
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
}