This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# A Custom Matcher for RSpec that shows the difference between two multi-line strings. | |
# Author: Clifford Heath. | |
# Usage: | |
# actual_text.should_not differ_from(expected_text) | |
# | |
require 'diff/lcs' | |
module FileMatcher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aget "/notifications/:n" do |n| | |
channel = $channels[n] and | |
subscription = channel.subscribe { |msg| | |
body(msg) | |
} | |
on_close { channel.unsubscribe(subscription) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar PivotalStories | |
rule stories | |
story* | |
end | |
rule story | |
story_label:one_line "\n" feature* | |
end | |
rule feature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'rubygems' | |
require 'hpricot' | |
require 'open-uri' | |
site = "http://www.tomwaits.com" | |
download_to = "/Users/gus/tmp/" | |
index = open(site + "/songs/") { |f| Hpricot(f) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RSpec | |
module Matchers | |
class ArrayMatcher < Matcher | |
def initialize expected | |
super(:be_different_array_from, expected) do |*_expected| | |
match_for_should do |actual| | |
perform_match(actual, _expected[0]) | |
@extra + @missing != [] | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :video do | |
desc "Create a bunch of sent messages to test reporting & analytics, with random contacts" | |
task :transcode do | |
Dir["*.mov"].each do |mov| | |
# REVISIT: Get width and height from the video: | |
width = 568 | |
height = 386 | |
ogv = mov.sub(%r{.mov}i, '.ogv') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# ScopeVariables is a collection of utility methods to access variables | |
# relative to a specific Proc or Binding. It allows getting and assigning | |
# local variables in a method which passed us a block, for example: | |
# | |
# def monkey &block | |
# block.var_set("v1", "goodbye") | |
# end | |
# | |
# class Test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
# | |
# This code works (or fails!) differently on MRI, Rubinius and JRuby, | |
# also depending on whether the Fixnum monkey-patches are included. | |
# Note that the patches exist to apply a to_i to the parameter of Fixnum@eql? | |
# | |
# If Ruby's Hash claims to use only "hash" and "eql?" to store and find | |
# items, why can't the Ruby interpreters agree on *how*? | |
# | |
# In particular: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Capybara | |
class << self | |
attr_accessor :default_wait_time | |
def magic(a,&b) | |
puts "doing magic for #{a}" | |
yield | |
puts "mischief managed" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object.flash3times = function() { | |
object.attr({fill: "#FF0"}); | |
var times = 3; | |
var flashMore = function() { | |
// Make it go dim: | |
object.attr({fill: "#CC0"}); | |
if (--times > 0) | |
setTimeout(function() { | |
object.attr({fill: "#FF0"}); |
OlderNewer