Skip to content

Instantly share code, notes, and snippets.

@tmcgann
tmcgann / .prettierrc
Created September 16, 2020 16:19
Preferred Prettier config
{
"arrowParens": "avoid",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"printWidth": 100,
"proseWrap": "preserve",
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
@tmcgann
tmcgann / async-serial-reduction.js
Created July 6, 2020 21:54
Two different ways to process asynchronous requests serially without the use of convenient library like async (https://caolan.github.io/async/v3/docs.html#eachSeries).
(async function () {
// Setup
const values = [1, 2, 3]
const makeTimestamp = () => Math.round(Date.now() / 1000)
const request = (value, time = 1000) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(value)
}, time)

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.

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 * 

Query Proposal

Pagination

Offset

Possible keys:

  • offset: Int
  • limit: Int
@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.

@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 / 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 / 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 / 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);