Skip to content

Instantly share code, notes, and snippets.

View mnelson's full-sized avatar

Mike Nelson mnelson

View GitHub Profile
$(".call-to-action").live("click",function(e){
register_user_modal($(this).attr("href"));
e.preventDefault();
return false;
});
function register_user_modal(target_link){
var options = {
open:function(){
$.get(target_link,{},
function(r){
##### USAGE #####
#
# The StaticValue class gives you access to globally accessible constants through a human-readable and compact format.
#
# To define a new set of static values just define a class in this file such as:
# StaticValue.register('MyValues')
#
# Once your class is present you can add values to it via the add_item method:
# MyValues.add_item :Default, 0
# MyValues.add_item :Custom, 1
class Effect < AR::Base
scope :my_scope, select('project_id, taskType, user_id, SUM(hours)').joins(:project_task).where(:project_tasks => {:project_id => 2, :taskType => 'Pre-Sales'}).group('user_id')
end
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
@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)}
@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 / 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();
}
});
require 'exception_handler'
class ApplicationController < ActionController::Base
include YourApp::ExceptionHandler
end
#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}
@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)