Skip to content

Instantly share code, notes, and snippets.

View CodeOfficer's full-sized avatar

Russell Jones CodeOfficer

View GitHub Profile
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"}
# 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
# another great snippet courtesy of http://heypanda.com/
class Fixnum
# returns seconds
def hours
self * 3600
end
end
def forever
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
$('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;
});
@CodeOfficer
CodeOfficer / finder_sort.rb
Created July 7, 2009 22:07 — forked from ryanb/finder_sort.rb
sorting like mac's finder
# 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[& # % + < = > | ~ $]
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);
# 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"
/*
* a smart poller for jquery.
* (by github)
*
* simple example:
*
* $.smartPoller(function(retry) {
* $.getJSON(url, function(data) {
* if (data) {
* doSomething(data)
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