Skip to content

Instantly share code, notes, and snippets.

View mnelson's full-sized avatar

Mike Nelson mnelson

View GitHub Profile
module FacebookSession
module Session
def self.included(base)
base.class_eval do
cattr_accessor :finding_current
include Methods
end
end
module Methods
Class.Mutators.Memoize = function(method_names){
Array.from(method_names).each(function(method){
var old_method = this.prototype[method];
this.prototype[method] = function(){
if(this.__memoized[method] !== undefined) return this.__memoized[method];
return this.__memoized[method] = old_method.apply(this, arguments);
};
}, this);
class ApplicationController < ActionController::Base
helper_method :page_title,
:page_description
# ...
end
@mnelson
mnelson / enumerables.rb
Created December 28, 2010 21:33
Allows you to access static values by human names. eg. Browser::Firefox => 5
class EnumerableClass
UNKNOWN_ENUMERABLE = "Unknown"
class << self
def all
self.to_a.collect{|g| g[1]}
end
def add_item(key,value)
#attached_files
%p.declaration
Attachments:
%em
= add_object_link("add", "#attached_files", {:partial => '/attached_files/file', :locals => {:form => form}})
- object.attached_files.each_with_index do |attachment, i|
= render :partial => '/attached_files/file', :locals => {:form => form, :attached_file => attachment, :child_index => i}
require 'exception_handler'
class ApplicationController < ActionController::Base
include YourApp::ExceptionHandler
end
@mnelson
mnelson / diabox.js
Created April 14, 2011 22:19
Let's try to be a little friendlier with new dom elements.
observe_anchors : function(){
box = this;
$(document.body).addEvent('click:relay(a[rel*="box"])', function(e){
var a = e.target;
if(a.rel && a.rel.test(box.opt.rel_target)){
box.set_loading();
box.construct_renderable_from_link(a).render();
e.stop();
}
});
@mnelson
mnelson / parser.js
Created October 1, 2011 20:57
The basic format to follow when defining your own renderable.
var d = new Diabox({parser : function(target){
// use target string to determine the renderable key. ie 'custom_key'
// return null if the target does not fit your criteria
}});
@mnelson
mnelson / _head.haml
Created October 5, 2011 20:37
DynMeta demonstration
%title= meta(:title)
%meta{:name => 'robots', :content => meta(:robots)}
%meta{:name => 'description', :content => meta(:description)}
module TemplateHelper
def url_for(*args)
options = args.extract_options!
return super unless options.present?
handle = options.delete(:handlebars)
url = super(*(args.push(options)))
handle ? url.gsub(/%7B%7B(.+)%7D%7D/){|m| "{{#{$1}}}"} : url
end