Skip to content

Instantly share code, notes, and snippets.

@nason
nason / machine.js
Last active March 16, 2020 15:40
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
async function handleInsert(record) {}
async function handleUpdate(record) {}
async function handleRemove(record) {}
async function receiveHandler(event, context, callback) {
const results = await Promise.all(
event.Records.map(record => {
console.log(JSON.stringify(record));
switch (record.eventName) {
case 'INSERT':
@nason
nason / SketchSystems.spec
Last active June 22, 2018 19:20
Checkout App
Checkout App
Inactive*
activate -> Init
Init
fetch estimate -> Configure and Review
fetch error -> Error
Configure and Review

Keybase proof

I hereby claim:

  • I am nason on github.
  • I am nason (https://keybase.io/nason) on keybase.
  • I have a public key ASDr3hnnWlYnBwVXpmXtdoPn5yi6X_JsbZg2hUvuDmW6wgo

To claim this, I am signing this object:

@nason
nason / optimumStockPrices.js
Last active December 30, 2015 15:58
Given a list of integers representing stock prices by day, return the optimum buy and sell points to maximize profit. (You can only make one buy and one sell.) Your function should take a list as input and return the two indexes of the buy and sell points.
var optimumPoints = function(input) {
var min = input.reduce(getMin),
max = input.reduce(getMax),
minIndex = input.indexOf(min),
maxIndex = input.lastIndexOf(max);
if (minIndex > maxIndex) {
// Can't sell before we buy, try again
var copy = input.slice();
// This time, delete the current min to calculate the second lowest min
@nason
nason / doubleAnagram.js
Last active December 30, 2015 15:49
Find two words in a text that are anagrams of another two words in that text. Works in all browsers (IE >= 9)
var doubleAnagram = function(string) {
// parse the input string & generate pairs
var words = parseInput(string).map(buildDoubles),
result = false;
for (var i = 0; i<words.length; i++) {
for (var j = i+1; j<words.length; j++) {
// iterate through the words structure, and compare the current to all subsequent
result = checkForAnagram(words[i], words[j]);
if (result) {
@nason
nason / avgStudentsPerSection.js
Last active December 30, 2015 10:09
Quick calculation of average students per section in API dummy data.
var request = require('request');
var options = {
uri: 'https://api.com/v1.1/sections',
qs: {
limit: 1000000000000000
},
auth: {
'user': 'DEMO_KEY'
}
};