Skip to content

Instantly share code, notes, and snippets.

dbrady_trainline

Build a bot that triggers searches on http://thetrainline.com and returns the results in a specific format.

Input

  • The bot should respond to ComThetrainline.find(from, to, departure_at).
  • Assume that the parameters from and to will be EXACTLY what you need.
  • departure_at will be a Ruby DateTime object.
@ordinaryzelig
ordinaryzelig / .ruby-version
Last active August 29, 2015 14:01
Test cases for thread-safety in mocking libraries (http://redningja.com/dev/parallel-tests-with-single-database/)
ruby-2.0.0-p353
{
"token" => "02999FA70DA28B16C1F48D99D07ECEB7.sbg-vm-fe02",
"transaction" => {
"account" => {
"brand" => "PAYPAL"
},
"channel" => "52275ebaf361f20a76b038ba4c806991",
"criterions" => [
[0] {
"name" => "mode",
@ordinaryzelig
ordinaryzelig / active_record_sand_boxed.rb
Created February 26, 2010 22:22
internal sandbox mode
# rollback whatever was done in this block.
class ActiveRecord::Base
def self.sand_boxed
transaction do
yield
raise ActiveRecord::Rollback
end
end
@ordinaryzelig
ordinaryzelig / attributes_for.rb
Created March 14, 2010 02:46
attributes hash for any object
# convert results of calling methods into attributes hash.
# e.g. Date.today.attributes_for(:day, :month, :year) would return
# {:day => 13, :month => 3, :year => 2010}
class Object
def attributes_for(*method_names)
method_names.inject({}) do |hash, method_name|
hash[method_name] = send(method_name)
hash
end
# application_controller.rb
before_filter :april_fool
def april_fool
unless logged_in? && session[:april_fooled]
session[:april_fooled] = true
flash.now[:april_fool] = 'error 10.4.1: you may have corrupted data. contact administrator immediately.'
# get it? 2010.4.1!
end
# app/helpers/application_helper.rb
def update_flash
[:notice, :error].each do |type|
message = flash[type]
concat "$('#flash_#{type}').html('message')"
end
end
// app/views/layouts/application.js.erb
alert(<%= flash[:notice]) %>)
// app/views/layouts/application.js.erb
<% update_flash %>
<%= yield %>