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 / 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
@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 / 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 / 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
# 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 / 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?
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: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"]
@carpeliam
carpeliam / .irbrc.rb
Created March 24, 2012 22:42
pretty print active record model (good for .irbrc)
def arp(model)
key_length = model.attributes.keys.max_by(&:size).size
model.attributes.sort.each do |k,v|
puts "#{k.ljust key_length}: #{v.inspect}"
end
return nil
end
Parent extends Backbone.Model
initialize: ->
# should the model listen to child events here and fire a separate event?
@children = new Backbone.Collection([], model: Parent)
ObjView extends Backbone.View
initialize: ->
@collection = new Backbone.Collection([], model: Parent)
# should the view try to be responsible for listening to any sync on any child, no matter how deep?
@collection.each (m) ->