Skip to content

Instantly share code, notes, and snippets.


Bran van der Meer branneman

View GitHub Profile
branneman /
Last active Dec 2, 2022
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 25, 2022
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

def application(environ, start_response):
import sys
if path not in sys.path:
from pyinfo import pyinfo
output = pyinfo()
start_response('200 OK', [('Content-type', 'text/html')])
return [output]
branneman / 1.js
Last active Nov 2, 2022
JavaScript examples: No coupling, Loose coupling, Tight coupling
View 1.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() {
function b() {}
View 1.js
// Interface of a primitive variable: its name and type
const DEFAULT_DB_HOST = 'localhost'
// Interface of a container variable: its name, types and structures
const config = {
user: 'readuser',
pass: '******',
db: 'test-env',
branneman / git.js
Last active Oct 11, 2022
How Git works - super simplified!
View git.js
// blob = file contents, identified by hash
const blobs = {
'73d8a': 'import x from "y"; console.log("some file contents")',
'9c6bd': 'D8 A1 31 0F ...',
'547d4': '# Readme\nThis is documentation',
'a0302': '# Readme\nThis is some updated documentation',
// tree = references to blobs and trees, identified by hash
const trees = {
branneman / unit-testing.js
Last active Oct 5, 2022
How I write High Quality Unit tests -
View unit-testing.js
* Returns a list of numbers from `min` (inclusive) to `max` (exclusive).
const range = (min, max, acc = []) => {
if (max < min) throw new Error('not supported!')
if (min >= max) return acc
return range(min + 1, max, acc.concat(min))
branneman /
Last active Sep 16, 2022
Hogget language specification -

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.

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 / lambda-img-to-webp.js
Created May 5, 2017
AWS Lambda@Edge whitelisted image to webp request mapper
View lambda-img-to-webp.js
'use strict';
const whitelist = {
'/static/img/photo.jpg': '/static/img/photo.webp'
exports.handler = (event, context, callback) => {
// Grab HTTP request and it's headers
const request = event.Records[0].cf.request;