Skip to content

Instantly share code, notes, and snippets.

View jarib's full-sized avatar

Jari Bakken jarib

View GitHub Profile
@jarib
jarib / myfile.rb
Created January 26, 2010 22:02
YARD issue #72
module A
class B
end
class Object < B
end
end
>> require 'socket'
=> true
>> TCPServer.new "localhost", 5000
=> #<TCPServer:0x100568370>
>> TCPServer.new "localhost", 5000
=> #<TCPServer:0x100530970>
>> TCPServer.new "localhost", 5000
=> #<TCPServer:0x10050e5c8>
>> TCPServer.new "localhost", 5000
Errno::EADDRINUSE: Address already in use - bind(2)
>> s = []; i = 0; loop { s << TCPServer.new("localhost", 5000); p i+=1 }
1
2
3
Errno::EADDRINUSE: Address already in use - bind(2)
from (irb):3:in `initialize'
from (irb):3:in `new'
from (irb):3
from (irb):3:in `loop'
from (irb):3
$ cat bug.rb
require "socket"
s, i = [], 0
loop do
s << TCPServer.new("localhost", 5000)
p i += 1
sleep 1
end
$ cat bug.rb
require "socket"
s, i = [], 0
loop do
s << TCPServer.new("localhost", 5000)
p i += 1
sleep 1
end
$ cat bug.rb
require "socket"
loop do
s = TCPServer.new("localhost", 5000)
p s => Socket.unpack_sockaddr_in(s.getsockname)
end
$ ruby bug.rb
{#<TCPServer:0x100154950>=>[5000, "::1"]}
@jarib
jarib / wait.rb
Created February 16, 2010 22:50
wait in selenium-webdriver
#!/usr/bin/env ruby
require "rubygems"
require "selenium-webdriver"
module Wait
extend self
def until(timeout = 10)
end_time = Time.now + timeout
$ echo "æåø" > test.txt
$ file test.txt
test.txt: UTF-8 Unicode text
$ echo "æåø" |iconv -t iso-8859-1 >> test.txt
$ file test.txt
test.txt: ISO-8859 text
$ cat test.txt
æåø
???
$
@jarib
jarib / wd.rb
Created February 23, 2010 22:25
require "rubygems"
require "selenium-webdriver"
d = Selenium::WebDriver.for :firefox
d.get "http://google.com"
p d.find_element(:css => 'div')
d.quit
We couldn’t find that file to show.