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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Painter</title> | |
<style> | |
body { | |
margin: 0; | |
padding: 0; | |
background: #eee; |
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
# This monkey patches the PostgreSQL adapter to use asynchronous | |
# communication when doing its "SELECT 1" check for is-connection-active. | |
# One symptom of this problem is stalled processing queues in Sidekiq. | |
# See also: | |
# | |
# https://github.com/rails/rails/issues/12867 | |
# | |
# At the time of writing we have seen indefinite blocking down in the C | |
# library's "poll()" method due to the out-of-box Rails code using blocking | |
# I/O, in multithreaded environments - one thread gets stuck in the I/O and |
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
# Is this connection alive and ready for queries? | |
def active? | |
begin | |
conn = @connection | |
timeout = 5 # seconds | |
# Now grab a reference to the underlying socket so we know when the | |
# connection is established | |
socket = conn.socket_io # AKA IO.for_fd(conn.socket) - same thing |
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
#$ rails new foo | |
#$ cd foo | |
# <set up config/database.yml to use Postgres with "pool: 1"> | |
# development: | |
# adapter: postgresql | |
# encoding: utf8 | |
# database: foo_development | |
# pool: 1 | |
# <add "gem 'pg'" to Gemfile> | |
#$ bundle install |
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 visit_Arel_Nodes_Between o | |
if (o.right.children[0].class == Date && o.right.children[1].class == Date) | |
min = o.right.children[ 0 ] | |
max = o.right.children[ 1 ] + 1 | |
"(#{visit o.left} >= #{visit min} AND #{visit o.left} < #{visit max})" | |
else | |
"#{visit o.left} BETWEEN #{visit o.right}" | |
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
Rails database adapter issue: Postgres vs SQLite and BETWEEN | |
"Foo.where(:date=>(d..d))" in Postgres => finds records spanning the date | |
"Foo.where(:date=>(d..d))" in SQLite => finds nothing | |
This is an inclusive/exclusive ambiguity in BETWEEN which Rails doesn't resolve |
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
1.9.3p392 :010 > reference = YAML::load( reference ) | |
NoMethodError: undefined method `from' for nil:NilClass | |
from /Users/adh1003/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/relation/query_methods.rb:264:in `build_arel' | |
from /Users/adh1003/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/relation/query_methods.rb:260:in `arel' | |
from /Users/adh1003/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/relation/delegation.rb:29:in `respond_to?' | |
from /Users/adh1003/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:291:in `init_with' | |
from /Users/adh1003/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:284:in `revive' | |
from /Users/adh1003/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:219:in `visit_Psych_Nodes_Mapping' | |
from /Users/adh1003/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit' | |
from /Users/adh1003/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1 |
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
pondmac:log adh1003$ irb | |
1.9.3p392 :004 > {:thing => ("foo" if true)} | |
=> {:thing=>"foo"} | |
1.9.3p392 :005 > {:thing => ("foo" if false)} | |
=> {:thing=>nil} | |
1.9.3p392 :006 > |
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
pondmac:log adh1003$ rake db:migrate | |
(in /Users/adh1003/Documents/Work/Hipposoft/TrackRecord/Development/trackrecord) | |
== CreateHomes: migrating ==================================================== | |
-- create_table(:homes) | |
NOTICE: CREATE TABLE will create implicit sequence "homes_id_seq" for serial column "homes.id" | |
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "homes_pkey" for table "homes" | |
-> 0.0236s | |
== CreateHomes: migrated (0.0237s) =========================================== | |
pondmac:log adh1003$ rails c |
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 File.dirname(__FILE__) + '/../test_helper' | |
class SavedReportTest < ActiveSupport::TestCase | |
def not_nil( a, msg ) | |
@errors << [ msg, a ] if a.nil? | |
end | |
def check( a, b, msg ) | |
@errors << [ msg, a, b ] unless a == b |
NewerOlder