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;
@stoyan
stoyan / topx.js
Created September 14, 2022 20:30
top chrome extensions
// data from https://github.com/DebugBear/chrome-extension-list
const data = require('./extensions-2021.json');
const topx = {};
data.forEach(x => {
if (x.installs !== "10,000,000+") {
Object.keys(topx).sort().forEach(key => {
console.log(topx[key]);
})
process.exit();
}
let i = document.querySelector('input.waterfall-transparency');
let up = true;
i.value = parseFloat(i.min);
i.dispatchEvent(new Event('change'));
function animate() {
const curr = parseFloat(i.value);
const max = parseFloat(i.max);
const min = parseFloat(i.min);
const step = parseFloat(i.step);
i.value = up ? curr + step : curr - step;
<IfModule mod_rewrite.c>
# BEGIN Force http to https
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [R=301,L]
# END Force http to https
</IfModule>
<IfModule mod_rewrite.c>
@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 / jsdaybr.js
Created December 12, 2020 20:40
Slides from JSDay Brazil 2020
React State Management
JSDay🇧🇷 Recife 2020
@stoyanstefanov
phpied.com
@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')
$$('[aria-label="Not interested"]').forEach(b => b.click())
@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');
<script>
document.getElementById('wrapper').addEventListener('click', function(event) {
var checkbox = event.target.querySelector('input[type=checkbox]');
if (checkbox) {
checkbox.checked = !checkbox.checked;
}
}, true);
</script>