Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Brownsmith brownsmith

  • Camberley, Surrey
View GitHub Profile
@brownsmith
brownsmith / reduxNotes.js
Last active Mar 18, 2020
Redux action types, actions and action creators
View reduxNotes.js
// action type
const orderCardType = 'ORDER_CARD';
// action
const orderCardAction = () => ({
type: orderCardType,
});
// action creator
const orderCardActionCreator = () => dispatch => {
View .zshrc
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/paulbrownsmith/.oh-my-zsh"
SPACESHIP_PROMPT_ORDER=(
battery # Battery level and status
dir # Current directory section
git # Git section (git_branch + git_status)
View promises.js
function hello(resolve) {
// do whatever
resolve();
}
function hello2(resolve) {
// do whatever
resolve();
}
@brownsmith
brownsmith / blatdocker.sh
Created May 31, 2018
Delete all docker images
View blatdocker.sh
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
@brownsmith
brownsmith / super.js
Last active May 30, 2018
Use of super in React Class constructor
View super.js
// 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 / amp.js
Created May 29, 2018
Classes and composition
View amp.js
// ##### CLASS INHERITANCE:
class GuitarAmp {
constructor ({ cabinet = 'spruce', distortion = '1', volume = '0' } = {}) {
Object.assign(this, {
cabinet, distortion, volume
});
}
}
class BassAmp extends GuitarAmp {
View closure.js
function bookSlotByCustId(customerId) {
const custId = customerId
return function bookSlot(slotId) {
//psuedo code here:
dispatch({
apiCall: api.bookSlot(custId, slotId)
});
}
}
@brownsmith
brownsmith / sort.js
Last active May 9, 2018
Array sorting - returning products in price order
View sort.js
const products = [
{
price: '123',
name: 'cproduct1'
},
{
price: '50',
name: 'bproduct1'
},
{
View prefs.js
{
"workbench.colorTheme": "One Dark+ (Sublime)",
"eslint.autoFixOnSave": true,
"terminal.integrated.shell.osx": "zsh",
"editor.tabSize": 2,
}
@brownsmith
brownsmith / decorator.js
Created May 3, 2018
HOC, decorating functions
View decorator.js
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;