This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
posts GET /posts {:controller=>"posts", :action=>"index"} | |
formatted_posts GET /posts.:format {:controller=>"posts", :action=>"index"} | |
POST /posts {:controller=>"posts", :action=>"create"} | |
POST /posts.:format {:controller=>"posts", :action=>"create"} | |
new_post GET /posts/new {:controller=>"posts", :action=>"new"} | |
formatted_new_post GET /posts/new.:format {:controller=>"posts", :action=>"new"} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# courtesy of http://heypanda.com/ | |
class TryProxy | |
def initialize(receiving_object) | |
@receiving_object = receiving_object | |
end | |
def method_missing(meth, *args, &block) | |
@receiving_object.nil? ? nil : @receiving_object.send(meth, *args, &block) rescue nil | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# another great snippet courtesy of http://heypanda.com/ | |
class Fixnum | |
# returns seconds | |
def hours | |
self * 3600 | |
end | |
end | |
def forever |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tempfile' | |
def say(cmd, voice='Fred') | |
temp_file = Tempfile.new('sayfile') | |
tf = File.new(temp_file.path, "w+") | |
tf.puts(cmd) | |
tf.close | |
`cat #{temp_file.path} | /usr/bin/say -v #{voice}` | |
temp_file.unlink | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('button[type="submit"]').bind('click', function() { | |
this.setAttribute('originalValue', this.innerHTML); | |
this.disabled=true; | |
this.innerHTML='Submitting...'; | |
result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit()); | |
if (result == false) { this.innerHTML = this.getAttribute('originalValue'); this.disabled = false }; | |
return result; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mimic Mac OS X Finder's sort by name. | |
class Array | |
def finder_sort | |
sort_by { |s| s.to_finder_sort } | |
end | |
end | |
class String | |
def to_finder_sort | |
punctuation = %w[` ^ _ - , ; ! ? ' " ( ) [ ] { } @ *] + ['\\'] + %w[& # % + < = > | ~ $] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.fn.restForm = function(type, options) { | |
var defaults = { | |
method: 'post', | |
action: this.attr('href'), | |
confirm: false, | |
confirm_message: 'Are you sure?', | |
trigger_on: 'click' | |
}; | |
var opts = $.extend(defaults, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# adapted from http://blog.caboo.se/articles/2006/12/28/a-better-capistrano-backup | |
# supports multistage deploy setup | |
# allows for restore and local database imports | |
namespace :db do | |
desc "Copy the remote production database to the local development machine" | |
task :backup, :roles => :db, :only => { :primary => true } do | |
filename = "#{application}_#{Time.now.strftime("%Y%m%d_%H%M%S")}.sql.bz2" | |
backupfile = "/tmp/#{filename}" | |
data = capture "cat #{shared_path}/config/database.yml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* a smart poller for jquery. | |
* (by github) | |
* | |
* simple example: | |
* | |
* $.smartPoller(function(retry) { | |
* $.getJSON(url, function(data) { | |
* if (data) { | |
* doSomething(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AccordionsHelper | |
def accordions_for( *options, &block ) | |
raise ArgumentError, "Missing block" unless block_given? | |
accordions = AccordionsHelper::AccordionsRenderer.new( *options, &block ) | |
accordions_html = accordions.render | |
concat accordions_html | |
end | |