This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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})], | |
]; |
This file contains hidden or 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
start.server <- function(host = "localhost", port = 8000, request.handler) { | |
max.request.length <- 100 * 1024 * 1024 # 100 MB request size | |
repeat { | |
socket <- make.socket(host, port, server = TRUE) | |
on.exit(close.socket(socket)) | |
request <- parse.request(read.socket(socket, maxlen = max.request.length)) | |
response <- request.handler(request) | |
write.socket(socket, response) | |
close.socket(socket) | |
} |
This file contains hidden or 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(global) { | |
global.axis = { | |
axisLeft: axisLeft, | |
axisBottom: axisBottom, | |
}; | |
function axisLeft(canvas, config) { | |
let font = config.font || systemFont; | |
let { xOffset, yOffset, scale, tickValues, tickSize } = config; | |
tickSize = tickSize || 6; |
This file contains hidden or 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> | |
<!-- React/ReactDOM --> | |
<script src="https://cdn.jsdelivr.net/combine/npm/[email protected]/umd/react.production.min.js,npm/[email protected]/umd/react-dom.production.min.js"></script> | |
<!-- Redux/Redux Thunk/React Redux --> | |
<script src="https://cdn.jsdelivr.net/combine/npm/[email protected]/dist/redux.min.js,npm/[email protected]/dist/redux-thunk.min.js,npm/[email protected]/dist/react-redux.min.js"></script> | |
<link rel="stylesheet" href="styles.css"> |
This file contains hidden or 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> | |
<div id="root">Loading...</div> | |
<script nomodule src="https://cdn.jsdelivr.net/combine/npm/[email protected]/dist/polyfill.min.js,npm/[email protected]"></script> |
This file contains hidden or 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 Promise-based wrapper for the http/https.request function | |
* @param {string|URL} url - Strings are parsed as URL objects | |
* @param {Object} opts - A set of options for http.request - includes `body` | |
* @example let response = await request('http://jsonplaceholder.typicode.com/posts/1') | |
*/ | |
function request(url, opts) { | |
return new Promise((resolve, reject) => { | |
if (!(url instanceof URL)) { |
This file contains hidden or 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" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<title>Hacker News</title> | |
<style> | |
body { | |
background-color: white; |