Skip to content

Instantly share code, notes, and snippets.

View fuzzyfox's full-sized avatar

William Duyck fuzzyfox

View GitHub Profile
@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 / 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 <sam@hocevar.net>
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 / 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 / removeTrailingWhiltespace.php
Created September 22, 2020 19:09
Remove trailing whitespace from an input string (multiline).
function removeTrailingWhitespace(string $string) : string
{
return preg_replace('/[ \t]+(\r?)$/m', '$1', $string);
}
// PHPUnit testcase for method
// public function testTestInternalRemoveTrailingWhitespace()
// {
// $this->assertSame(
// "\n some\r\n string\n\n\r\nto remove trailing\n whitespace from.\n\n",
@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 / _tooltip.scss
Created May 26, 2017 18:24
Super Simple, Tiny, SCSS tooltips.
$spacer: 1rem;
$tooltip-border-radius: ( 0.333 * $spacer );
[data-tooltip] {
position: relative;
&::before,
&::after {
opacity: 0;
pointer-events: none;
@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;
@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 / 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 / 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/
*/