View Hash required key assertions
class Hash | |
# Confirms that a key is set in the Hash | |
def assert_required_keys(*required_keys) | |
missing_keys = [] | |
[required_keys].flatten.each { |k| missing_keys << k unless keys.has_key?(k) } | |
raise(ArgumentError, "Missing required key(s): #{missing_keys.join(", ")}") unless missing_keys.empty? | |
end | |
# Confirms that a key is present and that is has value |
View Unless Helpers
module ActionView | |
module Helpers | |
module PrototypeHelper | |
def link_to_remote_if(condition, name, options = {}, html_options = nil) | |
condition ? link_to_remote(name, options, html_options) : name | |
end | |
def link_to_remote_unless(condition, name, options = {}, html_options = nil) | |
!condition ? link_to_remote(name, options, html_options) : name | |
end |
View backup.rake
## rake file lib/tasks/backup.rake | |
desc "Backup Everything Specified in config/backup.yml" | |
task :backup => [ "backup:db", "backup:push"] | |
namespace :backup do | |
RAILS_APPDIR = RAILS_ROOT.sub("/config/..","") | |
def interesting_tables |
View string.map_concat.coffee
String.prototype.mapConcat = (args...) -> | |
separator = args.slice(0,1) if $.type(args[0]) == 'string' or $.type(args[0]) == 'regexp' | |
separator or= '' | |
chars = @.split(separator) | |
rtn = [] | |
for char, i in chars | |
rtn.push(args[0].call(@, char, i) or char) | |
rtn.join('') |
View string.array_replace.coffee
String.prototype.arrayReplace = (args...) -> | |
rtn = @ | |
for set in args | |
rtn = rtn.replace(new RegExp(set[0], 'gi'), set[1]) | |
rtn |
View url_patterns.rb
REMOTE_URL_PATTERN = /\A(?:(?:http|https):\/\/[a-z0-9]+(?:[\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(?:\:[0-9]{1,5})?).*\z/ix | |
LOCAL_URL_PATTERN = /\A(?:[a-zA-Z]{1,2}\:\\\\?).*\z/ |
View document_types.rb
module DocumentFileTypes | |
module Microsoft | |
WORD = %w( | |
application/msword | |
application/vnd.openxmlformats-officedocument.wordprocessingml.document | |
application/vnd.openxmlformats-officedocument.wordprocessingml.template | |
application/vnd.ms-word.document.macroEnabled.12 | |
application/vnd.ms-word.template.macroEnabled.12 | |
) | |
View paginate_array.rb
require 'will_paginate' | |
class Array | |
def paginate(all = nil, options = {}) | |
options[:page] = (options[:page].to_i == 0) ? 1 : options[:page].to_i | |
options[:per_page] = (options[:per_page].to_i == 0) ? 30 : options[:per_page].to_i | |
pagination_array = WillPaginate::Collection.new(options[:page], options[:per_page], self.size) | |
start_index = pagination_array.offset | |
end_index = start_index + (options[:per_page] - 1) | |
array_to_concat = self[start_index..end_index] |
View aspell_spell_checker.rb
module Spelling | |
require 'net/https' | |
require 'uri' | |
require 'rexml/document' | |
ASPELL_WORD_DATA_REGEX = Regexp.new(/\&\s\w+\s\d+\s\d+(.*)$/) | |
ASPELL_PATH = "aspell" | |
# | |
# @param String: spell_check_text - represents the source string |
View object_true_false.rb
class Object | |
def true? | |
self.respond_to?( :to_i ) ? !self.to_i.zero? : true | |
end | |
def false? | |
!true? | |
end | |
end |
OlderNewer