Skip to content

Instantly share code, notes, and snippets.

View jfsiii's full-sized avatar

John Schulz jfsiii

View GitHub Profile
@jfsiii
jfsiii / ts-repl.mjs
Created July 12, 2026 21:36
Augment the native NodeJS REPL to support TypeScript
// A tiny, dependency-free TypeScript REPL for Node.
//
// node ts-repl.mjs
//
// Needs Node 22.13+ (24 recommended). No install, no ts-node, no build — it
// augments Node's OWN `repl` instead of reimplementing one. We start the real
// REPL and override only `eval` to type-strip each entry (via Node's built-in
// `module.stripTypeScriptTypes`) before handing it to Node's default eval. That
// means the line editor, history, tab-completion, `_` last value, top-level
// await, multiline, and error display are all Node's, for free. We add three
@jfsiii
jfsiii / fetch-chunked.js
Last active April 24, 2026 13:43
Quick example of using fetch to parse a chunked response
var chunkedUrl = 'https://jigsaw.w3.org/HTTP/ChunkedScript';
fetch(chunkedUrl)
.then(processChunkedResponse)
.then(onChunkedResponseComplete)
.catch(onChunkedResponseError)
;
function onChunkedResponseComplete(result) {
console.log('all done!', result)
}
<!doctype html>
<body>
<script src="https://unpkg.com/lodash/lodash.min.js"></script>
<script src="https://unpkg.com/platform/platform.js"></script>
<script src="https://unpkg.com/benchmark/benchmark.js"></script>
<pre id="output"></pre>
<script>
function log(message) {
document.getElementById("output").innerHTML += message + '\n';
}
@jfsiii
jfsiii / request.js
Created September 17, 2012 19:26
Give a url, get back a base64-encoded data URI
/**
* Given an image URL, return a base64-encoded data URI.
* @param {String} url|uri|image The URL for the image to be converted.
* @param {String} [callback|cb] Name of the function you want to be called.
* @returns {Object} JSON
* @returns {String} JSON.data The data URI for the image
* @returns {Object} JSON.meta
* @returns {Number} JSON.meta.width The width of the image, in pixels.
* @returns {Number} JSON.meta.height The height of the image, in pixels.
* @returns {Object} JSON.http
@jfsiii
jfsiii / image2base64.js
Created September 6, 2012 01:12
Convert a remote image to Base64-encoded string
// Uses [request](https://github.com/mikeal/request)
// /?url=http://nodejs.org/logo.png
// /?uri=http://nodejs.org/logo.png
// /?url=http://nodejs.org/logo.png&cb=cbName
// /?url=http://nodejs.org/logo.png&callback=cbName
var fs = require('fs');
var url = require('url');
var http = require('http');
var request = require('request');
@jfsiii
jfsiii / index.html
Last active January 25, 2026 15:30
Full-Screen Layout using Flexbox
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Holy Grail</title>
<style>
/* some basic styles. nothing to do with flexbox */
header, footer,
nav, article, aside {
border: 1px solid black;
@jfsiii
jfsiii / image2canvas.js
Created October 16, 2010 22:06
previously canvasFromImage
var image2canvas = (function ( global, document, undefined )
{
// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
function parseUri (str)
{
var o = parseUri.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
@jfsiii
jfsiii / gist:814784
Created February 7, 2011 17:33 — forked from paulirish/gist:601751
get and set objects in localStorage and sessionStorage
// Forked from paul irish's https://gist.github.com/601751
// desire: localStorage and sessionStorage should accept objects
// in fact they do according to spec.
// http://code.google.com/p/chromium/issues/detail?id=43666
// but so far that part isnt implemented anywhere.
// so we duckpunch set/getItem() to stringify/parse on the way in/out
// this seems to work in chrome
@jfsiii
jfsiii / .block
Last active September 9, 2025 12:54
SVG colored patterns via masks/CSS without images
license: unlicense
@jfsiii
jfsiii / relativeLuminanceW3C.js
Last active February 25, 2025 12:35
Calculate the relative luminance, or brightness, of a color. Accepts values 0-255 for R, G, B.
// from http://www.w3.org/TR/WCAG20/#relativeluminancedef
function relativeLuminanceW3C(R8bit, G8bit, B8bit) {
var RsRGB = R8bit/255;
var GsRGB = G8bit/255;
var BsRGB = B8bit/255;
var R = (RsRGB <= 0.03928) ? RsRGB/12.92 : Math.pow((RsRGB+0.055)/1.055, 2.4);
var G = (GsRGB <= 0.03928) ? GsRGB/12.92 : Math.pow((GsRGB+0.055)/1.055, 2.4);
var B = (BsRGB <= 0.03928) ? BsRGB/12.92 : Math.pow((BsRGB+0.055)/1.055, 2.4);