Skip to content

Instantly share code, notes, and snippets.

@jooeycheng
Last active October 26, 2017 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jooeycheng/e962e567ca1527a55c953727d575634b to your computer and use it in GitHub Desktop.
Save jooeycheng/e962e567ca1527a55c953727d575634b to your computer and use it in GitHub Desktop.
Ruby auto-restart script for localtunnel
# https://github.com/localtunnel/localtunnel/issues/81#issuecomment-218320442
# usage: ruby localtunnel.rb --port 3000 --subdomain yourdomainhere
require 'optparse'
options = { subdomain: 'defaultdomain', port: 3000 }
parser = OptionParser.new do |opts|
opts.banner = 'Usage: localtunnel.rb [options]'
opts.on('-s', '--subdomain subdomain', 'Subdomain') do |subdomain|
options[:subdomain] = subdomain
end
opts.on('-p', '--port port', 'Port') do |port|
options[:port] = port
end
opts.on('-h', '--help', 'Displays Help') do
puts opts
exit
end
end
parser.parse!
def ordinal(number)
abs_number = number.to_i.abs
if (11..13).cover?(abs_number % 100)
'th'
else
case abs_number % 10
when 1 then 'st'
when 2 then 'nd'
when 3 then 'rd'
else 'th'
end
end
end
def ordinalize(number)
"#{number}#{ordinal(number)}"
end
launch_count = 0
while true
launch_count += 1
puts "Running localtunnel for the #{ordinalize(launch_count)} time on https://#{options[:subdomain]}.localtunnel.me, port #{options[:port]}"
`lt --port #{options[:port]} --subdomain #{options[:subdomain]}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment