Skip to content

Instantly share code, notes, and snippets.

View kornysietsma's full-sized avatar

Korny Sietsma kornysietsma

View GitHub Profile
require 'rubygems'
require 'cucumber'
require 'xmlrpc/client'
# a hacky way to combine outputs to several io devices
class IoMerger
attr_accessor :other_ios
def initialize(base_io)
@base_io = base_io
Given "I am on the Twitter home page" do
@home_page.visit
end
Given "I see the most popular topic" do
@most_popular = @home_page.most_popular_topic
puts "Most popular topic: '#{@most_popular}'"
end
When "I visit the Twitter home page" do
class TwitterHomePage
PAGE_URL = "http://www.twitter.com"
def initialize(world)
@world = world
@browser = $selenium_helper.browser
end
def visit
@browser.open PAGE_URL
@browser.wait_for_page_to_load
selenium.browser.name=*firefox
selenium.port=4444
require 'selenium/client'
require 'selenium/rspec/spec_helper'
require File.join(BASEDIR,'support/user_config.rb')
if defined? JRUBY_VERSION
# jruby has it's own process-handling code, as 'fork' is unreliable in java
require 'java'
end
class SeleniumHelper
BASEDIR = File.join(File.dirname(__FILE__),"..") unless defined? BASEDIR
PRJDIR = File.join(File.dirname(__FILE__),"..","..","..") unless defined? PRJDIR
require 'spec/expectations' # rspec extras
require File.join(BASEDIR,'support/selenium_helper.rb')
require File.join(BASEDIR,'support/user_config.rb')
# globals - keep these to a minimum!
$user_config = UserConfig.new
$selenium_helper = SeleniumHelper.new($user_config) # better a global than a singleton - still need something global as it's used in monkey-patching bits below
selenium.browser.name=*firefox
selenium.port=4444
class KornyHanoi
def initialize(options={:discs => 8})
@discs = options[:discs]
@all_pegs = [:from, :pivot, :to]
@pegs = {:from => [], :to => [], :pivot => []}
@discs.downto(1) do |num|
@pegs[:from] << num
end
end
@kornysietsma
kornysietsma / excel_reader.rb
Created November 28, 2010 22:29
basic JRuby code to read/write a spreadsheet using the Apache poi libraries
require 'java'
require 'pp'
import "org.apache.poi.hssf.usermodel.HSSFWorkbook"
import "org.apache.poi.hssf.usermodel.HSSFSheet"
import "org.apache.poi.hssf.usermodel.HSSFRow"
import "org.apache.poi.hssf.usermodel.HSSFCell"
import "java.io.FileInputStream"
import "java.io.FileOutputStream"
@kornysietsma
kornysietsma / sample.scala
Created January 29, 2011 10:39
sample use of progresslogger if it were scala code
p = new ProgressLogger(count=1000000)
( state => println("Processed " + state.count + "rows"))
collection.foreach(
record => (
p.trigger
// do stuff
)
)