Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Tony Brown anthonybrown

🎯
Focusing
View GitHub Profile
@anthonybrown
anthonybrown / Enhance.js
Created Oct 16, 2020 — forked from sebmarkbage/Enhance.js
Higher-order Components
View Enhance.js
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@anthonybrown
anthonybrown / twittermute.txt
Created Jan 24, 2020 — forked from IanColdwater/twittermute.txt
Here are some terms to mute on Twitter to clean your timeline up a bit.
View twittermute.txt
Mute these words in your settings here: https://twitter.com/settings/muted_keywords
ActivityTweet
generic_activity_highlights
generic_activity_momentsbreaking
RankedOrganicTweet
suggest_activity
suggest_activity_feed
suggest_activity_highlights
suggest_activity_tweet
View getFirstLast.js
function getFirstLast(array) {
const {
0: first,
length: len,
[len - 1]: last
} = array
return {first, last}
}
@anthonybrown
anthonybrown / App.js
Created Sep 3, 2019
React Cheat Sheet: --> Context, Refs, Memo, Lazy, Suspense
View App.js
// createContext
const WeatherContext = React.createContext({ day: 3 })
const App = ({ children }) => {
const [weather, setWeather] = React.useState(null)
const [error, setError] = React.useState(null)
React.useEffect(() => {
api.getWeather(...)
.then(setWeather)
.catch(setError)
}, [])
@anthonybrown
anthonybrown / bigArr.js
Created Sep 2, 2019
Shorter code isn't always better code.
View bigArr.js
const bigArr = new Array(1000000).fill(1).map((_, i) => i);
bigArr[100] = 5;
const allUnique = arr => {
const all = new Set();
for (let el of arr) {
if (all.has(el)) {
return false;
}
@anthonybrown
anthonybrown / learn-curry.js
Last active Aug 30, 2019
example of using curried functions
View learn-curry.js
/** Store Data */
const prices = {
game: 59.95,
nintendo: 399.99,
controller: 49.99,
xbox: 299.99,
ps1: 349.99
}
const basket = [
@anthonybrown
anthonybrown / curried.js
Last active Aug 30, 2019
A simple example of currying in functional JavaScript
View curried.js
function greetCurried(greeting) {
return function(name) {
if (typeof(greeting) !== 'string') {
return ('Greetings!')
} else if (typeof(name) !== 'string') {
return (greeting)
}
return (`${greeting}, ${name}`)
}
@anthonybrown
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
You can’t perform that action at this time.