Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View brownsmith's full-sized avatar

Paul Brownsmith brownsmith

  • Camberley, Surrey
View GitHub Profile
https://medium.com/stephenkoo/how-to-set-up-create-react-app-redux-react-router-redux-thunk-prettier-scss-airbnb-eslint-dda0bba5616a
@brownsmith
brownsmith / console.js
Created April 12, 2018 15:36
Viewing entire object shape in console.warn
console.log(JSON.stringify(objName, null, 2));
@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 / prefs.js
Created May 3, 2018 09:49
VSCode prefs
{
"workbench.colorTheme": "One Dark+ (Sublime)",
"eslint.autoFixOnSave": true,
"terminal.integrated.shell.osx": "zsh",
"editor.tabSize": 2,
}
@brownsmith
brownsmith / sort.js
Last active May 9, 2018 09:15
Array sorting - returning products in price order
const products = [
{
price: '123',
name: 'cproduct1'
},
{
price: '50',
name: 'bproduct1'
},
{
@brownsmith
brownsmith / closure.js
Created May 17, 2018 15:37
Closure notes
function bookSlotByCustId(customerId) {
const custId = customerId
return function bookSlot(slotId) {
//psuedo code here:
dispatch({
apiCall: api.bookSlot(custId, slotId)
});
}
}
@brownsmith
brownsmith / amp.js
Created May 29, 2018 07:28
Classes and composition
// ##### CLASS INHERITANCE:
class GuitarAmp {
constructor ({ cabinet = 'spruce', distortion = '1', volume = '0' } = {}) {
Object.assign(this, {
cabinet, distortion, volume
});
}
}
class BassAmp extends GuitarAmp {
@brownsmith
brownsmith / super.js
Last active May 30, 2018 13:39
Use of super in React Class constructor
// ES6 class constructors MUST call super if they are subclasses.
// Thus, you have to call super() if you have a constructor.
// A subclass does not have to have a constructor (see #1)
// #1 no need to call super() here as there is no constructor
class MyClass extends React.Component {
render(){
return <div>Hello { this.props.world }</div>;
}
}
@brownsmith
brownsmith / blatdocker.sh
Created May 31, 2018 10:10
Delete all docker images
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
@brownsmith
brownsmith / promises.js
Created March 19, 2019 15:16
Promise stuff
function hello(resolve) {
// do whatever
resolve();
}
function hello2(resolve) {
// do whatever
resolve();
}