Skip to content

Instantly share code, notes, and snippets.

View jussi-kalliokoski's full-sized avatar

Jussi Kalliokoski jussi-kalliokoski

View GitHub Profile
@jussi-kalliokoski
jussi-kalliokoski / modulo.js
Created May 9, 2011 06:24
A faster replacement for modulo in most cases, use when applicable and while the JS engines haven't optimized the native.
function modulo(dividend, divisor){
while (dividend >= divisor){
dividend -= divisor;
}
return dividend;
}
/*
A shim for non ES5 supporting browsers.
Adds function bind to Function prototype, so that you can do partial application.
Works even with the nasty thing, where the first word is the opposite of extranet, the second one is the profession of Columbus, and the version number is 9, flipped 180 degrees.
*/
Function.prototype.bind = Function.prototype.bind || function(to){
// Make an array of our arguments, starting from second argument
var partial = Array.prototype.splice.call(arguments, 1),
// We'll need the original function.
@jussi-kalliokoski
jussi-kalliokoski / sleep.js
Created July 15, 2011 14:24
Small sleep function for JavaScript
/**
* Does nothing (useful) for a specified time.
*
* @param {Uint} The time to sleep, in milliseconds.
*/
function sleep(t){var m=+new Date+t;while(+new Date<m);}
// Please note that this is a pattern that is hardly useful, never advisable and a bit intensive.
@jussi-kalliokoski
jussi-kalliokoski / LICENSE.txt
Created July 15, 2011 14:56 — forked from 140bytes/LICENSE.txt
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@jussi-kalliokoski
jussi-kalliokoski / jasdijasdij.js
Created August 15, 2011 14:18
the embarrassing
str = "asas";
int = (str.charCodeAt(0) << 24) + (str.charCodeAt(1) << 16) + (str.charCodeAt(2) << 8) + str.charCodeAt(3);
@jussi-kalliokoski
jussi-kalliokoski / silence.js
Created October 6, 2011 11:47
Methods for creating an audio tag filled with a specified time of silence.
(function(g){
var urlPath =
window.URL ? 'URL' :
window.webkitURL ? 'webkitURL' :
window.mozURL ? 'mozURL' :
window.msURL ? 'msURL' :
window.oURL ? 'oURL' : '';
var blobPath =
@jussi-kalliokoski
jussi-kalliokoski / silence.js
Created October 6, 2011 11:47
Methods for creating an audio tag filled with a specified time of silence.
(function(g){
/*var URL =
window.URL ||
window.webkitURL ||
window.mozURL ||
window.msURL ||
window.oURL;
var BlobBuilder =
@jussi-kalliokoski
jussi-kalliokoski / inline-worker.html
Created December 4, 2011 19:34
A small library to get Workers from Data/Blob URIs where supported
<!DOCTYPE html>
<html>
<head>
<script src="inline-worker.js"></script>
</script>
</head>
<body>
<div id="log"></div>
<script>
inlineWorker.onready(function(){
@jussi-kalliokoski
jussi-kalliokoski / setImmediate.js
Created January 22, 2012 14:48
A small shim for the setImmediate() that creates a callback similar to process.nextTick() on node.js
(function (global, prefixes, timeouts, id, i) {
if (typeof process !== 'undefined' && process && process.nextTick) {
global.setImmediate = function (callback, args) {
var i = id;
timeouts[id] = {
c: callback,
a: args || [],
};
@jussi-kalliokoski
jussi-kalliokoski / number-math.js
Created January 25, 2012 19:30
Extend Number.prototype with Math functions
(function (define, names) {
if (!define || !names.forEach) return;
names.forEach(function (name) {
define(Number.prototype, name, {
value: function () {
return Math[name].apply(
Math,
[this].concat([].slice.call(arguments))