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 / data.json
Created Jul 5, 2013
Example of how to use JSON.minify() to pre-process your JSON strings and remove comments (and whitespace) before parsing.
View data.json
/* this is an example of how to use
whitespace and comments in your JSON
but still have it parseable */
{
"name": "JSON.minify()",
"type": "javascript" // values: "javascript", "js"
}
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 {
View gist:2b53198906d320abe650
function foo(x) { x = (typeof x != "undefined") ? x : 10; .. }
function foo(x = 10) { .. }
function foo(x,y,z) { .. }; foo.apply(null,[1,2,3]);
function foo(x,y,z) { .. }; foo(...[1,2,3]);
function foo() { var args = [].slice.call(arguments); .. }
function foo(...args) { .. }
var o = { x: 2, y: 3 }, x = o.x, y = o.y, z = (typeof o.z != "undefined") ? o.z : 10;
@getify
getify / ex1.js
Last active Oct 13, 2019
class vs OLOO
View ex1.js
class Foo {
constructor(x,y,z) {
Object.assign(this,{ x, y, z });
}
hello() {
console.log(this.x + this.y + this.z);
}
}
@getify
getify / ex1-prototype-style.js
Last active Oct 13, 2019
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 / 1.js
Last active Sep 27, 2019
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);
}
@getify
getify / gist:5226305
Last active Sep 21, 2019
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 / 1.js
Last active Sep 19, 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 / 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 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;
You can’t perform that action at this time.