Skip to content

Instantly share code, notes, and snippets.

💭
Just coding

Kyle Simpson getify

💭
Just coding
Block or report user

Report or block getify

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@getify
getify / gist:1b26accb1a09aa53ad25
Last active Sep 16, 2019
first draft sketch of a "Worker" polyfill
View gist:1b26accb1a09aa53ad25
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Worker Polyfill</title>
<script src="polyfill.worker.js"></script>
</head>
<body>
<h1>Worker Polyfill</h1>
<script>
@getify
getify / 1.js
Last active Sep 15, 2019
quick sketch of CAF
View 1.js
btn.addEventListener("send-btn",onSend);
send = CAF(send);
var prevSend = Promise.resolve();
function onSend(evt) {
prevSend.finally(function f(){
prevSend = send(
CAF.timeout(1000,"send took too long."),
{ some: "data" }
)
@getify
getify / 1.js
Last active Sep 13, 2019
microtask queue got me singin' the blues
View 1.js
// VERSION 1 -- broken
async function *main() {
yield ready;
}
var resolve1;
var resolve2;
var ready = new Promise(function c(res){
resolve1 = res;
@getify
getify / number-prototype-iterator.js
Created Jan 25, 2017
Make JavaScript Great Again
View number-prototype-iterator.js
Object.defineProperty(Number.prototype,Symbol.iterator,{
*value({ start = 0, step = 1 } = {}) {
var inc = this > 0 ? step : -step;
for (let i = start; Math.abs(i) <= Math.abs(this); i += inc) {
yield i;
}
},
enumerable: false,
writable: true,
configurable: true
@getify
getify / gist:2926699
Created Jun 13, 2012
non-rectangular (line and circle) clears in canvas
View gist:2926699
/*
To see a demo of these in use, check out: http://test.getify.com/test-canvas-clear-alt.html
Example uses:
*/
clearCircle(context,/*x=*/120,/*y=*/80,/*radius=*/60);
clearLineSquared(context,/*x1=*/10,/*y1=*/10,/*x2=*/53,/*y2=*/67,/*thickness=*/5);
clearLineRounded(context,/*x1=*/15,/*y1=*/100,/*x2=*/90,/*y2=*/170,/*thickness=*/10);
View 1.js
// NOTE: To see this demo: https://codepen.io/getify/pen/LYPbmYG?editors=0012
var counter = 1;
function printMessage() {
console.log(`message ${counter++}`);
}
var schedule = Scheduler(/* debounceMinimum = */50,/* throttleMaximum = */500);
@getify
getify / gist:7325764
Last active Aug 23, 2019
converting between Uint8Arrays and binary-encoded strings and word-arrays (for crypto purposes, with CryptoJS and NaCL)
View gist:7325764
/*
wordArray: { words: [..], sigBytes: words.length * 4 }
*/
// assumes wordArray is Big-Endian (because it comes from CryptoJS which is all BE)
// From: https://gist.github.com/creationix/07856504cf4d5cede5f9#file-encode-js
function convertWordArrayToUint8Array(wordArray) {
var len = wordArray.words.length,
u8_array = new Uint8Array(len << 2),
offset = 0, word, i
View pi-hex-digits.js
// This is a port of the C-language reference implementation, which can be
// found here: http://www.experimentalmath.info/bbp-codes/piqpr8.c
/*
This program implements the BBP algorithm to generate a few hexadecimal
digits beginning immediately after a given position id, or in other words
beginning at position id + 1. On most systems using IEEE 64-bit floating-
point arithmetic, this code works correctly so long as d is less than
approximately 1.18 x 10^7. If 80-bit arithmetic can be employed, this limit
@getify
getify / 1.js
Last active Jul 23, 2019
creating hard-bound methods on classes
View 1.js
class Foo {
constructor(x) { this.foo = x; }
hello() { console.log(this.foo); }
}
class Bar extends Foo {
constructor(x) { super(x); this.bar = x * 100; }
world() { console.log(this.bar); }
}
@getify
getify / gist:701970
Created Nov 16, 2010
how to use jQuery.noConflict() to manage multiple versions of jQuery on same page
View gist:701970
<html>
<head>
<script src="jquery-1.3.3"></script>
<script>var $jq133 = jQuery.noConflict(true);</script>
<!-- other stuff -->
<script src="jquery-1.4"></script>
<script>var $jq14 = jQuery.noConflict(true);</script>
You can’t perform that action at this time.