Skip to content

Instantly share code, notes, and snippets.

View fuzzyfox's full-sized avatar

William Duyck fuzzyfox

View GitHub Profile
@fuzzyfox
fuzzyfox / cookiemonster.js
Created September 2, 2010 18:36
JavaScript: JSON flavoured cookies
/*
This is a cookiemonster... it is a cookie control that uses JSON to store
information and make it easy to use.
*/
var cookiemonster = {};
/**
* This function creates the cookie.
*
@fuzzyfox
fuzzyfox / LICENSE
Last active November 28, 2022 19:53
Average Colour of Background
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <[email protected]>
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
@fuzzyfox
fuzzyfox / preg_replace.js
Created June 22, 2013 18:21
JavaScript: preg_replace
/**
* preg_replace (from PHP) in JavaScript!
*
* This is basically a pattern replace. You can use a regex pattern to search and
* another for the replace. For more information see the PHP docs on the original
* function (http://php.net/manual/en/function.preg-replace.php), and for more on
* JavaScript flavour regex visit http://www.regular-expressions.info/javascript.html
*
* NOTE: Unlike the PHP version, this function only deals with string inputs. No arrays.
*
@fuzzyfox
fuzzyfox / markdown.js
Created June 22, 2013 23:57
JavaScript: Simple Markdown Parser
/* jshint browser: true, devel: true */
/**
* preg_replace (from PHP) in JavaScript!
*
* This is basically a pattern replace. You can use a regex pattern to search and
* another for the replace. For more information see the PHP docs on the original
* function (http://php.net/manual/en/function.preg-replace.php), and for more on
* JavaScript flavour regex visit http://www.regular-expressions.info/javascript.html
*
@fuzzyfox
fuzzyfox / data-markdown.user.js
Created June 23, 2013 00:45 — forked from paulirish/data-markdown.user.js
JavaScript: [data-markdown]
// ==UserScript==
// @name Use Markdown, sometimes, in your HTML.
// @author Paul Irish <http://paulirish.com/>
// @link http://git.io/data-markdown
// @match *
// ==/UserScript==
// If you're not using this as a userscript just delete from this line up. It's cool, homey.
@fuzzyfox
fuzzyfox / gist:5843307
Last active December 18, 2015 20:49
JavaScript: wicked closure pattern
// wicked closure pattern w/ hat tip to Paul Irish [source](https://gist.github.com/paulirish/315916)
(function(window, document, undefined){
})(this, this.document);
@fuzzyfox
fuzzyfox / average-color.js
Last active August 31, 2020 17:33
JavaScript: image average color
var getAverageColor = (function(window, document, undefined){
return function(imageURL, options}){
options = {
// image split into blocks of x pixels wide, 1 high
blocksize: options.blocksize || 5,
fallbackColor: options.fallbackColor || '#000'
};
var img = document.createElement('img'),
canvas = document.createElement('canvas'),
@fuzzyfox
fuzzyfox / getQueryVariable.js
Last active December 19, 2015 15:39
JavaScript: getQueryVariable
var getQueryVariable = function(variable, queryString){
queryString = queryString || window.location.search;
var query = queryString.substr(1),
vars = query.split('&'),
pairs;
for(var i = 0, j = vars.length; i < j; i++){
pairs = vars[i].split('=');
@fuzzyfox
fuzzyfox / dominant-color.js
Created July 11, 2013 17:49 — forked from leibovic/dominant-color.js
JavaScript: Dominant Color
function getDominantColor(aImg) {
let canvas = document.createElement("canvas");
canvas.height = aImg.height;
canvas.width = aImg.width;
let context = canvas.getContext("2d");
context.drawImage(aImg, 0, 0);
// keep track of how many times a color appears in the image
let colorCount = {};
@fuzzyfox
fuzzyfox / pubsub.jquery.js
Last active December 19, 2015 15:58
JavaScript: Sexy PubSub
// Works in modern browsers + IE9, but Modernizr has a polyfill baked in for function.bind.
// Hat tip Paul Irish
var o = $( {} );
$.subscribe = o.on.bind(o);
$.unsubscribe = o.off.bind(o);
$.publish = o.trigger.bind(o);