Skip to content

Instantly share code, notes, and snippets.

View lazyatom's full-sized avatar
🤠
Yes

James Adam lazyatom

🤠
Yes
View GitHub Profile
@lazyatom
lazyatom / anonimise_selections.sql
Created March 14, 2013 13:26
Ruby Manor 4.0 voting - anonymised
select substring(md5(<first salt> || proposal_id) for 8) as proposal_hash, substring(md5(<second salt> || user_id) for 8) as user_hash from selections;
@lazyatom
lazyatom / thing.rb
Last active December 12, 2015 00:18
Is this a pattern? Does it have a name? It allow swapping out basically the whole behaviour of the `Thing`.
class Thing
def self.runner=(custom_runner)
@runner = custom_runner
end
def self.runner
@runner ||= new
end
def run(*args)
@lazyatom
lazyatom / test.rb
Created January 29, 2013 10:51
An example of action usage in Kintama
describe ThingController do
describe "creating a thing" do
action { post :create, attributes }
describe "when not logged in" do
it "should redirect to login" do
assert_redirected_to login_path
end
end
@lazyatom
lazyatom / Output.md
Last active December 11, 2015 21:09
There's no way to definitively run a single test using MiniTest as it currently stands.

(Here's my proposed fix for this)

First, print out the test names:

$ ruby minitest.rb -v                 
Run options: -v --seed 58440

# Running tests:

AnotherTest#test_something = 0.00 s = F

@lazyatom
lazyatom / literate_kintama.rb
Created November 21, 2012 18:37
An example of using kintama to run tests while some things are being defined
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
ENV["KINTAMA_EXPLICITLY_DONT_RUN"] = "true"
at_exit { $reporter.show_final_results }
require 'kintama'
$contexts = []
class TomReporter < Kintama::Reporter::Inline
def show_final_results
puts
puts test_summary
@lazyatom
lazyatom / indenting.rb
Created August 10, 2012 13:34
indenting styles
a_really_long_method_name_with_arguments "looks weird",
{if: "they are indented"}
"like this"
but_a_shorter_one "doesn't look",
"quite as weird"
it_also_depends_on "how long", "the arguments", "are"
and_how_many_arguments(
@lazyatom
lazyatom / output
Created July 26, 2012 12:28
Testing Harmonia's fairness algorithm
{"blog"=>{"Alice"=>2422, "Bob"=>2542, "Clare"=>2503, "Dave"=>2533},
"invoice"=>{"Alice"=>2504, "Bob"=>2493, "Clare"=>2535, "Dave"=>2468},
"fire_log"=>{"Alice"=>2488, "Bob"=>2500, "Clare"=>2479, "Dave"=>2533}}
@lazyatom
lazyatom / convert_image_to_bytes.rb
Created July 11, 2012 22:08
Small script to convert an image to printer commands, based on http://github.com/freerange/printer
#!/usr/bin/env ruby
# You should ensure that the `rmagick` and `a2_printer` gems are installed.
require "rubygems"
require "RMagick"
require "a2_printer"
if ARGV.length < 2
puts "Usage: convert_image_to_bytes.rb <image_file> <output_file>"
@lazyatom
lazyatom / 0-readme.md
Created June 13, 2012 19:15 — forked from sj26/0-readme.md
ruby-1.9.3-p194 cumulative performance patch.

Patched ruby 1.9.3-p194 for 30% faster rails boot

What is?

This script installs a patched version of ruby 1.9.3-p194 with patches for boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84). It also includes the new backported GC from ruby-trunk.

Huge thanks to funny-falcon for the performance patches.

@lazyatom
lazyatom / git-mate
Created June 8, 2012 09:28
Open all files with changes in TextMate
#!/usr/bin/env ruby
git_changes = `git status --porcelain | awk '{print $2}'`
files = []
git_changes.split.each do |file|
if File.directory?(file)
files += Dir["#{file}**/*"]
else
files << file
end