Skip to content

Instantly share code, notes, and snippets.

@jimweirich
jimweirich / rock.rb
Created November 9, 2012 23:04
Ruby in Flight - Rock the Cradle
require 'argus'
# Video at: http://youtu.be/6V7hTH35xWw
drone = Argus::Drone.new
drone.start
drone.take_off
sleep 5
2.times do
drone.left(0.3)
@jimweirich
jimweirich / wag_the_dog.rb
Created November 8, 2012 21:00
Ruby Trivia
class Dog
def wag(tail=my_tail)
tail
end
def my_tail
:dogs_tail
end
end
class Cat
@jimweirich
jimweirich / ruby_flight2.rb
Created November 7, 2012 21:36
Flying the Parrot AR Drone via Ruby code
# See a video of this at: http://www.youtube.com/watch?v=jlKt2Ed-Y04&feature=youtu.be
require 'ardrone'
drone = ARDrone::Drone.new
drone.start
drone.take_off
sleep 5
drone.turn_right(1.0)
@jimweirich
jimweirich / shell_and_rake.log
Created November 7, 2012 05:16
Error compiling Rubinius under rvm.
$ rvm install rbx --1.9
rbx-head installing #dependencies
Cleaning git repo
Fetching from origin
Pulling from origin master
Copying from repo to source...
rbx-head - #configuring
rbx-head - #compiling
Error running 'env CONFIGURE_ARGS=--with-libyaml-dir=/Users/jim/.rvm/usr /Users/jim/.rvm/wrappers/ruby-1.8.6-p420/rake install --trace', please read /Users/jim/.rvm/log/rbx-head/rake.log
There has been an error while running 'CONFIGURE_ARGS=--with-libyaml-dir=/Users/jim/.rvm/usr /Users/jim/.rvm/wrappers/ruby-1.8.6-p420/rake install --trace'.
@jimweirich
jimweirich / take_off_and_land.rb
Created November 6, 2012 20:20
Ruby control of an Parrot AR Drone
# See video at: http://www.youtube.com/watch?v=3NlYGn3QY4U&feature=youtu.be
require 'socket'
class ATCommand
def initialize(socket, host=nil)
@host = host || '192.168.1.1'
@socket = socket
@tick = 0
@buffer = ""
@jimweirich
jimweirich / nc-twitterers.rb
Created November 5, 2012 22:18
Data Havesters for twitter names
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
# Note: Some of these haven't filled out the who's who page yet
MISSING = %w(codingbull ericries flngn giffco JeetKunDoug Joi kattrali kEND rabble tappythebird)
updating = ARGV.include?("--update")
@jimweirich
jimweirich / dual_spec.rb
Created September 17, 2012 17:51
Experiment using two different mocking frameworks
require 'flexmock/dual'
RSpec.configure do |config|
config.mock_with FlexMock.flexmock_and(:rspec)
end
describe "Dual Mocking" do
before do
@rm = mock("with rspec")
@rm.should_receive(:foo)
@jimweirich
jimweirich / gist:3729476
Created September 15, 2012 19:50
Seems to work
$ ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin11.2.0]
$ irb
>> RUBY_VERSION
=> "1.8.7"
>> p = lambda { |*args, &block| puts [args, block].inspect }
=> #<Proc:0x000000010b97b678@(irb):2>
>> p.call(1,2,3) { :hi }
[[1, 2, 3], #<Proc:0x000000010b94bef0@(irb):3>]
@jimweirich
jimweirich / temp2.rb
Created September 13, 2012 20:43 — forked from jredville/temp2.rb
describe Stack do
# Suggested Syntax...
Invariants do
If { stack.empty? }
Then { stack.depth.should == 0 }
Then { stack.should be_pushable }
ElseIf { stack.full? }
Then { stack.depth.should == stack.max_depth }
Then { stack.should_not be_pushable }
@jimweirich
jimweirich / and_example_spec.rb
Created September 12, 2012 12:17
Description of the "And" Experimental feature for RSpec/Given (was "Also")
# Experimental And Clauses
#
# I've been thinking about tests where there are multiple Thens
# in a single context. All the Givens and before blocks are run
# for each Then. Since Then's are idempotent, that seems to be a waste.
#
# Maybe we can introduce And clauses. They are like Then clauses, but
# they reuse the Givens of an existing Then clause. This could make a
# difference in spec that have expensive setups.
#