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 / salt-hash-password.js
Last active March 30, 2022 15:56
Node.js: Create salted hashed password
const crypto = require('crypto')
const { promisify } = require('util')
const pbkdf2 = promisify(crypto.pbkdf2)
module.exports = { createHashPasswordFn, isPasswordCorrect }
/**
* @typedef {Object} HashPassword
* @property {String} hash
* @property {String} salt
@branneman
branneman / recursive-binary-search.js
Last active February 13, 2018 10:41
JavaScript: Recursive Binary Search algorithm
const indexOf = node => list => {
const guess = (min, max) => {
const index = Math.floor((max - min) / 2) + min
if (list[index] === node) {
return index
} else if (list[index] < node) {
min = index + 1
} else {
max = index - 1
}
@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 [email protected]: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)
/**
* @module GTMEventTracking
* @example
* <a
* data-module="event-tracking/GTMEventTracking"
* data-payload='{"event":"EventOpenGoogle"}'
* href="https://google.com/" target="_blank">
* Click me
* </a>
*/
@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 / fp-lenses.js
Last active May 17, 2023 00:56
JavaScript: Lenses (Functional Programming)
// FP Lenses
const lens = get => set => ({ get, set });
const view = lens => obj => lens.get(obj);
const set = lens => val => obj => lens.set(val)(obj);
const over = lens => fn => obj => set(lens)(fn(view(lens)(obj)))(obj);
const lensProp = key => lens(prop(key))(assoc(key));
@branneman
branneman / howto.md
Last active October 1, 2017 16:16
macOS: Manage Multiple versions of Java

macOS: Manage Multiple versions of Java

Setup tooling

brew update
brew install jenv
brew tap caskroom/cask
brew tap caskroom/versions
mkdir ~/.jenv/versions