Skip to content

Instantly share code, notes, and snippets.

var $;
YUI().use('*', function(Y){
$ = Y.get;
for(var p in Y) {
$[p] = Y[p];
}
});
// test
$('body').append("boo!");
@stoyan
stoyan / isNativeFunction.js
Created June 6, 2012 00:04
version of Andrea's
var isNativeFunction = function (f) {
try {
Function("return " + f.toString());
return false;
} catch (_) {
return true;
}
};
@stoyan
stoyan / gist:3801728
Created September 28, 2012 19:39
sync ie
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<pre id=r></pre>
<iframe></iframe>
<script>

Snow in canvas land

Other peoples' code is awful, and your own code from months previous counts as someone else's. With this and the festive spirit in mind, I dug up a canvas snow demo I made two years ago to see how bad my code really was.

How does it work?

Snowflake objects are created with a radius, opacity, y-velocity, and x-range (they drift from side to side). As they fall, they're drawn to a canvas, this canvas is cleared on every frame. When snowflakes land, they're drawn to another canvas, and the Snowflake is removed from the "active snowflakes" list. The second canvas is never cleared, snowflakes shapes are added as they land, meaning I don't have to redraw all the landed snowflakes per frame.

Two years of browser development later, what's wrong with it?

@stoyan
stoyan / clean.js
Created February 21, 2013 17:04
AsciiDoc unit test cleanup
var clean = require('fs').readFileSync('book.asc').toString().split('\n').filter(function(line) {
if (line.indexOf('/*nolint*/') === 0 ||
line.indexOf('/*global') === 0 ||
line.indexOf('/*jshint') === 0) {
return false;
}
return true;
})
.join('\n')
.replace(/--\+\+--/g, '--')
From b62bc38b72a6646cd4cb87a84355a7e8c2720e8f Mon Sep 17 00:00:00 2001
From: Stoyan <ssttoo@ymail.com>
Date: Wed, 18 Jan 2017 18:14:39 -0800
Subject: [PATCH] Exif tool based on FAIL
---
README.md | 6 +-----
manifest.json | 6 +++---
package.json | 5 +++--
public/exif-icon.png | Bin 0 -> 620 bytes
<script>
document.getElementById('wrapper').addEventListener('click', function(event) {
var checkbox = event.target.querySelector('input[type=checkbox]');
if (checkbox) {
checkbox.checked = !checkbox.checked;
}
}, true);
</script>
@stoyan
stoyan / html2ascii.js
Last active November 17, 2017 06:16
asciidoc for perfplanet book
// replacements
var t = $$('.entry')[0].innerHTML;
t = t.replace(/’/g, "'").replace(/“/g, '"').replace(/”/g, '"');
t = t.replace(/<li>/g, '<li>* ');
t = t.replace(/<\/ul>/g, '</ul><br>');
t = t.replace(/<code>/g, '`').replace(/<\/code>/g, '`');
t = t.replace(/<h2>/g, '<h2>=== ');
t = t.replace(/<h3>/g, '<h3>==== ');
t = t.replace(/<h4>/g, '<h4>===== ');
t = t.replace(/<pre/g, '[source,js]<br>----------------------------------------------------------------------<pre');
$$('[aria-label="Not interested"]').forEach(b => b.click())
@stoyan
stoyan / cleanup.js
Last active August 30, 2018 16:06
Script to lint and unit-test a JavaScript book written in AsciiDoc
// cleanup the extra markup to make it valid AsciiDoc
const clean = require('fs').readFileSync('2.primitive.asciidoc').toString().split('\n').filter(line => {
if (line.indexOf('/*nolint*/') === 0 ||
line.indexOf('/*global') === 0 ||
line.indexOf('/*jshint') === 0) {
return false;
}
return true;
})
.join('\n')