Skip to content

Instantly share code, notes, and snippets.

View smks's full-sized avatar

Shaun Stone smks

View GitHub Profile
@smks
smks / people.js
Created December 2, 2018 12:57
Reducer for people.js
import { getPeople } from '../actions';
const INITIAL_STATE = {
hasLoadedPeople: false,
errorGettingPeople: false,
list: [],
};
const people = (state = INITIAL_STATE, { type, payload }) => {
switch (type) {
@smks
smks / index.js
Created December 2, 2018 12:53
Redux routines example
import { createRoutine } from 'redux-saga-routines';
export const GET_PEOPLE = 'GET_PEOPLE';
export const getPeople = createRoutine(GET_PEOPLE);
@smks
smks / index.js
Created December 2, 2018 12:42
PeopleList index.js
import { connect } from 'react-redux';
import PeopleList, { mapStateToProps, mapDispatchToProps } from './PeopleList';
export default connect(
mapStateToProps,
mapDispatchToProps,
)(PeopleList);
@smks
smks / PeopleList.js
Last active December 2, 2018 13:06
Render a list of people
import React, { Component } from 'react';
import Loading from 'react-loading';
import {
shape, arrayOf, string, func, bool, number,
} from 'prop-types';
import './PeopleList.css';
import Panel from '../Panel';
import { getPeople } from '../../actions';
@smks
smks / App.js
Created August 19, 2018 19:55
Example of using moment.js to find difference in days
import moment from 'moment';
// Last day of tax year: 5th April 2018
const lastDayOfTaxYear = moment([2018, 4, 5]);
// My birthday: 18th September 2018
const myBirthday = moment([2018, 9, 18]);
const daysDiff = myBirthday.diff(lastDayOfTaxYear, 'days');
@smks
smks / App.js
Created August 19, 2018 19:53
Demonstrates using date-fns to compare days differences
import differenceInDays from 'date-fns/difference_in_days'
// Last day of tax year: 5th April 2018
const lastDayOfTaxYear = new Date(2018, 4, 5, 0, 0);
// My birthday: 18th September 2018
const myBirthday = new Date(2018, 9, 18, 0, 0);
const daysDiff = differenceInDays(myBirthday, lastDayOfTaxYear);
@smks
smks / npm link
Created March 2, 2018 20:07
Extract of package.json
@smks
smks / mason.js
Last active June 10, 2020 18:30
This is a sample commander CLI application used in Medium Article - How I automated my Job with Node JS
#! /usr/bin/env node
const mason = require('commander');
const { version } = require('./package.json');
const console = require('console');
// commands
const create = require('./commands/create');
const setup = require('./commands/setup');
const batman = {firstName: 'Bruce', lastName: 'Wayne'};
const superman = {firstName: 'Clark', lastName: 'Kent'};
function speak(quote, location) {
console.log(this);
console.log(this.firstName + ' ' + this.lastName + ' ' + 'says ' + quote + ' from ' + location);
};
// Apply for Array
speak.apply(batman, ["'It's not who I am underneath, but what I do that defines me'", "Gotham City"]);
@smks
smks / bind.js
Created November 13, 2016 13:00
Demonstration of how bind() works in JavaScript
/**
*
* Incorrect Context
*
*/
class Greeter {
constructor(name) {
this.name = name;
}