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
# http://en.wikibooks.org/wiki/SQL_dialects_reference/Functions_and_expressions/Math_functions/Numeric_functions | |
def rand_function | |
@rand_function ||= ( | |
if [ "SQLite", "PostgreSQL" ].include? ActiveRecord::Base.connection.adapter_name then | |
"random" | |
else | |
"rand" | |
end | |
) | |
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
#!/usr/bin/env ruby | |
## | |
# alert_me | |
# | |
# A simple delay timer to send a growl notification at specific time with a | |
# message. Useful for when you need to check on something later | |
# | |
# echo "Go look at system 42" | alert_me in 2 hours | |
# |
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
# Returns a copy of the attributes hash that only includes those | |
# attributes that have values. | |
def attributes_with_values | |
returning Hash.new do |with_values| | |
@attributes.each_pair do |name, value| | |
if value⋅ | |
with_values[name] = value | |
else | |
column = column_for_attribute(name) | |
if column.has_default? and !column.null then |
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 method to have RETURNING work if you are partitioning data using trigger. | |
-- The method to this madness is: | |
-- | |
-- 1) Use the normal trigger mechanism to insert the data into the child tables, but | |
-- Instead of the trigger function returning NULL so that the row does not get⋅ | |
-- inserted into the master table, it returns the row inserted into the child | |
-- table | |
-- | |
-- 2) Postgres will insert the new row from the trigger into the master table | |
-- |
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 'rubygems' | |
require 'activerecord' | |
class ActiveRecord::Base | |
alias_method '__initialize__', 'initialize' | |
def initialize options = nil, &block | |
returning( __initialize__(options, &block) ) do | |
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
require 'rubygems' | |
require 'spec' | |
require 'stringio' | |
require 'logging' | |
Logging::Logger['root'].level = :all | |
module Spec | |
module Log | |
def self.io | |
@io ||= StringIO.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
# | |
# This exists as a way to make active record use SQL literals in attributes when | |
# creating or updating records | |
# | |
module ActiveRecord | |
module ConnectionAdapters | |
class Column | |
class Literal < ::String | |
def quoted_id() self end | |
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
# Overwrite the quote column name since it quotes everything, but pk can return | |
# a multiple columname for a pk, and when that is quoted it does not match any | |
# column. | |
if ActiveRecord::Base.connection.adapter_name == "PostgreSQL" then | |
module ActiveRecord | |
module ConnectionAdapters | |
class PostgreSQLAdapter | |
if instance_methods.include?('quote_column_name') then | |
unless instance_methods.include?( 'orig_quote_column_name' ) |
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
#!/usr/bin/env ruby | |
=begin | |
INSTALL: | |
curl http://github.com/defunkt/gist/raw/master/gist.rb > gist && | |
chmod 755 gist && | |
sudo mv gist /usr/local/bin/gist | |
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
# Please install the Engine Yard Capistrano gem | |
# gem install eycap --source http://gems.engineyard.com | |
require "eycap/recipes" | |
set :keep_releases, 5 | |
set :application, 'sinatra' | |
set :repository, 'git://github.com/copiousfreetime/integrity.git' | |
set :user, 'jeremy' | |
set :password, 'VBGYjMiZ5A' | |
set :deploy_to, "/data/#{application}" |
OlderNewer