Instantly share code, notes, and snippets.

View _util.js
/**
* 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) {
View index.js
#!/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
View salt-hash-password.js
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
View recursive-binary-search.js
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
}
View vscode-settings.md

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)
View GTMEventTracking.js
/**
* @module GTMEventTracking
* @example
* <a
* data-module="event-tracking/GTMEventTracking"
* data-payload='{"event":"EventOpenGoogle"}'
* href="https://google.com/" target="_blank">
* Click me
* </a>
*/
View primitive-reference-types-javascript.md

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

View fp-lenses.js
// 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));