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 / composition.js
Last active April 15, 2018 19:51
OO JavaScript: Inheritance vs. Composition
//
// hasPosition trait
//
const hasPosition = state => ({
setPosition: function(x, y) {
this.x = x;
this.y = y;
}.bind(state)
});
@branneman
branneman / dump.php
Created July 30, 2013 08:16
PHP: A better formatted var_dump()
function dump($var) {
ob_start();
var_dump($var);
$output = ob_get_clean();
echo preg_replace("/=>(\s+)/m", ' => ', $output);
}
@branneman
branneman / index.js
Last active September 5, 2018 11:57
Updates a DNS record via Gandi's API
#!/usr/bin/env node
const fetch = require('node-fetch')
const ip = require('ip')
const os = require('os')
const env = require('./.env.json')
const endpoint = 'https://dns.api.gandi.net/api/v5/'
const newip = `${ip.address()}`
const domain = env.domain
@branneman
branneman / vscode-settings.md
Last active October 9, 2018 08:05
Visual Studio Code: My setup

Visual Studio Code: My setup (macOS)

Global settings

git clone git@github.com:branneman/dotfiles.git ~/.dotfiles
ln -s ~/.dotfiles/vscode-settings.json "~/Library/Application Support/Code/User/settings.json"

Run from terminal

  • Open the Command Palette ( + + P)
@branneman
branneman / _util.js
Created October 22, 2018 15:40
React + Apollo: Integration test without `await wait(0)` (and the waait dependency)
/**
* This function polls the component's props for Apollo to set `props.data.loading` to `false`
* @example
* await waitDuringLoadingState(testRenderer, TodoContainer)
* @see {@link https://reactjs.org/docs/test-renderer.html}
* @param {TestRenderer} testRenderer
* @param {React.Component} testComponent
* @returns {Promise}
*/
export function waitDuringLoadingState(testRenderer, testComponent) {
@branneman
branneman / server.js
Created June 13, 2013 13:31
Node.js — Serve generated PNG from SVG, specifying dimensions in the url/filename. This node.js express server generates 'checkmark.svg.107x94.png' from 'checkmark.svg' with Inkscape CLI
var fs = require('fs'),
exec = require('child_process').exec,
express = require('express'),
app = express();
app.get('/static/img/*.svg.*.png', function(req, res) {
var pngFile = 'src' + req.url,
svgFile = pngFile.substring(0, pngFile.indexOf('.svg') + 4);
if (!fs.existsSync(svgFile)) {
return res.render('404', {
@branneman
branneman / event.js
Last active December 27, 2018 11:58
JavaScript window resize event with a 100ms delay
$(function() {
var resizeEnd;
$(window).on('resize', function() {
clearTimeout(resizeEnd);
resizeEnd = setTimeout(function() {
$(window).trigger('resize-end');
}, 100);
});
});
@branneman
branneman / turing-machine-interpreter.js
Last active February 12, 2019 12:12
Turing Machine Interpreter in JavaScript
/**
* Turing Machine Interpreter
*
* Features:
* - Infinite tape, both ways
* - Uses JS values, anything that matches ==, is a valid symbol
*
* Definition:
* - States (Q): { integer, halt }
* - Input symbols read/write (Σ): any integer or string
@branneman
branneman / breakpoints.scss
Last active February 19, 2019 08:57
JavaScript - CSS breakpoint Sync
/**
* Set the breakpoints as a font-family and pseudo element.
* This way JavaScript can read the current active breakpoint.
*/
head {
font-family: 'no-breakpoint';
}
body:after {
display: none;
content: 'no-breakpoint';
@branneman
branneman / howto.md
Last active April 23, 2019 08:42
Run Debian as docker container

Run Debian as docker container

Setup

Start a container in detached mode:

docker run -dit --name deb -e "LANG=C.UTF-8" -w "/root" debian:latest bash

Connect to it and do initial setup: