This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you're using Structs within a Rails project (in particular), | |
# you might run into an error about "superclass mismatch for class". | |
# You can solve this quite simply. Rather than doing this: | |
class SimpleContact < Struct.new(:name, :role, :company) | |
def get_details | |
... | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var View = Backbone.View.extend({ | |
events : function() { | |
var events = {}; | |
var throttledAction = _.throttle(this.doSomeAction, 500); | |
events["click .someItem"] = function(event) { | |
throttledAction.call(this, event); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ { left : x, top : y }, width, height ] = [ | |
$el.offset(), $el.width(), $el.height() | |
] | |
@bounds = {x, y, width, height} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "redcarpet" | |
require "redcarpet/render_strip" | |
# I'm not suggesting this is particularly sane, but it works. | |
# | |
# The little bit of regex fixes cases where two paragraphs get squished | |
# together and you end up with the unsightly | |
# | |
# "end of sentence.New sentence" | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby's epoch times are three digits shorter than JavaScript's, | |
# which need only be slightly annoying: | |
class Time | |
def self.at_from_js(date) | |
self.at date.to_i / 1000 | |
end | |
end | |
Time.at(1369503558784) # 45367-11-03 15:13:04 +0000 | |
Time.at_from_js(1369503558784) # 2013-05-25 18:39:18 +0100 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.defineProperty Object.prototype, "new", get : -> new @ | |
class Foo | |
constructor : -> console.log "foo!" | |
class Bar | |
constructor : -> console.log "bar!" | |
Foo.new # -> "foo!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Open JIRA tickets from the commandline! | |
# | |
# Installation: | |
# | |
# $ sudo ln jira.sh /usr/bin/jira | |
if [ -z $1 ] | |
then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
paper = Raphael el | |
rect = paper.rect 100, 100, 100, 100 | |
methods = | |
move : (x, y) -> | |
rect.attr | |
transform : "...T#{x},#{y}" | |
rotate : (ang) -> | |
rect.attr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shift = (element, dir) -> | |
if dir is "down" | |
fn = "insertBefore" | |
prop = "prev" | |
else | |
fn = "insertAfter" | |
prop = "next" | |
# sibling (either next or previous) | |
sib = element[prop] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
randomColour = -> "#" + (Math.floor(Math.random() * 0xffffff)).toString(16) |