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 / better-nodejs-require-paths.md
Last active June 24, 2025 22:40
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

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
branneman / app.py
Last active June 7, 2025 14:14
Generating bidirectional Anki decks with Python from a CSV file
import csv
import genanki
from gtts import gTTS
import unicodedata
import re
import os
import sys
from pathlib import Path
if len(sys.argv) < 2:
@branneman
branneman / call-apply-bind-proxy.js
Last active April 19, 2025 05:17
JavaScript call() vs apply() vs bind() vs $.proxy()
var fn = function(arg1, arg2) {
var str = '<p>aap ' + this.noot + ' ' + arg1 + ' ' + arg2 + '</p>';
document.body.innerHTML += str;
};
var context = {
'noot': 'noot'
};
var args = ['mies', 'wim'];
// Calls a function with a given 'this' value and arguments provided individually.
@branneman
branneman / radicals.json
Created June 9, 2020 12:37
JSON list of 214 Simplified Chinese Radicals, data contains radical number, pinyin, english translation, stroke count
[
{
"id": 1,
"radical": "一",
"pinyin": "yī",
"english": "one",
"strokeCount": 1
},
{
"id": 2,
@branneman
branneman / splitser.js
Last active January 22, 2025 09:38
Splitser algorithm
export const getSettlement = (transactions) => {
const settlement = []
let recurProtection = 0
while (true) {
const balances = getBalances(transactions.concat(settlement))
if (allBalancesZero(balances)) break
if (recurProtection++ > 1e2) {
console.log({ settlement })
@branneman
branneman / primitive-reference-types-javascript.md
Last active October 28, 2024 04:04
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.

Facts

  • 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

$source = "C:\Program Files (x86)\World of Warcraft\_classic_era_\Screenshots"
$destination = "C:\Users\branv\Proton Drive\bran.van.der.meer\My files\70 - Backups\wow-classic\Screenshots"
$zipFolder1 = "C:\Program Files (x86)\World of Warcraft\_classic_era_\Interface"
$zipFolder2 = "C:\Program Files (x86)\World of Warcraft\_classic_era_\WTF"
$zipLocation = "C:\Users\branv\Proton Drive\bran.van.der.meer\My files\70 - Backups\wow-classic\"
$zipDate = Get-Date -Format "yyyy-MM-dd"
$zipFileName = "$zipLocation\wowclassic-backup-$zipDate.zip"
if (!(Test-Path -Path $destination)) {
@branneman
branneman / http-easy.rkt
Last active June 29, 2024 18:58
Racket: How to do HTTP requests
#lang racket/base
(require
net/http-easy)
(define (base-url path)
(string-append "https://httpbin.org" path))
; request: GET
; response: plain string body
@branneman
branneman / example-mod-wsgi.py
Last active June 28, 2024 17:49
pyinfo(). License: MIT
def application(environ, start_response):
import sys
path = 'YOUR_WWW_ROOT_DIRECTORY'
if path not in sys.path:
sys.path.append(path)
from pyinfo import pyinfo
output = pyinfo()
start_response('200 OK', [('Content-type', 'text/html')])
return [output]
@branneman
branneman / skills.md
Last active June 12, 2024 02:39
Front-End Software Craftsmanship

JavaScript knowledge

  • Operators, operands, operator precedence (unary, binary, ternary)
  • Dynamic Type system: types and conversion
    • Value type vs. Reference type
  • Expression vs. Statement
  • Scope
  • Hoisting
  • Overloading
  • Prototypal inheritance vs. Classical inheritance
  • Instancing