Skip to content

Instantly share code, notes, and snippets.

View taybenlor's full-sized avatar

Ben Taylor taybenlor

View GitHub Profile
@taybenlor
taybenlor / colour.js
Created October 15, 2012 23:28
Colour Helpers in JS
/**
* A class to parse colour values. Updated by Ben to support colour conversions.
* @author Stoyan Stefanov <sstoo@gmail.com>
* @author Ben Taylor <taybenlor@gmail.com>
* @link http://www.phpied.com/rgb-color-parser-in-javascript/
* @license Use it if you like it
*/
function Colour(colour_string)
{
this.ok = false;
@taybenlor
taybenlor / gist:3684133
Created September 9, 2012 12:49
Heroku pros/cons

Pros

  • Very low effort to get running
  • Easily extensible to add very powerful features eg. I added memcache and caching to one of our apps and had it live within 30mins
  • Less downtime stress (if shit fails, you know heroku is dealing with it and you don't have to do much other than respond to customers)
  • Very little platform lockin (unlike Google App Engine)
  • Standing on shoulders of giants
  • Strong app segmentation = stability
  • Easy to price for clients
@taybenlor
taybenlor / gist:3486381
Created August 27, 2012 07:04
Top Aussie Designers on Dribbble
http://dribbble.com/jessedodds
http://dribbble.com/snootyfox
http://dribbble.com/bjango
http://dribbble.com/MelDraws
http://dribbble.com/zane_david
http://dribbble.com/charlessantoso
http://dribbble.com/envato
http://dribbble.com/tomricci
http://dribbble.com/VERG
http://dribbble.com/alanvanroemburg
@taybenlor
taybenlor / gist:3212275
Created July 31, 2012 00:30
Explaining this within JS
/*
* In JavaScript "this" is very finicky. Mostly it tends to get lost whenever
* you use a callback. When you assign a function you're literally creating
* a function object and then putting it into an object. Whenever the function
* is called it works out what it's this is based on how it was called.
*
* There are several ways to make sure your this stays around.
*
*/
var widths = $("elements").map(function(i, el){
$(el).width();
});
var max_width = Math.max.apply(Math, widths);
var widest_el = null;
var width = 0;
$("elements").each(function(i, el){
if(el.width() > width){
widest_el = el;
width = el.width();
}
});
var handler = function(event){
// if the target is a descendent of container do nothing
if($(event.target).is(".container, .container *")) return;
// remove event handler from document
$(document).off("click", handler);
// dostuff
}
@taybenlor
taybenlor / gist:2632667
Created May 8, 2012 04:48
Most Useful CoffeeScript function
window.System =
delay: (num, fn) ->
if arguments.length == 1
setTimeout(num, 0)
else
setTimeout(fn, num)
# Use Like #
System.delay ->
@taybenlor
taybenlor / person.py
Created April 2, 2012 03:43
Lynden likes python.
DEFAULT_NAME = File.open("default_name.txt").read()
class Person:
def __init__(self, name=None):
self.name = name or DEFAULT_NAME
@taybenlor
taybenlor / gist:2011217
Created March 10, 2012 11:45
Wong likes pie
def price
return @price if @price
@price = Money.new(self.cents || 0, self.some_relationship.currency || Money.default_currency)
end
def price=(new_price)
@price = new_price.to_money
self.cents = @price.cents
self.some_relationship.currency = @price.currency_as_string
end