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
chefThomas / heroku-ref.md
Last active Jan 22, 2020
Heroku quick ref
View heroku-ref.md

View latest logs

heroku logs --tail

Run Heroku

Remotely
heroku open
Locally
heroku local web

Propagate local changes to remote

View testingCheatSheet.md

Testing Reference

Unit Testing

Integration Test Initialization Example - Express MongoDb Mongoose Supertest

setup

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

package.json

{
@chefThomas
chefThomas / errorHandler.js
Last active Sep 6, 2019
Express error handler example
View errorHandler.js
const errorHandler = (error, request, response, next) => {
console.error(error.message)
if (error.name === 'CastError' && error.kind === 'ObjectId') {
return response.status(400).send({ error: 'malformatted id' })
}
next(error)
}
@chefThomas
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
// http://thesassway.com/beginner/how-to-structure-a-sass-project
"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} ${subject.name} says '${subject.makeNoise()}'`);
},
// delegated method
eat: function() {subject.eat()}
}
@chefThomas
chefThomas / index.md
Last active Mar 1, 2019
design patterns
View index.md

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.

Patterns

Module

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
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 } = iter.next();
if(done) {
return count;
}
else {
@chefThomas
chefThomas / solution.js
Created Jan 22, 2019
reverse words in a string leetcode
View solution.js
// https://leetcode.com/problems/reverse-words-in-a-string-iii/submissions/
/**
* @param {string} s
* @return {string}
*/
var reverseWords = function(s) {
return s
.split(' ')
@chefThomas
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
chefThomas / solution.js
Last active Jan 23, 2019
Calculate total points
View solution.js
// https://www.codewars.com/kata/total-amount-of-points
// scores: array with game scores as string element eg ["3:1", "2:2", "0:1"]. See link for details
const totalChampionshipPoints = scores => {
return (
scores
.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.