Skip to content

Instantly share code, notes, and snippets.

View bernerdschaefer's full-sized avatar

Bernerd Schaefer bernerdschaefer

View GitHub Profile
// Naive proxy server to route data from 12345 to postgres as 5432
//
// javac Server.java
// java -server Server
import java.io.IOException;
import java.nio.channels.*;
import java.nio.ByteBuffer;
import java.net.*;
# Newbie Programmer
def factorial(x)
if x == 0
return 1
else
return x * factorial(x - 1)
end
end
puts factorial(6)
puts factorial(0)
## Sibling constant resolution/scoping
module X
class Y; end
end
class X::Z
def self.y
Y
end
end
10.times do |i| args = File.readlines(__FILE__)[__LINE__-1].match(/\|(.+?)\|/)[1].split(/[, ]+/)
p args
end
def wait_conditionally_until
if page.driver.wait?
page.wait_until do
begin
yield
rescue Selenium::WebDriver::Error::WebDriverError => e
# do nothing - continue to wait for timeout
end
end
else
def luhn?(c)(0..c.size).inject(0){|s,i|_=c[i,1].to_i;s+(i%2!=0?_:(_*2).to_s.split('').inject(0){|y,z|y+z.to_i})}%10==0 end
# mongoid issue #136
require 'rails'
require 'rspec'
require 'mongoid'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db('testing')
end
require 'mongoid'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db('testing')
end
class Parent
include Mongoid::Document
field :name
#!/usr/bin/env ruby
require "rubygems"
require "jruby-jars"
args = [ "-jar", JRubyJars.stdlib_jar_path,
"-r", JRubyJars.stdlib_jar_path ].push(*$*)
exec("java", *args)
1) Mongoid::Persistence .create! inserting with a field that is not unique when a unique index exists raises an error
Failure/Error: lambda { Person.create!(:ssn => "555-55-9999") }.should raise_error
expected Exception but nothing was raised
# ./spec/integration/mongoid/persistence_spec.rb:34
# spec/integration/mongoid/association_attributes_spec.rb:3
2) Mongoid::Collections .index_information returns index information from the collection
Failure/Error: Person.index_information["title_1"].should_not be_nil
expected not nil, got nil
# ./spec/unit/mongoid/collections_spec.rb:53