Skip to content

Instantly share code, notes, and snippets.

View JonathonMA's full-sized avatar

Jonathon M. Abbott JonathonMA

  • Brisbane, Australia
View GitHub Profile
#!/usr/bin/env ruby
# pingpongninja_expected_results -- simulate a series of games on pingpongninja
#
# algorithm extracted from
# https://github.com/jdennes/pingpongapp/blob/master/pingpong/rankings.py
def new_ranks(rank1, rank2, points1, points2)
decay_factor = 10
game_ranking_points = (rank1 + rank2) / 2
ranking_change1 = game_ranking_points + (points1 - points2) * 100 / [points1, points2].max
ranking_change2 = game_ranking_points + (points2 - points1) * 100 / [points1, points2].max
class Foo
class << self
def hello
"hello"
end
end
end
def singleton &block
singleton_class.class_eval &block
class Evaluator
def evaluate &block
instance_eval &block
end
def upcase bar
bar.upcase
end
end
module IPoint
attr_accessor :x, :y
end
module IReadonlyPoint
attr_reader :x, :y
end
module IReadonlyLine
attr_reader :source, :destination
time_range = Time.now .. Time.now
number_range = 1.0 .. 10.0
p time_range.cover? Time.now
p number_range.cover? 5.0
begin
time_range.to_a
rescue
puts "time_range is unenumerable"
require 'test_helper'
class MiniTestDoesntWorkWithUnenumerableRangesTest < ActiveSupport::TestCase
test ":(" do
period = Time.current - 1.week .. Time.current
mock = MiniTest::Mock.new
mock.expect :foo, true, [period]
mock.foo period
@JonathonMA
JonathonMA / i18n_fallbacks.rb
Created January 21, 2014 23:39
Rails I18n fallback experiment
require "i18n/backend/fallbacks"
I18n::Backend::Simple.send :include, I18n::Backend::Fallbacks
I18n.backend.store_translations :en, test: {
no_translations: {
specific: "en specific",
generic: "en generic",
},
only_generic_translations: {
source 'https://rubygems.org'
gem 'fruity', '~> 0.2.0'
gem 'rubyzip', '1.1.0'
gem 'zippo', '0.2.0'
@JonathonMA
JonathonMA / stubs_spec.rb
Created December 12, 2013 23:27
Demonstration of why checking your stub parameters is important if you value having.
class Collaborator
# not implemented yet because TDD!
end
class ThingThatDoesThings
def initialize name
@name = name
end
def do_thing with
require 'unicode_utils'
baffle = 'baffle'
puts baffle # => baffle
puts baffle.upcase # => BAfflE
puts UnicodeUtils.upcase(baffle) # => BAFFLE
noel = 'noël'