Skip to content

Instantly share code, notes, and snippets.

@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 June 2, 2025 18:33 — 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 <[email protected]>
* @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));

importScripts(
"https://unpkg.com/[email protected]/dist/polyfill.min.js",
"https://unpkg.com/[email protected]/bundles/rxjs.umd.min.js",
"https://unpkg.com/[email protected]/dist/zone.min.js",
"https://unpkg.com/@angular/[email protected]/bundles/core.umd.min.js",
"https://unpkg.com/@angular/[email protected]/bundles/common.umd.min.js",
"https://unpkg.com/@angular/[email protected]/bundles/compiler.umd.min.js",
"https://unpkg.com/@angular/[email protected]/bundles/platform-browser.umd.min.js",
"https://unpkg.com/@angular/[email protected]/bundles/platform-webworker.umd.min.js",
"https://unpkg.com/@angular/[email protected]/bundles/platform-browser-dynamic.umd.min.js",
@park-brian
park-brian / README.md
Last active August 23, 2018 16:31
Angular 6 Prerendering

Add these files!

<h1>{{ title }}</h1>
<button (click)="updateMessage()">
Click me!
</button>
<p *ngFor="let line of message">
{{ line }}
</p>
@park-brian
park-brian / createFormObject.ts
Created June 19, 2018 17:39
Recursive FormBuilder which returns an AbstractControl
import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms';
/**
* Creates a nested FormGroup, FormArray, or FormControl with validators
* from a given object
*/
export const createFormObject = (initial: any): AbstractControl => {
if (Array.isArray(initial)) {
// detemine if array contains ValidatorFn or ValidatorFn[]
// eg: use same syntax as formBuilder