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 / gist:3eb37fbb4a4b720f0537
Created March 13, 2012 23:38
super-sexy model binding for a collection
ProjectPages.Views.Projects ||= {}
class ProjectPages.Views.Projects.KeyMilestoneView extends Backbone.View
templates:
show: JST["backbone/templates/projects/key_milestones/show"]
edit: JST["backbone/templates/projects/key_milestones/edit"]
form: JST['backbone/templates/projects/key_milestones/_form']
modalHeader: JST["backbone/templates/shared/modal/header"]
modalFooter: JST["backbone/templates/shared/modal/footer"]
window.Story = Backbone.Model.extend({});
window.Stories = Backbone.Collection.extend({
model: Story,
url: 'https://www.facebook.com/feeds/page.php?id=347259993124&format=json&callback=?',
parse: function(response) {
console.log(response);
return response.entries;
}
});
@carpeliam
carpeliam / gist:1163049
Created August 22, 2011 18:01
Sass output
Sass::Engine.new(".GreenLight\n background-color: #0FF", :syntax => :sass).render
# returns => ".GreenLight {\n background-color: aqua; }\n"
# Is there a way to have Sass output #0FF instead of aqua?
# any way this could be a for loop in coffeescript too?
i = 0
j = 2
while i < 2 and j < 4
alert i
alert j
i++
j++
@carpeliam
carpeliam / node.log
Created June 26, 2011 01:11
socket.io + haproxy, having some proxy set-up issues
info - socket.io started
25 Jun 21:09:25 - Server started on port 8124
127.0.0.1 - - [Sun, 26 Jun 2011 01:09:32 GMT] "GET /require.js HTTP/1.1" 200 - "http://kriegspiel.carpeliam.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30"
debug - served static /socket.io.js
debug - client authorized
info - handshake authorized
info - handshaken 2411a4f640f1ac6684614b98bc7a95d5
127.0.0.1 - - [Sun, 26 Jun 2011 01:09:33 GMT] "GET /favicon.ico HTTP/1.1" 404 - "" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30"
debug - setting request GET /socket.io/1/websocket/2411a4f640f1ac6684614b98bc7a95d5
debug - publishing that 2411a4f640f1ac6684614b98bc7a95d5 connected
@carpeliam
carpeliam / jquery-nearest.js
Created April 27, 2011 20:56
jQuery function to find the closest element somewhere above the current element.. so either a prev sibling or a parent or a parent's prev sibling.
$.fn.nearest = function(selector) {
// base case if we can't find anything
if (this.length == 0)
return this;
var nearestSibling = this.prevAll(selector + ':first');
if (nearestSibling.length > 0)
return nearestSibling;
return this.parent().nearest(selector);
};
@carpeliam
carpeliam / db.rake
Created April 15, 2011 02:44
dump, load, or clear a mysql database for a rails project
namespace :db do
desc "Clear all tables"
task :clear => :environment do
conn = ActiveRecord::Base.connection
conn.tables.select{|t| t.start_with? ActiveRecord::Base.table_name_prefix }.each do |t|
conn.drop_table t
end
end
desc "Dump database into an SQL file"
@carpeliam
carpeliam / my_spec.rb
Created April 11, 2011 06:20
this fails: No route matches "/foos/1/bars"
require 'spec_helper'
module ActionDispatch::Routing
describe Mapper do
context "#my_method_that_modifies_routes", :type => :routing do
before do
# do some stuff that alters the routes
module DealsHelper
def render_deals
Deal.all.collect do |deal|
content_tag :div, :class => 'deal' do
image_tag(deal.photo_url)
content_tag :h3, deal.title, :class => 'title'
content_tag :p, deal.full_price, :class => 'full_price'
content_tag :p, deal.selling_price, :class => 'selling_price'
content_tag :p, deal.discount, :class => 'discount'
content_tag :p, deal.store.name, :class => 'store_name'
@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>