Skip to content

Instantly share code, notes, and snippets.

View taybenlor's full-sized avatar

Ben Taylor taybenlor

View GitHub Profile
@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
$("#somelink").on("click", function(){
$("#somediv").show();
$("#anotherdiv").hide():
$("#athirddiv").hide();
});
int maxlen = max(a.length, b.length, c.length);
for(int i = 0; i < maxlen; i++){
int ai = max(a.length - i, 0);
int bi = max(b.length - i, 0);
int ci = max(c.length - i, 0);
//dostuff
}