Skip to content

Instantly share code, notes, and snippets.

View anthonybrown's full-sized avatar
🎯
Focusing

Tony Brown anthonybrown

🎯
Focusing
View GitHub Profile
@anthonybrown
anthonybrown / add.js
Last active August 15, 2019 01:38
Using closures, higher order functions to have a stateful function
function getAdd() {
let foo = 0;
return function() {
foo = foo + 1;
return foo;
};
}
const add = getAdd()
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
node_modules
package-lock.json
@anthonybrown
anthonybrown / array_iteration_thoughts.md
Created July 20, 2019 16:40 — forked from ljharb/array_iteration_thoughts.md
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.

Intro

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
anthonybrown / commands.md
Last active June 20, 2019 09:26
Mac OS terminal commands

Terminal Cheatsheet for Mac (Basics)

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

SHORTCUTS

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
anthonybrown / create-react-component.js
Created June 18, 2019 12:17 — 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
#! /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(
'components',
componentName

Array<T>

Legend:

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

Array<T>.prototype.*:

  • concat(...items: Array): T[] 🔒 ES3
@anthonybrown
anthonybrown / flux.js
Created May 30, 2019 09:34 — forked from acdlite/flux.js
A Redux-like Flux implementation in <75 lines of code
/**
* 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
anthonybrown / myHigherOderFunction.js
Last active June 10, 2019 00:20
An example of functional programing using a higher order function
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
anthonybrown / vscode.json
Last active June 10, 2019 00:14
My current vscode settings as of May 2019
{
// 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,