Skip to content

Instantly share code, notes, and snippets.

@dillonhafer
Created November 19, 2014 06:44
Show Gist options
  • Save dillonhafer/eb308809148dcaa7f28d to your computer and use it in GitHub Desktop.
Save dillonhafer/eb308809148dcaa7f28d to your computer and use it in GitHub Desktop.
Emoji spinner in ruby

You can display a spinning clock while performing network tasks.

puts "Starting nmap scan..."
scan_results = ""
spin_during {
  scan_results = %x(nmap -Pn dillonhafer.com)
}
puts scan_results
def spin_during
clocks = %w(πŸ•› πŸ• πŸ•‘ πŸ•’ πŸ•“ πŸ•” πŸ•• πŸ•– πŸ•— πŸ•˜ πŸ•™ πŸ•š)
working = 0
timer = Thread.new do
while working do
print clocks[(working+=1) % clocks.length]+' '
sleep 0.1
print "\b\b"
end
end
yield.tap{
working = false
timer.join
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment