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 / 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 / better-nodejs-require-paths.md
Last active June 29, 2024 16:00
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 / 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 / primitive-reference-types-javascript.md
Last active May 12, 2024 03:45
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 / 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) {
@branneman
branneman / call-apply-bind-proxy.js
Last active February 22, 2024 21:06
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.