Skip to content

Instantly share code, notes, and snippets.

View rsl's full-sized avatar
🏳️‍🌈
still a bad fish and free bird

Russell Norris rsl

🏳️‍🌈
still a bad fish and free bird
View GitHub Profile
require 'coffee'
require 'water'
require 'cup'
require 'carsten'
cup = Cup.new(:size => 'small')
cup.add(Coffee::Espresso.new(:shots => 3))
cup.add(Water::Ice.new(:cubes => 12))
cup.join
$("body.entries #all_tags span").click(function() {
var thisTag = $(this).text();
var indexOfThisTag = jQuery.inArray(thisTag, window.currentTags);
if (indexOfThisTag >= 0) {
window.currentTags.splice(indexOfThisTag, 1);
} else {
window.currentTags.push(thisTag);
}
$("#entry_tags_as_string").val(window.currentTags.join(", "));
});
@rsl
rsl / gist:12303
Created September 23, 2008 15:19
class FoosController < ApplicationController
def create
@foo = Foo.new(params[:foo])
respond_to do |format|
if @foo.save
flash[:notice] = 'Foo was successfully created.'
format.html { redirect_to(@foo) }
format.xml { render :xml => @foo, :status => :created, :location => @foo }
else
module LuckySneaks
module ActsAsUrl # :nodoc:
def self.included(base)
base.extend ClassMethods
end
module ClassMethods # :doc:
# Creates a callback to automatically create an url-friendly representation
# of the <tt>attribute</tt> argument. Example:
#
require 'test/unit'
begin
require File.dirname(__FILE__) + '/../../../config/environment'
rescue LoadError
require 'rubygems'
gem 'activerecord'
require 'active_record'
RAILS_ROOT = File.dirname(__FILE__)
class User < ActiveRecord::Base
def merge(other)
%w{
attribute_1
attribute_2
attribute_3
attribute_4
attribute_5
attribute_6
}.each do |attribute|
## Helper
# Used for the column that is the default sort
def default_sortable_header(column, order, text = nil)
column = column.to_s.downcase
order = order.to_s.downcase
opposite = order == "desc" ? "asc" : "desc"
text ||= column.humanize
query_string = ""
if params[:sort]
if params[:sort] == column
## Controller
# Calls with :order => order_with_default("documents.created_at", :desc)
private
def order_with_default(column, direction)
if params[:sort]
"#{params[:sort]} #{params[:direction]}, #{column} #{direction}"
else
"#{column} #{direction}"
@rsl
rsl / gist:76227
Created March 9, 2009 12:21 — forked from radar/gist:76111
Please confirm the upgrade from
%strong= Plan[session[:old_plan_id]]
to
%strong= Plan[session[:new_plan_id]]
%br
%br
You are upgrading your
%strong Orchestrate
account located at
%string
module ActiveSupport
module CoreExtensions #:nodoc:
module String
module Conversions
def to_klass
self.classify.constantize
rescue NameError
nil
end
end