Skip to content

Instantly share code, notes, and snippets.

View CodeOfficer's full-sized avatar

Russell Jones CodeOfficer

View GitHub Profile
class JobsController < ApplicationController
before_filter :require_user, :except => [ :index, :show ]
def index
@listings = Job.find_by_complex_search(current_user, params).paginate({ :page => params[:page], :per_page => CONFIG['per_page'] })
flash.now[:notice] = "Sorry, there were no records found." if @listings.blank?
respond_to do |format|
format.html # index.html.erb
(function(message){
alert(message);
})('hello!');
// -------------------------
var Test = function() {
var message = 'hello';
return {
say: function() {
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
/*
* a smart poller for jquery.
* (by github)
*
* simple example:
*
* $.smartPoller(function(retry) {
* $.getJSON(url, function(data) {
* if (data) {
* doSomething(data)
# 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"
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);
@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[& # % + < = > | ~ $]
$('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;
});
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
# another great snippet courtesy of http://heypanda.com/
class Fixnum
# returns seconds
def hours
self * 3600
end
end
def forever