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' unless defined? Gem # rubygems is only needed in 1.8 | |
def unbundled_require(gem) | |
loaded = false | |
if defined?(::Bundler) | |
Gem.path.each do |gems_path| | |
gem_path = Dir.glob("#{gems_path}/gems/#{gem}*").last | |
unless gem_path.nil? | |
$LOAD_PATH << "#{gem_path}/lib" |
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
class TimeStringValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
require 'chronic' | |
record.errors[attribute] << "doesn't seem to be a valid time" unless Chronic.parse(value) | |
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
# Original credits: http://blog.inquirylabs.com/2006/04/13/simple-uri-validation/ | |
# HTTP Codes: http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTPResponse.html | |
require 'net/http' | |
class UriExistsValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
begin # check header response | |
url = URI.parse(value) | |
request = Net::HTTP.new(url.host, url.port) | |
response = request.request_head(url.path.empty? ? '/' : url.path) |
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 'uri' | |
class AbsoluteUriValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
begin | |
unless URI.parse(value).absolute? | |
record.errors[attribute] << 'is not an absolute URL' | |
end | |
rescue URI::InvalidURIError => error | |
record.errors[attribute] << 'is not a valid URL' |
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 'uri' | |
class RelativeUriValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
begin | |
unless URI.parse(value).relative? | |
record.errors[attribute] << 'is not a relative URL' | |
end | |
rescue URI::InvalidURIError => error | |
record.errors[attribute] << 'is not a valid URL' |
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
# Examples: | |
# test_valid_attribute Link, :url => 'http://example.com' | |
# test_invalid_attribute Link, :url => 'OH NOES!!!1!' | |
module ValidationHelpers | |
def test_valid_attribute(model, attr_val_hash) | |
test_attribute(:valid, model, attr_val_hash) | |
end | |
def test_invalid_attribute(model, attr_val_hash) |
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
-- Must me NUMBER or CHAR if you want to print it. Printing a VARCHAR is too complex for expensive databases like Oracle. | |
VARIABLE r CHAR (1000); | |
BEGIN | |
-- := is for assignment. vs = for equality | |
-- bind variables are prefixed with a colon | |
-- BANIST1 is the instance | |
-- BSK_INFO_REQUEST is the package | |
-- get_prel_codes() is the function | |
:r := BANINST1.BSK_INFO_REQUEST.get_prel_codes(); |
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
<html> | |
<head> | |
<title>RA White Pages</title> | |
<style type="text/css"> | |
* { | |
font-family: Arial, sans-serif; | |
font-size: 10pt; | |
} |
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
def batch_session_prune(keep_after = 1.month.ago, batch_by = 1.day, pause_time = 10) | |
time = ActiveRecord::SessionStore::Session.order(:updated_at).first[:updated_at] | |
while time < keep_after | |
time = time + batch_by | |
puts "Deleting sessions from #{time.to_s(:short)}" | |
ActiveRecord::SessionStore::Session.where('updated_at < ?', time).delete_all | |
sleep pause_time |
OlderNewer