This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from "fs"; | |
import moment from "moment"; | |
const cache = new Map(); | |
function put(key, data) { | |
cache.set(key.toLowerCase(), { | |
expires: moment.utc().add(moment.duration(1, "h")), | |
value: data | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @flow */ | |
export function debounce(callback: () => mixed, timeout: number) { | |
let activeTimeout; | |
return function() { | |
if (activeTimeout) { | |
clearTimeout(activeTimeout); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getNestedValue(key, object) { | |
return key.split('.').reduce((previous, current) => { | |
return previous[current]; | |
}, object); | |
} | |
export function setNestedValue(key, value, object) { | |
const compound = key.split('.'); | |
return compound.reduce((previous, current, index) => { | |
if (index === compound.length - 1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWS.config.update({ | |
httpOptions: { | |
agent: process.env.HTTPS_PROXY | |
? require('proxy-agent')(process.env.HTTPS_PROXY) | |
: undefined, | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// task: count frequency of words in a string | |
// assumptions: | |
// - "words" are separated by spaces | |
// - input will always be a string, never undefined/null etc. | |
// - numbers and emoji are "words" | |
// - input will be latin script | |
// steps: | |
// - split input by ' ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
watch_for_interface() | |
{ | |
if (ifconfig "$1" | grep -q "status: active") | |
then | |
echo "[$1] state changed: active" | |
echo "...do stuff here..." | |
else | |
echo "[$1] state changed: inactive" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hosts = [ | |
{ | |
name: "z1d.12xlarge", | |
capacity: 48, | |
cost: 5.273, | |
}, | |
{ | |
name: "z1d.6xlarge", | |
capacity: 24, | |
cost: 2.636, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// quick and dirty reference for oauth flow in CLI apps | |
let server: http.Server; | |
const recievedCode = new Promise<string>((resolve, reject) => { | |
server = http.createServer((req, res) => { | |
const { pathname, searchParams } = new URL( | |
req.url, | |
"http://localhost:3000/" | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Type, Schema } from "js-yaml"; | |
const BigDecimal = new Type("!ruby/object:BigDecimal", { | |
kind: "scalar", | |
construct: (data) => { | |
return parseFloat(data.split(":")[1]); | |
}, | |
}); | |
const supportedTags = [BigDecimal]; |