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 / 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

@branneman
branneman / better-nodejs-require-paths.md
Last active October 18, 2024 20:29
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

$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
@branneman
branneman / index.html
Created April 13, 2024 13:22
HTML5 Video: MediaSource, SourceBuffer, video segments, etc.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, viewport-fit=cover"
/>
<title>video test</title>
</head>
@branneman
branneman / six-nations-table.test.ts
Last active March 23, 2024 14:53
Six Nations table calculator
import { describe, expect, it } from 'vitest'
import { Table, Match } from './six-nations-table'
import {
matches2table,
updateTable,
getTable,
orderTable,
PgamesPlayed,
WgamesWon,
LgamesLost,
@branneman
branneman / Struct.php
Created May 2, 2011 09:53
PHP Struct class
<?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) {