Skip to content

Instantly share code, notes, and snippets.

View JonRowe's full-sized avatar
💭
⛵️

Jon Rowe JonRowe

💭
⛵️
View GitHub Profile
@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
if expand('%') =~# '_spec\.rb$'
syn keyword rubyRspec describe context it specify it_should_behave_like before after setup subject its shared_examples_for shared_context let
endif
hi def link rubyRspec Function
@JonRowe
JonRowe / embedded_document_problem_spec.rb
Created February 2, 2011 16:30
embedded_document_problem_spec.rb
require 'spec_helper'
class Thing
include Mongoid::Document
field :name
embedded_in :person, inverse_of: :things
end
@JonRowe
JonRowe / .autotest
Created January 14, 2011 15:40
A generic rails .autotest mappings file
egin
require 'autotest/fsevent'
rescue LoadError
end
Autotest.add_hook :initialize do |at|
at.add_mapping(/^spec\/**\/*_spec\.rb$/, true){ |filename, _|
filename
}
@JonRowe
JonRowe / async_rack_cache.rb
Created December 16, 2010 16:40
Async rack cache monkey patch.... use with caution
require 'async-rack'
require 'rack/cache'
module Rack::Cache
class Context
include AsyncRack::AsyncCallback::Mixin
def async_callback(result)
response = Response.new(*result)
@request ||= Request.new(env.dup.freeze)
store response if response.cacheable?
@JonRowe
JonRowe / rspec_core_230_patch_jonrowe_14122010.diff
Created December 14, 2010 15:08
RSpec-Core 2.3.0 autotest failed spec regular expression fix for colour
From fa82095f0928decfeead82341959d7e451fd16aa Mon Sep 17 00:00:00 2001
From: Jon Rowe <mail@jonrowe.co.uk>
Date: Tue, 14 Dec 2010 15:01:10 +0000
Subject: [PATCH] add spec for checking coloured output and regular expression that matches both coloured and non coloured output
---
lib/autotest/rspec2.rb | 2 +-
spec/autotest/failed_results_re_spec.rb | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletions(-)