Skip to content

Instantly share code, notes, and snippets.


Tony Brown anthonybrown

View GitHub Profile
anthonybrown / add.js
Last active Aug 15, 2019
Using closures, higher order functions to have a stateful function
View add.js
function getAdd() {
let foo = 0;
return function() {
foo = foo + 1;
return foo;
const add = getAdd()
View symbolToPrimitive.js
class Decimal {
constructor(number) {
this.precision = 8
this.number = number
this.integer = Math.floor(number)
this.fractional = Math.round(number * Math.pow(10, this.precision))
[Symbol.toPrimitive](hint) {
// hint can be: string, number, default
anthonybrown /
Created Jul 20, 2019 — forked from ljharb/
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.


JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

anthonybrown /
Last active Jun 20, 2019
Mac OS terminal commands

Terminal Cheatsheet for Mac (Basics)

Letters are shown capitalized for readability only. Capslock should be off.


Key/Command Description
Ctrl + A Go to the beginning of the line you are currently typing on. This also works for most text input fields system wide. Netbeans being one exception
Ctrl + E Go to the end of the line you are currently typing on. This also works for most text input fields system wide. Netbeans being one exception
anthonybrown / create-react-component.js
Created Jun 18, 2019 — forked from rastating/create-react-component.js
A script to create the boilerplate code for a new React.js component with a [Jest] spec file
View create-react-component.js
#! /usr/bin/env node
# Usage: node create-react-component.js ComponentName
# Note: If a `components` directory does not exist in the current working directory, nothing will be created
const fs = require('fs')
const path = require('path')
const componentName = process.argv[2]
const componentPath = path.join(



  • ✏️ method changes this.
  • 🔒 method does not change this.


  • concat(...items: Array): T[] 🔒 ES3
anthonybrown / flux.js
Created May 30, 2019 — forked from acdlite/flux.js
A Redux-like Flux implementation in <75 lines of code
View flux.js
* Basic proof of concept.
* - Hot reloadable
* - Stateless stores
* - Stores and action creators interoperable with Redux.
import React, { Component } from 'react';
export default function dispatch(store, atom, action) {
anthonybrown / myHigherOderFunction.js
Last active Jun 10, 2019
An example of functional programing using a higher order function
View myHigherOderFunction.js
let formatCurrency = function( currencySymbol, decimalSeparator ) {
return function( value ) {
let wholePart = Math.trunc(value / 100);
let fractionalPart = value % 100;
if ( fractionalPart < 10 ) fractionalPart = '0' + fractionalPart;
return `${currencySymbol}${wholePart}${decimalSeparator}${fractionalPart}`;
let formatter = formatCurrency( '$', '.' );
anthonybrown / vscode.json
Last active Jun 10, 2019
My current vscode settings as of May 2019
View vscode.json
// Place your settings in this file to overwrite the default settings
"window.zoomLevel": 1,
"editor.formatOnSave": true,
"editor.detectIndentation": true,
"editor.fontSize": 18,
// "editor.lightbulb.enabled": false,
"editor.parameterHints.enabled": false,
"editor.fontFamily": "Operator Mono",
"editor.fontLigatures": true,