Skip to content

Instantly share code, notes, and snippets.

View brownsmith's full-sized avatar

Paul Brownsmith brownsmith

  • Camberley, Surrey
View GitHub Profile
@brownsmith
brownsmith / decorator.js
Created May 3, 2018 08:45
HOC, decorating functions
function doSomething(name) {
console.log('hello ' + name);
}
function loggingDecorator(wrappedFunction) {
return function() {
console.log('starting');
const result = wrappedFunction.apply(this, arguments);
console.log('finished');
return result;
@brownsmith
brownsmith / console.js
Created April 12, 2018 15:36
Viewing entire object shape in console.warn
console.log(JSON.stringify(objName, null, 2));
https://medium.com/stephenkoo/how-to-set-up-create-react-app-redux-react-router-redux-thunk-prettier-scss-airbnb-eslint-dda0bba5616a
@brownsmith
brownsmith / selector.js
Created March 2, 2018 10:41
Redux selectors
export const selectorName = state => {
return ...
}
@brownsmith
brownsmith / keypress.js
Last active February 16, 2018 10:43
Nokia old style phone, key press array
const keyArray = [
['1'],
['A', 'B', 'C', '2'],
['D', 'E', 'F', '3'],
['G', 'H', 'I', '4'],
['J', 'K', 'L', '5'],
['M', 'N', 'O', '6'],
['P', 'Q', 'R', 'S', '7'],
['T', 'U', 'V', '8'],
['W', 'X', 'Y', 'Z', '9'],
@brownsmith
brownsmith / pure.js
Created February 14, 2018 13:21
Little note on pure functions
// A function is only pure if, given the same input, it will always produce the same output.
const highpass = (cutoff, value) => value >= cutoff;
highpass(5, 123); // true
highpass(5, 6); // true
highpass(5, 18); // true
highpass(5, 5); // true
highpass(5, 1); // false
highpass(5, 3); // false
highpass(5, 4); // false
@brownsmith
brownsmith / Descending.js
Created February 1, 2018 09:51
Sort random numbers into descending order
function descendingOrder(n){
return parseInt(String(n).split('').sort().reverse().join(''))
}
@brownsmith
brownsmith / codekata.js
Created January 30, 2018 15:21
Friend or Foe Code Kata solution
function friend(friends){
return friends.filter(n => n.length === 4)
}
@brownsmith
brownsmith / App.js
Last active October 10, 2017 13:27
Passing children about in JSX
getMain = (children) => {
return (
<Switch>
<Route path={pathJoin(this.baseUrl, '/path/one')}>
<main className={styles.something}>
{children}
</main>
</Route>
<Route path={pathJoin(this.baseUrl, '/path/two')}>
<main className={styles.somethingElse}>
@brownsmith
brownsmith / arrow.js
Last active March 2, 2018 10:23
Arrow functions example
// ES5
var multiply = function(a, b) {
return a * b;
};
// ES6
var multiply = (a, b) => { return a * b };
// even neater
var multiply = (a, b) => a * b;