This file contains hidden or 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
# Gets the index for where +obj+ _should_ be, even if it's not in the | |
# list. | |
def index_for!(obj) | |
divide_and_conquer( | |
@array, | |
:divisible? => lambda do |list| | |
# divide if the list could contain obj | |
list.length > 1 && @sorter.call(obj, list.first) > 0 && @sorter.call(obj, list.last) <= 0 | |
end, | |
:divide => lambda do |list| |
This file contains hidden or 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 merge_two_sorted_lists(a, b, &comparator) | |
comparator ||= lambda { |x,y| x <=> y } | |
linrec( | |
:cond => lambda { |pair| pair.first.empty? || pair.last.empty? }, | |
:before => lambda do |pair| | |
preceding, following = case comparator.call(pair.first.first, pair.last.first) | |
when -1; [pair.first, pair.last] | |
when 0; [pair.first, pair.last] | |
when 1; [pair.last, pair.first] | |
end |
This file contains hidden or 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
# config.gem "rspec", :lib => false, :version => ">=1.2.6" unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec')) | |
# config.gem "rspec-rails", :lib => 'spec/rails', :version => ">=1.2.6" unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails')) |
This file contains hidden or 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 'chronic' | |
require 'timecop' | |
module TemporalHelpers | |
# Travels to +time+ and lets the clock keep running. | |
# | |
# If a block is given, executes the block at that | |
# time then returns to the present. | |
def travel_to(time, &block) |
This file contains hidden or 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
# ... | |
Rails::Initializer.run do |config| | |
# ... | |
# set up Syslog logging: | |
config.gem 'SyslogLogger', :version => '1.4.0' | |
require 'syslog_logger' | |
config.logger = RAILS_DEFAULT_LOGGER = SyslogLogger.new("my_rails_app.#{ENV['RAILS_ENV']}") | |
config.middleware.use Rack::CommonLogger, RAILS_DEFAULT_LOGGER |
This file contains hidden or 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
# an example Monit configuration file for delayed_job | |
# | |
# To use: | |
# 1. copy to /var/www/apps/{app_name}/shared/delayed_job.monitrc | |
# 2. replace {app_name} and {environment} as appropriate | |
# 3. add this to your /etc/monit/monitrc | |
# | |
# include /var/www/apps/{app_name}/shared/delayed_job.monitrc | |
check process delayed_job with pidfile /var/www/apps/{app_name}/shared/pids/delayed_job.pid |
This file contains hidden or 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 SomeModel < ActiveRecord::Base | |
include TemporalHelper | |
def my_temporal_attribute=(value) | |
write_attribute :my_temporal_attribute, parse_temporal(value) | |
end | |
end |
This file contains hidden or 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
# make asset paths fully-qualified when pages are | |
# rendered as widgets in an OpenSocial container: | |
config.action_controller.asset_host = 'my_app.local' |
This file contains hidden or 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 => 2, | |
# NOTE for partials, you need to include the format | |
# otherwise, it'll fail to find byows/_byow.erb even if byows/_byow.html.erb exists | |
:b => render(:partial => 'example.html') | |
}.to_json |
This file contains hidden or 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 PeopleController < ActionController::Base | |
def index | |
respond_to do |format| | |
format.jqa | |
end | |
end | |
end |
OlderNewer