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
function sleep(ms) { | |
return new Promise((resolve) => setTimeout(resolve, ms)); | |
} | |
async function insertDynamoDBItems(documentClient, tableName, items) { | |
if (!items.length) return; | |
let responses = []; | |
let response = await documentClient | |
.batchWrite({ |
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>GistRun</title> | |
<link rel="stylesheet" href="styles.css"> | |
</head> | |
<body> | |
<h1>PLCO QQ Plot</h1> | |
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
/** | |
* A parser which handles any rfc4180 compliant csv file | |
* Configuration takes the following properties | |
* delimiter: specifies the field delimiter (default: ",") | |
* escape: specifies the escape character (default: ") | |
* skipLines: specifies the number of lines to skip (default: 0) | |
* transformRow: transform sthe default ouput from an array of strings to your custom format (eg: an array of objects) | |
* transformValue: transforms individual values (eg: for custom typecasting logic) | |
*/ |
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>GistRun</title> | |
<link rel="stylesheet" href="styles.css"> | |
</head> | |
<body> | |
<input id="height" placeholder="Height"> | |
<input id="width" placeholder="Width"> |
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>GistRun</title> | |
<link rel="stylesheet" href="styles.css"> | |
</head> | |
<body> | |
<input id="height" placeholder="Height"> | |
<input id="width" placeholder="Width"> |
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
/** | |
* A simple quadtree for rapidly fetching spatial data | |
* @param {number} xMin | |
* @param {number} xMax | |
* @param {number} yMin | |
* @param {number} yMax | |
*/ | |
function QuadTree(xMin, xMax, yMin, yMax) { | |
// swap xMin/xMax and yMin/yMax if needed | |
if (xMin > xMax) [xMin, xMax] = [xMax, xMin]; |
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
data:text/html,<body oninput="document.querySelector('iframe').srcdoc=h.value+'<style>'+c.value+'</style><script>'+j.value+'</script>'"><style>textarea,iframe{box-sizing:border-box;float:right;width:100%;height:50%;border:1px solid steelblue;}body{margin:0}textarea{width:33.33%;font-size:18;resize:none;}</style><textarea placeholder=JS id=j></textarea><textarea placeholder=CSS id=c></textarea><textarea placeholder=HTML id=h></textarea><iframe> |
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
function validate(object, rules) { | |
return Object.entries(object).reduce((errors, [key, value]) => { | |
let validators = rules[key]; | |
if (!validators || validators.length === 0) | |
return errors; | |
if (typeof validators === 'function') | |
validators = [validators]; |
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
/** | |
* Sometimes, we need a plain es5 function to chain execution of promises (eg: when | |
* targeting older browsers using polyfills, while eschewing a build step). This function | |
* takes an array of promises or functions which return promises, and applies the supplied | |
* callback function against each promise sequentially, waiting for resolution before | |
* executing/resolving the next promise. | |
* | |
* Promises always resolve in their order of appearance. However, this function only | |
* defers execution of promises if functions which return promises are provided (eg: | |
* using .bind to create bound functions). |
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
/* | |
Routing consists of matching a string against a set of regular expressions to call a function. | |
In this case, we can define routes as an array of regular expressions and callbacks. | |
For example: | |
let routes = [ | |
[/^\/user\/(\d+)\/?$/, (id) => response({id})], | |
[/^\/user\/([a-z0-9-_]+)\/?$/, (name) => response({name})], | |
[/^\/user\/([a-z0-9-_]+)\/(\d+)\/?$/, (name, id) => response({id, name})], | |
]; |
NewerOlder