Skip to content

Instantly share code, notes, and snippets.

Focusing on React

Tom chefThomas

Focusing on React
Block or report user

Report or block chefThomas

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
chefThomas /
Last active Jan 22, 2020
Heroku quick ref

View latest logs

heroku logs --tail

Run Heroku

heroku open
heroku local web

Propagate local changes to remote


Testing Reference

Unit Testing

Integration Test Initialization Example - Express MongoDb Mongoose Supertest


note: URIs for mongodb in .env file accessed using dotenv package


chefThomas / errorHandler.js
Last active Sep 6, 2019
Express error handler example
View errorHandler.js
const errorHandler = (error, request, response, next) => {
if ( === 'CastError' && error.kind === 'ObjectId') {
return response.status(400).send({ error: 'malformatted id' })
chefThomas / sass.json
Last active Jul 21, 2019
working sass watch compile
View sass.json
// in package.json where src/ also located in project root and directory follows
"scripts" : {
"sass": "node-sass --watch src/stylesheets/scss/ -o src/stylesheets/css"
View proxy_simple.js
function createPetProxy(subject) {
return {
// enhanced method
makeNoise: function () {
console.log(`${subject.species} ${} says '${subject.makeNoise()}'`);
// delegated method
eat: function() {}
chefThomas /
Last active Mar 1, 2019
design patterns

Design Patterns

Design patterns are reusable solutions to specific types of problems that continually arise when developing software. These solutions have been captured as design patterns.



Reference The Module Pattern creates a bubble of private scope using an IIFE (immediately-invoked function expression) and closure to ensure data is not mutated. It is also useful for organizing code functionally (encapsulation).

Modules return an anonymous object containing key-values where value calls functions declared in body of IIFE.

chefThomas / solution.js
Last active Feb 3, 2019
count array elements... without using length prop, plus more fun stuff
View solution.js
function getLength(arr, count=0) {
const iter = arr[Symbol.iterator]();
const { done } =;
if(done) {
return count;
else {
chefThomas / solution.js
Created Jan 22, 2019
reverse words in a string leetcode
View solution.js
* @param {string} s
* @return {string}
var reverseWords = function(s) {
return s
.split(' ')
chefThomas / solution1.js
Last active Jan 19, 2019
unique email addresses
View solution1.js
// tired brain
var numUniqueEmails = function(emails) {
let uniqueEmails = [];
for(email of emails){
let filtered = '';
let atIndex = email.indexOf("@");
let plusIndex = email.indexOf("+");
let name = email.substring(email[0], atIndex);
let domain = email.substring(atIndex, email.length);
chefThomas / solution.js
Last active Jan 23, 2019
Calculate total points
View solution.js
// scores: array with game scores as string element eg ["3:1", "2:2", "0:1"]. See link for details
const totalChampionshipPoints = scores => {
return (
.map(score => score.split(':'))
.map(score => {
if(parseInt(score[0]) > parseInt(score[1])) return 3;
if(parseInt(score[0]) === parseInt(score[1])) return 1;
You can’t perform that action at this time.