Skip to content

Instantly share code, notes, and snippets.

Stoyan stoyan

Block or report user

Report or block stoyan

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
@stoyan
stoyan / cleanup.js
Last active Aug 30, 2018
Script to lint and unit-test a JavaScript book written in AsciiDoc
View cleanup.js
// 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')
View notinterested.js
$$('[aria-label="Not interested"]').forEach(b => b.click())
View check.html
<script>
document.getElementById('wrapper').addEventListener('click', function(event) {
var checkbox = event.target.querySelector('input[type=checkbox]');
if (checkbox) {
checkbox.checked = !checkbox.checked;
}
}, true);
</script>
View exif.patch
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
@stoyan
stoyan / clean.js
Created Feb 21, 2013
AsciiDoc unit test cleanup
View clean.js
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, '--')
@stoyan
stoyan / test.js
Created Feb 12, 2013
AsciiDoc unit test
View test.js
// 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 / jsperf-bookmarklet.js
Last active Dec 12, 2015
bookmarklet to send a jsperf test to all webpagetest's IEs
View jsperf-bookmarklet.js
(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;
View gist:4339839

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?

View gist:3801728
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<pre id=r></pre>
<iframe></iframe>
<script>
View isNativeFunction.js
var isNativeFunction = function (f) {
try {
Function("return " + f.toString());
return false;
} catch (_) {
return true;
}
};
You can’t perform that action at this time.