Skip to content

Instantly share code, notes, and snippets.

💭
Just coding

Kyle Simpson getify

💭
Just coding
View GitHub Profile
@getify
getify / gist:1b26accb1a09aa53ad25
Last active Aug 5, 2020
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 / INFO.md
Last active Jul 27, 2020
AutoHotKeys (AHK) script for cycling active focus between a selected ("recorded") set of open windows
View INFO.md

Download Icon: https://jumpshare.com/v/T5yuKIP3Zc6Rr29GH5ye

How To Use

  1. While focused on an open window (like a browser or editor), hit the "record" hotkey (default: win+ctrl+shift+?) to add an app to the focus cycle list. Tooltips will pop up notifying you of recorded apps, or if there's an issue recording.

  2. To cycle forward through recorded apps, use the "cycle forward" hotkey (default: win+ctrl+shift+>), or click the system-tray icon, or click the menu Item "Cycle Apps" menu item.

  3. To cycle backward, use the "cycle backward" hotkey (default: win+ctrl+shift+<).

@getify
getify / 1.js
Last active Jul 27, 2020
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 / monads-and-friends.md
Created Jul 16, 2020
Monads and Friends...
View monads-and-friends.md

Monads and Friends...

Over the last 24-48 hours, I've fielded quite a flurry of tweets related to a couple of threads I posted recently. Upon reflection on the feedback, especially the negative stuff, I decided to write this blog post to clarify a few things about my background on the topic, what I was trying to say, what I've done so far, and what I'm hoping to do (and learn!) in the future.

It's a bit of a lengthy read, but if you find you've got the time, I hope you'll read it.

To be clear, the feedback has been on a broad spectrum. A lot of it was actually quite positive, people thanking me and appreciating my continued efforts to try to make dev topics approachable. As a matter of fact, over the years, I've received boat loads of such positive feedback, and I'm tremendously grateful that I've had a helpful impact on so many lives.

But some of it veered decidedly the other direction. I'm deliberately not linking to it, because I don't want to either amplify or gang up on those folks. I'm offended an

@getify
getify / gist:7325764
Last active Jul 21, 2020
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 sandbox.js
function sandboxJS(js) {
var whitelist = ["alert","console","navigator","location"];
var handlers = {
has(target,key,context) {
if (whitelist.indexOf(key) >= 0) {
return Reflect.has(
target, key, context
);
}
else {
@getify
getify / gist:5226305
Last active Jul 21, 2020
playing around with an `Object.make()` helper
View gist:5226305
// `Object.make(..)` is a helper/wrapper for `Object.create(..)`. Both create a new
// object, and optionally link that new object's `[[Prototype]]` chain to another object.
//
// But `Object.make(..)` makes sure the new object always has a `__proto__` property
// (even a null one) and delegation to a `isPrototypeOf(..)` method, both of which are
// missing from the bare object (aka "Dictionary") created by `Object.create(null)`.
//
// `isPrototypeOf()` is put on a extra object that your created object can delegate to,
// if any only if you create an empty object (by not passing a `linkTo`) that otherwise
// wouldn't have access to `isPrototypeOf()`.
@getify
getify / ex1-prototype-style.js
Last active Jul 21, 2020
OLOO (objects linked to other objects) pattern explored (with comparison to the prototype style of the same code)
View ex1-prototype-style.js
function Foo(who) {
this.me = who;
}
Foo.prototype.identify = function() {
return "I am " + this.me;
};
function Bar(who) {
Foo.call(this,"Bar:" + who);
@getify
getify / gist:3667624
Created Sep 7, 2012
escape all double-quote chars in a string
View gist:3667624
// NOTE: only escapes a " if it's not already escaped
function escapeDoubleQuotes(str) {
return str.replace(/\\([\s\S])|(")/g,"\\$1$2"); // thanks @slevithan!
}
escapeDoubleQuotes("ab"); // ab => ab
escapeDoubleQuotes("a\"b"); // a"b => a\"b
escapeDoubleQuotes("a\\\"b"); // a\"b => a\"b
escapeDoubleQuotes("a\\\\\"b"); // a\\"b => a\\\"b
escapeDoubleQuotes("a\\\\\\\"b"); // a\\\"b => a\\\"b
@getify
getify / 1.js
Last active Jul 17, 2020
is Maybe a "monad?
View 1.js
// is Just(..) a monad? Well, it's a monad constructor.
// Its instances are certainly monads.
function Just(v) {
return { map, chain, ap };
function map(fn) {
return Just(fn(v));
}
function chain(fn) {
return fn(v);
}
You can’t perform that action at this time.