Skip to content

Instantly share code, notes, and snippets.

View furf's full-sized avatar
🎯
Focusing

Dave Furfero furf

🎯
Focusing
View GitHub Profile
@furf
furf / LICENSE.txt
Last active August 29, 2015 13:59 — forked from 140bytes/LICENSE.txt
140byt.es Fuzzy Search - Search a string for one or more terms using fuzzy-matching.
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
@furf
furf / color-sort.js
Last active August 29, 2015 13:59
Compare sort speeds using inline and pre-computed distance calculations.
// Return a color object
function color(r, g, b) {
return {
r: r,
g: g,
b: b
};
}
// Return a random number between a and b inclusive
@furf
furf / search-and-replace-1.js
Last active August 29, 2015 14:00
Fuzzy search and replace multiple terms in a string.
function replace(phrase, query) {
return phrase.replace( // SEARCH the phrase...
RegExp('(' + // using a REGULAR EXPRESSION to capture...
query // all matches in the QUERY.
.trim() // Trim whitespace to PREVENT "EMPTY" WORDS when the query is...
.split(/\s+/) // split into DISCREET SEARCHABLE "WORDS" (non-whitespace terms),...
.sort(function(a,b) { // SORTED by...
return b.length - a.length; // descending length to PREVENT LOSS OF MATCHES previously replaced by shorter matches.
}).map(function(word) { // To capture non-word characters like PERIODS, HYPHENS, and APOSTROPHES,
return word.split('') // BETWEEN EACH CHARACTER of the word
@furf
furf / array-to-range.js
Last active August 29, 2015 14:01
convert an array to a range, sorta.
// https://twitter.com/angustweets/status/467117418511212544
var a = [1,2,3,4,5];
a.map(Date.call, Number); // [0, 1, 2, 3, 4]
var b = []; b.length = 5;
b.map(Date.call, Number); // [undefined × 5]
var c = [,,,,,]
c.map(Date.call, Number); // [undefined × 5]
@furf
furf / findLongSelectors.js
Last active August 29, 2015 14:04
Find CSS selectors greater than n
function findLongSelectors(n) {
var sheets = document.styleSheets;
var splitRule = /\s*,\s*/;
var splitWhitespace = /\s+/;
var longRules = [];
[].forEach.call(document.styleSheets, function(styleSheet) {
if (!styleSheet.cssRules) return;
[].forEach.call(styleSheet.cssRules, function(cssRule) {
@furf
furf / jsdoc-tdd.js
Created July 25, 2014 20:54
Wouldn't it be nice...
/**
* Adds two numbers.
* @param {Number} a First addend.
* @param {Number} b Second addend.
* @return {Number} The sum of the addends.
* @when a is 1 and b is 2
* @expect 3
*/
function addition(a, b) {
return a + b;
@furf
furf / cardFactory.html
Last active August 29, 2015 14:11
Prototypal factory
<!DOCTYPE html>
<html>
<head>
<title>CardFactory</title>
</head>
<body>
<script src="http://code.jquery.com/jquery.js"></script>
<script>
;(function(window, document, $) {
@furf
furf / fizzbuzz-precompute.js
Last active August 29, 2015 14:15
fizzbuzz
function fizzbuzz(n, s, i) {
s = {
0: 'FizzBuzz',
3: 'Fizz',
5: 'Buzz',
6: 'Fizz',
9: 'Fizz',
10: 'Buzz',
12: 'Fizz'
};
@furf
furf / base.js
Created March 12, 2015 16:11
Yet another prototypal inheritance scheme.
/**
* Base inheritable/mixable object with `create` and `mixin` functionality.
* @type {Object}
*/
var Base = {
/**
* Create a new instance of the object and mixin additional behaviors.
@furf
furf / sample.styl
Created March 12, 2015 17:40
stylus wins.
@import '_common'
/**
* Clock animation
*/
@keyframes alarm
from
transform rotate(-10deg)
to