Skip to content

Instantly share code, notes, and snippets.

@stoyan
stoyan / jsperf-bookmarklet.js
Last active April 29, 2023 14:58
bookmarklet to send a jsperf test to all webpagetest's IEs
(function(){
var key = localStorage.wpt_key;
if (!key) {
var prompt = window.__proto__.prompt;
key = prompt('Your WebPagetest API key, please?');
if (!key) {
return gameOver();
}
localStorage.wpt_key = key;

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 / 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>
@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 / 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');
var $;
YUI().use('*', function(Y){
$ = Y.get;
for(var p in Y) {
$[p] = Y[p];
}
});
// test
$('body').append("boo!");