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 /
Last active Nov 12, 2019
Better local require() paths for Node.js

Better local require() paths for Node.js


When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

branneman /
Last active Nov 10, 2019
Primitive Types & Reference Types in JavaScript

Primitive Types & Reference Types in JavaScript

An explanation of JavaScript's pass-by-value, which is unlike pass-by-reference from other languages.


  • JavaScript has 2 kinds of variable types: primitive and reference.
  • A fixed amount of memory is reserved after creation of every variable.
  • When a variable is copied, it's in-memory value is copied.
  • Passing a variable to a function via a call also creates a copy of that variable.

Primitive Types

branneman / gist:951847
Last active Nov 10, 2019
array_find() - A case insensitive array_search() with partial matches
View gist:951847
* Case in-sensitive array_search() with partial matches
* @param string $needle The string to search for.
* @param array $haystack The array to search in.
* @author Bran van der Meer <>
* @since 29-01-2010
branneman / svg-classes.js
Created Jan 15, 2014
SVG — hasClass, addClass, removeClass, toggleClass
View svg-classes.js
// SVG — hasClass, addClass, removeClass, toggleClass
// Source:
// Taken and adapted from:
if (SVGElement && SVGElement.prototype) {
branneman / fp-lenses.js
Last active Oct 25, 2019
JavaScript: Lenses (Functional Programming)
View fp-lenses.js
// FP Lenses
const lens = get => set => ({ get, set });
const view = lens => obj => lens.get(obj);
const set = lens => val => obj => lens.set(val)(obj);
const over = lens => fn => obj => set(lens)(fn(view(lens)(obj)))(obj);
const lensProp = key => lens(prop(key))(assoc(key));
View snake.clj
(ns main (:gen-class))
;; Snake :: [[int int]…]
;; vector of x,y tuples
;; head is first, tail is last
;; out-of-bounds? :: (int int int) -> bool
;; grid-size is 1-indexed, x+y are 0-indexed
(defn out-of-bounds? [grid-size x y]
(or (neg? x) (neg? y) (>= x grid-size) (>= y grid-size)))

List of all Clojure Predicate functions

A predicate function returns a boolean true or false, and it's name ends with a ?. Ran against Clojure 1.10.0.

({:ns clojure.string,
  ({:fn ends-with?, :arglists ([s substr])}
   {:fn starts-with?, :arglists ([s substr])}
   {:fn includes?, :arglists ([s substr])}
branneman / create-zip.js
Last active Sep 29, 2019
Node.js script to create a zip file from a list of files and directories
View create-zip.js
const stat = require('fs').statSync;
const AdmZip = require('adm-zip');
* Example usage
newArchive(`test-${+new Date}.zip`, [
View Struct.php
class Struct
* Define a new struct object, a blueprint object with only empty properties.
public static function factory()
$struct = new self;
foreach (func_get_args() as $value) {
branneman / fp.js
Last active Sep 18, 2019
JavaScript functional programming library
View fp.js
const { curryN, curry } = require('./curry') //
// Array higher-order
const map = curry((fn, list) =>
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))
You can’t perform that action at this time.