Skip to content

Instantly share code, notes, and snippets.

View carpeliam's full-sized avatar
👋
say hi!

Liam Morley carpeliam

👋
say hi!
View GitHub Profile
@tbranyen
tbranyen / backbone_pushstate_router.js
Last active February 25, 2024 21:38
hijack links for pushState in Backbone
// All navigation that is relative should be passed through the navigate
// method, to be processed by the router. If the link has a `data-bypass`
// attribute, bypass the delegation completely.
$(document).on("click", "a[href]:not([data-bypass])", function(evt) {
// Get the absolute anchor href.
var href = { prop: $(this).prop("href"), attr: $(this).attr("href") };
// Get the absolute root.
var root = location.protocol + "//" + location.host + Application.root;
// Ensure the root is part of the anchor href, meaning it's relative.
@robotlolita
robotlolita / gist:1034936
Created June 20, 2011 00:15
Attempt at explaining prototypical OO.

Objects

Objects are the most basic structure in JavaScript. Everything is an object: functions, arrays, numbers, strings, booleans, you-name-it. And yet we have no classes. That is, despite being an Object Oriented language, JavaScript does not use a separated layer of meta-data just to define how all these objects need to be constructed.

In fact, they are just collections of key/value pairs, that define their own behaviour. Thus, an object with properties foo = 1 and

# I don't necessarily love CoffeeScript as a template for ES.next, but here is an example
# of metaprogramming via a combination of:
# * "this" bound to the currently created class in class definitions
# * class methods inherited
class Foo
this.hasMany = (types) ->
this.prototype[types] = ->
alert "Looking up #{types}"
@gmoore
gmoore / gist:973748
Created May 16, 2011 01:09
While in Baltimore...
I want...
Steamed crabs!
Obrycki's
Walk east on Pratt Street for about half a mile
1727 E Pratt St, Baltimore, MD 21231
http://www.yelp.com/biz/obryckis-crab-house-and-seafood-restaurant-baltimore
http://www.obryckis.com/
@kamal
kamal / baby_talk.rb
Created April 29, 2011 14:02 — forked from stympy/subscription_plan.rb
Extending a model in a Rails 3 (pre-3.1) engine
module BabyTalk
class Engine < Rails::Engine
config.to_prepare do
User.class_eval do
has_many :participations, :foreign_key => "participant_id"
has_many :rooms, :through => :participations
end
end
end
end
@carpeliam
carpeliam / _form.html.erb
Created April 3, 2011 06:42
jQuery template solution for nested forms in rails
<!-- app/views/project_roles/_form.html.erb -->
<div class="projectRole">
<%= form.label :name %>
<%= form.text_field :name %>
<!-- etc etc etc -->
<!-- the JS down below relies on the following two lines being next to each other -->
<%= form.hidden_field '_destroy' unless form.object.new_record? %>
<a href="#" class="removeNestedItem">Delete</a>