Skip to content

Instantly share code, notes, and snippets.

Array.prototype.splice.call(document.querySelectorAll("h2,h3,h4,h5,h6"), 0).
map(function (el, n) {
var txt, id;
id = el.getAttribute("id");
txt = el.innerText;
if (!id) {
el.setAttribute("id", encodeURIComponent(txt));
}
@nikcorg
nikcorg / gist:5308870
Created April 4, 2013 08:54
Security Engineering — The Book
# Available here: http://www.cl.cam.ac.uk/~rja14/book.html
# Easy download using curl
curl -O http://www.cl.cam.ac.uk/~rja14/Papers/SEv2-c[01-27].pdf
curl -O http://www.cl.cam.ac.uk/~rja14/Papers/SEv2-{ack,index,toc,pref,acks,biblio}.pdf
@nikcorg
nikcorg / plot.html
Created April 5, 2013 08:02
Plotting a formula, just for fun.
<!doctype html>
<html>
<head>
<title>Plot</title>
<script type="text/javascript">
// Looking at this formula, just for fun
// http://en.wikipedia.org/wiki/Logistic_map
var R = Math.PI / 2;
var Rmax = 4;
@nikcorg
nikcorg / ts-fp-kbdnav.js
Last active December 15, 2015 22:49
Keyboard navigation for Fingerpori @ Turun Sanomat using (jQuery) promises
// Keyboard navigation for http://ts.fi/viihde/fingerpori/
(function ($) {
"use strict";
if (!$) {
console.error("jQuery is missing");
return;
}
var KEYS = {
var a = Q.delay(100).thenResolve("a is done");
var b = Q.delay(110).thenResolve("b is done");
var c = Q.delay(120).thenResolve("c is doen");
Q.all([a, b, c]).spread(function (a, b, c) { console.log("all", a, b, c); });
a.then(function (a) { console.log("a only", a); });
@nikcorg
nikcorg / setimmedate.js
Created July 9, 2013 16:49
A naive and simple experiment at setImmediate/clearImmediate polyfilling
(function (global, rand) {
var prefix = "setImmediate-";
var counter = 0;
var tasks = {};
global.setImmediate = function (cb, params) {
var id = prefix + counter++ + rand();
tasks[id] = {
fn: cb, p: params || []
};
@nikcorg
nikcorg / orders-sort.js
Created July 25, 2013 12:55
Sorting the order history table on david silver spares' website. Custom map/reduce/forEach function because browser natives were overwritten. Just an exercise for fun.
function forEach(a, fn) {
var i;
for (i in a) {
if (a.hasOwnProperty(i)) {
fn.call(null, a[i], i, a);
}
}
}
function map(a, fn) {
@nikcorg
nikcorg / fast_track-1.js
Last active December 22, 2015 05:49
My solution to the problem at http://reaktor.fi/ura/fast_track/
function (input) {
return [].reduce.call(input, function (mem, n, i) {
return mem[i % 5] = n, mem.push(Math.max(mem.pop(), eval(mem.join("*")))), mem;
}, [0, 0, 0, 0, 0, 0]).pop();
}
#!/bin/sh
#
# simulate_3g.sh - Simulate a sluggish 3G network with delays & packet loss
# Usage: simulate_3g.sh 8080 8081
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
@nikcorg
nikcorg / hyphenate.js
Last active October 18, 2016 19:08
Finnish hyphenation a la Haiku-editori
// Paraphrased from http://teppo.tv/haikueditori/haikueditori.js
var rVowels = /[aeiouyåäö]/i;
var rConsonants = /[bcdfghjklmnpqrstvwxz]/i;
var rDiphthongs = /(aa|ee|ii|oo|uu|yy|åå|ää|öö|ai|ei|oi|ui|yi|åi|äi|öi|au|eu|iu|ou|äy|öy|ie|uo|yö|ey|iy)/i;
function isVowel(chr) {
return rVowels.test(chr);
}