Skip to content

Instantly share code, notes, and snippets.

View blakehaswell's full-sized avatar

Blake Haswell blakehaswell

View GitHub Profile
@blakehaswell
blakehaswell / copy-team-icons.js
Created January 20, 2014 05:34
Little Node script which gets a list of teams from a CSV file, then copies and renames icons for those teams.
var q = require('q');
var copy = q.denodeify(require('fs-extra').copy);
var exists = require('fs-extra').existsSync;
var csv = require('csv');
var reduce = require('underscore').reduce;
function getTeams() {
var deferred = q.defer();
var teams = [];
csv()
@blakehaswell
blakehaswell / getUniqueModelsFromCollections.js
Created November 29, 2013 03:33
Returns the unique models from any Backbone collections passed in. Just some fun with functional programming.
var _ = require('underscore');
module.exports = function () {
var collectionArray = _.toArray(arguments);
return _.reduce(collectionArray, function (memo, collection) {
return memo.concat(collection.reject(function (model) {
return _.contains(_.pluck(memo, 'id'), model.id);
}));
}, []);
};
@blakehaswell
blakehaswell / css-search.html
Created February 28, 2013 10:32
Sexy Search Box in CSS
<!doctype html>
<html>
<head>
<title>Search Box in CSS</title>
<style>
body {
background-color: #eee;
margin: 0;
@blakehaswell
blakehaswell / Gruntfine.js
Created January 25, 2013 05:32
Gruntfile with my JSHint config.
module.exports = function (grunt) {
grunt.initConfig({
jshint: {
all: {
src: 'public/javascripts/app/*.js',
options: {
bitwise: true,
camelcase: true,
@blakehaswell
blakehaswell / _calculatePercentage.scss
Created January 24, 2013 09:10
Fluid grid system for Sass.
@function calculatePercentage($numerator, $denominator) {
@return ($numerator / $denominator) * 100%;
}
@blakehaswell
blakehaswell / Gruntfile.js
Created January 21, 2013 10:05
Gruntfile for running automated tests using Jasmine.
module.exports = function (grunt) {
grunt.initConfig({
connect: {
jasmine: {
options: {
hostname: 'localhost',
port: 9001
}
}
@blakehaswell
blakehaswell / example-test.js
Created September 11, 2012 04:36
Jasmine Test Suite Abstraction
TestSuite.add({
name: "List transformer",
getHtml: function () {
var html = [];
html.push("<ul class=\"unorderedList\">");
html.push("<li>A list item</li>");
html.push("<li>A second list item</li>");
@blakehaswell
blakehaswell / shrink-wrap-text.jquery.js
Created August 21, 2012 04:17
jQuery plugin to shrink text if the container is too small. Useful for buttons, text inputs, etc.
(function (window, undefined) {
"use strict";
var $ = window.jQuery;
$.fn.shrinkWrapText = function () {
return this.each(function () {
var $el = $(this);
var sw = new ShrinkWrapper($el);
@blakehaswell
blakehaswell / dedupCoffee.js
Created June 27, 2012 12:09
Deduplicate coffees code
var beverage = {
"SB" : "Short black",
"LB" : "Long black",
"Cap" : "Cappuccino",
"FW" : "Flat white"
};
var milk = {
"reg" : "Regular",
"soy" : "Soy milk",
@blakehaswell
blakehaswell / dropdown.js
Created April 19, 2012 23:14
Vanilla JS Dropdown
/**
* Given a list of items, adds and removes an active class as you hover over
* them. Used to create a dropdown menu.
*
* Copyright (c) 2012 Blake Haswell
* Licensed under the MIT license: http://opensource.org/licenses/MIT
*
* Example:
* var items = document.getElementById("dropdown").children;
* new Dropdown(items);