Skip to content

Instantly share code, notes, and snippets.

@park-brian
park-brian / server.R
Last active October 17, 2019 15:40
A minimal R application server
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)
}
@park-brian
park-brian / axis.js
Last active August 23, 2019 21:56
Canvas Manhattan Plot
(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;
@park-brian
park-brian / index.html
Last active August 23, 2019 19:14
React Redux ES5 - TodoMVC
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<!-- React/ReactDOM -->
<script src="https://cdn.jsdelivr.net/combine/npm/react@16.8.6/umd/react.production.min.js,npm/react-dom@16.8.6/umd/react-dom.production.min.js"></script>
<!-- Redux/Redux Thunk/React Redux -->
<script src="https://cdn.jsdelivr.net/combine/npm/redux@4.0.4/dist/redux.min.js,npm/redux-thunk@2.3.0/dist/redux-thunk.min.js,npm/react-redux@7.1.0/dist/react-redux.min.js"></script>
<link rel="stylesheet" href="styles.css">
@park-brian
park-brian / index.html
Created July 17, 2019 00:31
Simple HashRouter
<!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/babel-polyfill@6.26.0/dist/polyfill.min.js,npm/whatwg-fetch@3.0.0"></script>
@park-brian
park-brian / request.js
Last active May 5, 2021 19:07
Promise-based wrapper for space-constrained Node.js applications (aws lambda, gc functions, etc)
/**
* 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)) {
<!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;
@park-brian
park-brian / AdvancedWindowSnap.ahk
Last active February 6, 2024 21:53 — forked from AWMooreCO/AdvancedWindowSnap.ahk
Advanced Window Snap is a script for AutoHotKey that expands upon Windows built-in window-snapping hotkeys.
/**
* Advanced Window Snap
* Snaps the active window to a position within a user-defined grid.
*
* @author Andrew Moore <andrew+github@awmoore.com>
* @contributor jballi
* @contributor park-brian
* @contributor shinywong
* @version 1.2
*/
@park-brian
park-brian / native-font-preview.js
Last active November 8, 2018 06:23
Native Font Preview Bookmarklet (highlight code and drag into bookmarks bar)
javascript: var s = document.createElement('style'); s.innerHTML = '* { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important; }'; document.body.append(s);
@park-brian
park-brian / onIdle.js
Last active August 8, 2018 20:25
onIdle.js
/**
* Calls a function after a user has been idle for a specified period of time
* @param callback {Function} - The function to call
* @param delay {number} - The delay (in milliseconds)
*/
function onIdle(callback, delay) {
var timeoutId;
var events = ["click", "mousedown", "mouseup", "focus", "blur", "keydown", "change", "mouseup", "click", "dblclick", "mousemove", "mouseover", "mouseout", "mousewheel", "keydown", "keyup", "keypress", "textInput", "touchstart", "touchmove", "touchend", "touchcancel", "resize", "scroll", "zoom", "focus", "blur", "select", "change", "submit", "reset"];
function initTimeout() {
@park-brian
park-brian / usage.md
Last active November 8, 2018 17:24
Runs a function in a web worker

Make sure the Content Security Policy allows access to scripts that have been created on the same origin (eg: this will not work in the gists developer console since script-src is set to assets-cdn.github.com)

function sum(arr) {
    return arr.reduce(function(a, b) { return a + b; });
}

var sumWorker = workerFn(sum);

// generate input

for(var input = []; input.length < 1000; input.push(input.length));