Skip to content

Instantly share code, notes, and snippets.

View JonRowe's full-sized avatar
💭
⛵️

Jon Rowe JonRowe

💭
⛵️
View GitHub Profile
@JonRowe
JonRowe / rspec-expectations_spec.rb
Created February 15, 2013 21:21
Snippet from rspec-expectations showing failure due to usage of `public_send`
let(:proxy_class) do
Class.new(BasicObject) do
def initialize(target)
@target = target
end
def proxied?
true
end
@JonRowe
JonRowe / challenge_spec.rb
Created January 18, 2013 01:32
The Drag & Drop Challenge.... Can you automate this? I can't... Have tried: phantomjs, capybara-webkit, selenium (firefox & chrome)...
describe 'dragging and dropping', type: :js do
let(:manually) { page.driver.browser.action }
specify do
visit 'http://html5demos.com/drag'
find('#two').drag_to find('#bin')
#doesn't work so try...
@JonRowe
JonRowe / git_prompt.sh
Created September 4, 2012 12:03
Git branch prompt
__git_ps1 ()
{
local g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -n "$g" ]; then
local r
local b
if [ -d "$g/rebase-apply" ]
then
if test -f "$g/rebase-apply/rebasing"
then
@JonRowe
JonRowe / sketch.rb
Created June 29, 2012 16:04 — forked from mattwynne/sketch.rb
sketch for Matt Wynne
class Organization
def to_param
"42"
end
def saved?
rand > 0.5
end
end
class OrganizationResponder
$:.push File.expand_path '../../', __FILE__
module ActiveRecord
class RecordNotFound < StandardError; end
end
require 'action_controller'
require 'app/controllers/application_controller'
module ControllerSpecHelpers
@JonRowe
JonRowe / app-models-user.rb
Created March 15, 2012 15:20
Replicate problem with uniq associations
class User < ActiveRecord::Base
has_and_belongs_to_many :followers, :class_name=>'User', :foreign_key=>'follower_id', :association_foreign_key=>'user_id', :join_table=>'followers_users', :uniq=>true
has_and_belongs_to_many :followings, :class_name=>'User', :foreign_key=>'user_id', :association_foreign_key=>'follower_id', :join_table=>'followers_users', :uniq=>true
end
class Scanner
def initialize(display)
@display = display
end
def scan
@display.last_item = Item.new("Cornflakes")
end
end
Item = Struct.new(:name)
@JonRowe
JonRowe / gist:1351629
Created November 9, 2011 14:46
Devise stubs
def manually_sign_in(person)
controller.stub!(:current_user).and_return(person)
controller.stub!(:user_signed_in?).and_return(true)
controller.stub(:authenticate_user!).and_return(true)
end

Rubyists! SHRUG needs you!

The month, October, the year 2011, the battleground, the digital seas of Ruby. This month we're playing copy cat with LRUG again and facing off against each other in a contest of computerised wit, a.k.a Battleships!

Paul Battley, a.k.a threedaymonk has put together a game framework that allows Ruby bots to face-off against each other in the game of battleships, the challenge is to create yourself a bot capable of defeating it foes.

For those unfamiliar with the concept of battleships, each player has a 10x10 grid, and arranges upon that grid a fleet of 5 ships. Those 5 ships may be placed horizontally or vertically and are varying lengths (5,4,3,3 & 2). Players take turns at guessing where each others ships could be, noting hit and miss responses until the a players fleet is sunk.

Paul has written a few simple player classes to illustrate this, and a human player, so those wishing to compete should write a player class before the night and dependi

@JonRowe
JonRowe / webmock_synchrony_time_out_issue.rb
Created May 20, 2011 13:42
Proof of concept for fix for double fiber resume error with em-synchrony and webmock
require "em-synchrony"
require "em-synchrony/em-http"
require 'webmock'
include WebMock::API
stub_request(:get, "http://www.gooogle.com/").to_timeout
EM.synchrony do
# pass a callback enabled client to sync to automatically resume it when callback fires