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
@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>
@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
@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/
# 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}"
@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

@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.
@jimbojsb
jimbojsb / gist:1630790
Created January 18, 2012 03:52
Code highlighting for Keynote presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@desandro
desandro / require-js-discussion.md
Created January 31, 2013 20:26
Can you help me understand the benefit of require.js?

I'm having trouble understanding the benefit of require.js. Can you help me out? I imagine other developers have a similar interest.

From Require.js - Why AMD:

The AMD format comes from wanting a module format that was better than today's "write a bunch of script tags with implicit dependencies that you have to manually order"

I don't quite understand why this methodology is so bad. The difficult part is that you have to manually order dependencies. But the benefit is that you don't have an additional layer of abstraction.