Skip to content

Instantly share code, notes, and snippets.

@tmcgann
tmcgann / promisePlayground.js
Created October 24, 2016 21:45
Playing with some promise logic
function make(timeout=3000) {
const TIMEOUT = timeout;
let promise = null;
let data1 = {
currentCommunity: {
name: 'Dwelo',
},
currentUser: {
name: 'taylor',
@tmcgann
tmcgann / fizzbuzz.js
Created October 27, 2016 20:21
Iterative solutioning to classic FizzBuzz problem with goal of elegance (minimal state, branching, etc.)
// Inspired by: https://klipse.ghost.io/the-most-elegant-implementation-of-fizzbuzz/
// I read the first couple paragraphs of the post and before looking at the solution, I started working on the FizzBuss problem as stated in the article. I've copied it here for convenience:
//
// Write a program that prints the numbers from 1 to 100.
// But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”.
// For numbers which are multiples of both three and five print “FizzBuzz”.
// What follows is my iterative solutioning before viewing the solution:
// const numbers = Array.from(Array(100), (value, index) => index + 1);
@tmcgann
tmcgann / timeBetweenMoment.js
Last active December 7, 2016 22:58
Get the time between two dates. MomentJS required.
// Requires momentjs lib
function timeBetween(earlier, later) {
return humanize(getDiffInMilliseconds(earlier, later));
}
function getDiffInMilliseconds(earlier, later) {
const DATE_STRING_FORMAT = 'YYYY/MM/DD HH:mm:ss';
const earlierDate = moment(earlier, DATE_STRING_FORMAT);
const laterDate = moment(later, DATE_STRING_FORMAT);
@tmcgann
tmcgann / timeBetween.js
Created December 7, 2016 23:06
Get the time between two dates. No external libraries required.
function timeBetween(earlier, later) {
return humanize(getDiffInMilliseconds(earlier, later));
}
function getDiffInMilliseconds(earlier, later) {
const earlierDate = new Date(earlier);
const laterDate = new Date(later);
return (laterDate - earlierDate);
}
@tmcgann
tmcgann / funny-git-cli-typos.md
Last active July 11, 2019 17:08
Funny Git CLI Typos
Typo Command Intended Command
git ass git add
git stash poop git stash pop
@tmcgann
tmcgann / heavenly-shaved-ice-extras.md
Last active August 6, 2019 15:06
Heavenly Shaved Ice Extras

Heavenly Shaved Ice Extras

Data

JavaScript:

const flavors = [
  { id: 1, name: "Tiger's Blood" },
  { id: 2, name: 'Piña Colada' },
@tmcgann
tmcgann / heavenly-shaved-ice.md
Last active August 19, 2019 20:14
A code challenge designed for a mid-level software engineer

Heavenly Shaved Ice

Problem

You own and operate an automated shaved ice shack called Heavenly Shaved Ice. When a customer picks a menu item the system needs to look up the recipe to fulfill the customer's order.

Code Challenge

Design a program that will yield the correct recipe (i.e. ingredient names and quantities) when given a specific recipe by name.

Query Proposal

Pagination

Offset

Possible keys:

  • offset: Int
  • limit: Int

Background

We need to choose an API design for the JSON payload that developers will use to query datasets. We have two competing proposals. Both work just as well. Your objective is to solve the challenge below and then pick the API you think is better and explain why (or recommend a better one).

Challenge

Given the following SQL statement...

select * 

Challenge Results

Wesley

Preference: API A

When writing them, I initially thought I would like API B better because most everything was an object with keys to specify the value. But after looking at them more, I like API A. I like that the arrays indicate values that need to be evaluated, while the objects represent pieces that need to be constructed.

no i wouldnt want a pure array implementation, i like that the arrays and objects mean different things which makes it easy to parse quickly. creating B was as easy as A, maybe because i did A first and knew the pattern at that point. B feels like a lot of overhead, having everything be an object. with proper documentation i dont think that type of verboseness is needed.