Skip to content

Instantly share code, notes, and snippets.

@doughsay
Created October 2, 2014 21:49
Show Gist options
  • Save doughsay/4989697f2f2877991d22 to your computer and use it in GitHub Desktop.
Save doughsay/4989697f2f2877991d22 to your computer and use it in GitHub Desktop.
Continuously listen for remote-pry sessions.
require 'socket'
require 'timeout'
def is_port_open?(ip, port)
begin
Timeout::timeout(1) do
begin
s = TCPSocket.new(ip, port)
s.close
return true
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
return false
end
end
rescue Timeout::Error
end
return false
end
puts 'Waiting for remote pry session to be available on port 9876'
while true do
if is_port_open?('127.0.0.1', 9876)
system('pry-remote')
puts 'Waiting for remote pry session to be available on port 9876'
else
sleep 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment