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 / 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');
@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 / 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;
@stoyan
stoyan / test.js
Created February 12, 2013 05:47
AsciiDoc unit test
// dependencies where I can see them
var assert = require('assert');
var fs = require('fs');
var jslint = require('jshint').JSHINT;
// buncha vars
var snip, rawsnip, start = false, skipping = false, collecting = false;
var passed = 0, skipped = 0;
var lints = 0, nolints = 0;
@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 <[email protected]>
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>