Skip to content

Instantly share code, notes, and snippets.

View fuzzyfox's full-sized avatar

William Duyck fuzzyfox

View GitHub Profile
@fuzzyfox
fuzzyfox / Array.remove.js
Last active December 19, 2015 15:59
JavaScript: Array remove
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove || Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
@fuzzyfox
fuzzyfox / Array.cycle.js
Last active December 19, 2015 15:59
JavaScript: Array cycle
// Remove first element, place it at the end.
// Returns the first element before move.
Array.prototype.cycle || Array.prototype.cycle = function(){
var rtn = this.shift();
this.push(rtn);
return rtn;
};
@fuzzyfox
fuzzyfox / Array.shuffle.js
Last active December 19, 2015 17:19
JavaScript: Array shuffle
// Does an inplace shuffle of an array in O(n) time. Uses the Fisher-Yates Shuffle.
Array.prototype.shuffle || Array.prototype.shuffle = function(){
for(var j, x, i = this.length; i; j = parseInt(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
};
@fuzzyfox
fuzzyfox / TowTruck.bookmarklet.js
Created September 11, 2013 10:06
JavaScript: Mozilla TowTruck bookmarklet
(function(window,document,undefined){var script=document.createElement('script');script.setAttribute('src','https://towtruck.mozillalabs.com/towtruck.js');document.body.appendChild(script);setTimeout(function(){try{window.TowTruck(window);}catch(e){alert('Failed to load TowTruck');}},400);})(this,this.document);
@fuzzyfox
fuzzyfox / EventTarget.addEventListener.js
Created September 30, 2013 10:59
JavaScript: EventTarget.addEventListener shim
// target.addEventListener shim, hat tip [mdn](http://mzl.la/18ELrGJ)
(function() {
if (!Event.prototype.preventDefault) {
Event.prototype.preventDefault=function() {
this.returnValue=false;
};
}
if (!Event.prototype.stopPropagation) {
Event.prototype.stopPropagation=function() {
this.cancelBubble=true;
@fuzzyfox
fuzzyfox / image2dataurl.html
Created October 14, 2013 11:00
JavaScript: image to dataurl converter similar to http://daturi.me/ but clientside conversion
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Image 2 DataURL</title>
<style>
#images {
width: 420px;
margin: auto;
@fuzzyfox
fuzzyfox / jsdiff.js
Created October 15, 2013 16:13 — forked from mbijon/jsdiff.js
JavaScript: Diff Algorithm
/*
* Javascript Diff Algorithm
* By John Resig (http://ejohn.org/)
* Modified by Chu Alan "sprite"
*
* Released under the MIT license.
*
* More Info:
* http://ejohn.org/projects/javascript-diff-algorithm/
*/
@fuzzyfox
fuzzyfox / location.query.js
Created October 16, 2013 09:22
JavaScript: querystring to json object
// utility function to parse/use query strings
window.query = document.query = (function(window, document, undefined){
var pairs = window.location.search.slice(1).split('&'),
result = {};
pairs.forEach(function(pair){
pair = pair.split('=');
result[pair[0]] = decodeURIComponent(pair[1] || '');
});
@fuzzyfox
fuzzyfox / app.js
Created November 13, 2013 12:40
Very crude method of extracting data from the Mozilla Festival schedule. Moved to <http://github.com/fuzzyfox/firehug-numbers>
var request = require('request');
var data = {
saturday: {
total_sessions: 0
},
sunday: {
total_sessions: 0
},
format: {},
@fuzzyfox
fuzzyfox / enable-markdown-kit.js
Last active December 13, 2016 11:07
Make: Teaching Kits created with markdown
// turning the markdown feature into a one line include for kits.
// wicked closure pattern w/ hat tip to Paul Irish [source](https://gist.github.com/paulirish/315916)
(function(window, document, undefined){
// check if Showdown is loaded already or not... if not, then load it
// once we have Showdown run the converter
if(!window.Showdown){
var script = document.createElement('script');
script.src = '//cdnjs.cloudflare.com/ajax/libs/showdown/0.3.1/showdown.min.js';
script.onload = extendAndConvert;