Skip to content

Instantly share code, notes, and snippets.


Adam Cuppy acuppy

View GitHub Profile
acuppy / Hash required key assertions
Created Dec 28, 2010
Hash extension to add addition assertions
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?
# Confirms that a key is present and that is has value
acuppy / Unless Helpers
Created Jan 24, 2011
Adds the link_to_remote_if/unless helpers to a Rails application
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
def link_to_remote_unless(condition, name, options = {}, html_options = nil)
!condition ? link_to_remote(name, options, html_options) : name
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
acuppy /
Last active Dec 20, 2015
String#mapConcat: splits a string by character; iterates through each character; runs a callback on each character; and concat the callback return into a new string
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)
acuppy /
Last active Dec 20, 2015
String#arrayReplace: similar to String#replace, but allows you to pass multiple array sets for replacement.
String.prototype.arrayReplace = (args...) ->
rtn = @
for set in args
rtn = rtn.replace(new RegExp(set[0], 'gi'), set[1])
acuppy / url_patterns.rb
Created Jul 21, 2013
Remote URL (ex: and Local URL (ex: C:\\path\to\file or /path/to/file.txt)
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/
acuppy / document_types.rb
Created Jul 21, 2013
All major document mime types (Microsoft Office, Apple iWork, Adobe PDF) as a Ruby Module
View document_types.rb
module DocumentFileTypes
module Microsoft
WORD = %w(
acuppy / paginate_array.rb
Created Jul 21, 2013
Array#paginate: adds pagination functionality using the WillPaginate gem to a Ruby Array
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 =[: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]
acuppy / aspell_spell_checker.rb
Last active Dec 20, 2015
Simple abstraction layer to interact with the UNIX aspell library via Ruby
View aspell_spell_checker.rb
module Spelling
require 'net/https'
require 'uri'
require 'rexml/document'
ASPELL_WORD_DATA_REGEX =\&\s\w+\s\d+\s\d+(.*)$/)
ASPELL_PATH = "aspell"
# @param String: spell_check_text - represents the source string
acuppy / object_true_false.rb
Last active Dec 20, 2015
Object#true? and Object#false? boolean assertions
View object_true_false.rb
class Object
def true?
self.respond_to?( :to_i ) ? ! : true
def false?