Skip to content

Instantly share code, notes, and snippets.

View jed's full-sized avatar

Jed Schmidt jed

View GitHub Profile
@jed
jed / iterator.js
Last active January 21, 2021 01:56
Turning callbacks into async iterators, with a React hook-like API.
// Example usage:
//
// void async function() {
// let [clicks, onclick] = iterator()
// document.querySelector('button').addEventListener('click', onclick)
// for await (let click of clicks) console.log(click)
// }()
export default function iterator() {
let done = false
@jed
jed / tee.js
Last active November 24, 2020 17:59
Teeing an asynchronous iterator
function tee(asyncIterable) {
let source = asyncIterable[Symbol.asyncIterator]()
return [[], []].map((buffer, i, buffers) => ({
async next() {
if (0 in buffer) return buffer.shift()
let item = await source.next()
if (!item.done) buffers[1 - i].push(item)
@jed
jed / LICENSE.txt
Created May 15, 2011 15:57 — forked from 140bytes/LICENSE.txt
generate a random ID
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@jed
jed / LICENSE.txt
Created May 10, 2011 23:27 — forked from 140bytes/LICENSE.txt
calculate # of ms/seconds/minutes/hours/days in the past
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@jed
jed / LICENSE.txt
Created June 24, 2011 10:20 — forked from 140bytes/LICENSE.txt
Array.prototype.unique
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@jed
jed / LICENSE.txt
Created May 10, 2011 16:04 — forked from 140bytes/LICENSE.txt
write contextual templates
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@jed
jed / LICENSE.txt
Created May 10, 2011 16:06 — forked from 140bytes/LICENSE.txt
walk and filter DOM nodes by function
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@jed
jed / LICENSE.txt
Created May 26, 2011 17:39 — forked from 140bytes/LICENSE.txt
get a supported XHR instance
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@jed
jed / base64.js
Created November 19, 2009 23:26
a base64 adaptation for use with node.js
/* adapted by Jed Schmidt for use as a node.js module */
this.encode = base64encode;
this.decode = base64decode;
this.chars = function( string ) {
base64EncodeChars = string || "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
base64DecodeChars = [];
for ( var i = 128; i--; ) {
if ( base64DecodeChars[ i ] === undefined )
@jed
jed / LICENSE.txt
Created November 28, 2011 15:47 — forked from 140bytes/LICENSE.txt
turn the `new` keyword into a function
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE