Skip to content

Instantly share code, notes, and snippets.

Bran van der Meer branneman

Block or report user

Report or block branneman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@branneman
branneman / howto.md
Last active Oct 1, 2017
macOS: Manage Multiple versions of Java
View howto.md

macOS: Manage Multiple versions of Java

Setup tooling

brew update
brew install jenv
brew tap caskroom/cask
brew tap caskroom/versions
mkdir ~/.jenv/versions
@branneman
branneman / create-zip.js
Last active Sep 7, 2019
Node.js script to create a zip file from a list of files and directories
View create-zip.js
const stat = require('fs').statSync;
const AdmZip = require('adm-zip');
/**
* Example usage
*/
newArchive(`test-${+new Date}.zip`, [
'index.js',
'package.json',
'node_modules'
View a-page.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Homepage</title>
<!-- If HTTP/1: Inline with <style>, remove this <link> -->
<!-- If HTTP/2: Server push this CSS file, and leave this <link> -->
<link rel="stylesheet" href="critical-homepage.css">
@branneman
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;
@branneman
branneman / app.js
Last active Jan 2, 2018
[FP playground] Generate diceware passwords with NodeJS. See also: https://www.rempe.us/diceware/
View app.js
const map = fn => list => list.map(fn);
const filter = fn => list => list.filter(fn);
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
const tail = list => list.slice(1);
const fill = val => num => new Array(num).fill(val);
const getFileContents = file => require('fs').readFileSync(file, { encoding: 'utf8' });
const split = char => str => str.split(char);
const join = char => list => list.join(char);
View keybase.md

Keybase proof

I hereby claim:

  • I am branneman on github.
  • I am branneman (https://keybase.io/branneman) on keybase.
  • I have a public key ASBUXh5Xc1fnzeLViPT2_Wo268hlgsOINNiGJ7UzbkiVXQo

To claim this, I am signing this object:

View prefixEventListener.js
/**
* Capitalize
*/
const capitalize = string => {
return string.charAt(0).toUpperCase() + string.slice(1);
};
/**
* Prefix EventListener
*/
@branneman
branneman / executedBatched.js
Created Nov 1, 2016
executeBatched() – Run a list of async tasks as promises and wait after each batch
View executedBatched.js
/**
* Run a list of async tasks as promises and wait after each batch
* @param {Number} batchSize - Number of tasks to run in parallel
* @param {Number} waitTime - Time to wait after each batch, in milliseconds
* @param {Array<Function>} tasks - Promise executor functions (not promise objects!)
* @return {Promise<Array<*>>}
*/
function executeBatched(batchSize, waitTime, tasks) {
tasks = tasks.slice();
@branneman
branneman / modules.js
Last active Mar 29, 2019
A history of different JavaScript module formats
View modules.js
/**
* Globals
*/
var Carrousel = function(elem) { this.init() };
Carrousel.prototype = { init: function() {} };
new Carrousel();
/**
* Namespacing
* - No globals (only the namespace variable itself is global)
@branneman
branneman / es2015-returning-from-constructor.js
Last active Sep 20, 2016
ES2015: Returning a Promise from a constructor — Warning: I'm fairly sure this is always an anti-pattern.
View es2015-returning-from-constructor.js
class Parent {
constructor() {
return new Promise(resolve => {
setTimeout(() => resolve({ data: 'important' }), 1e3);
});
}
}
class Child extends Parent {
constructor() {
You can’t perform that action at this time.