15 10 / 2014

It all started with looking at a text only loader for a Linux package on the terminal, and ended in a heart warming video about a rescue operation, written purely in ruby! No this isn’t a clickbait, but you need to execute (see) it to believe it ;)

Below are some cool Ruby one liners : “text only loader/processing/progress indicators” && “some FUN”

# Loader for infinite time
["|", "/", "-", "\\"].each{|v| STDOUT.write "\r#{v}"; sleep 0.5} while 1
# In case you want to run it for a few seconds (~ 20s in the example below)
10.times{ ["|", "/", "-", "\\"].each{|v| STDOUT.write "\r#{v}"; sleep 0.5} }
# Progress Bar
100.times{STDOUT.write "|"; sleep 0.1}
# Another kind of loading indicator
(f=rand(20); STDOUT.write "\r#{'|'*f}#{'#'*15}#{'|'*(20-f)}"; sleep 0.5) while 1
# Dog drowning in sea waves ;)
(f=rand(10); STDOUT.write "\r#{'~'*f}^o^#{'~'*(20-f)}"; sleep 0.5) while 1
# Travelling ship =P
101.times{ |i| STDOUT.write "\r#{'~'*i}\\____/#{'~'*(100-i)}"; sleep 0.2 }
# Ship rescuing the dog =) #heartWarmingStory
75.times{ |i| f=rand(17); STDOUT.write "\r#{'~'*f}^o^#{'~'*(17-f)}#{'~'*(75-i)}\\___/#{'~'*i}"; sleep 0.2 }; STDOUT.write "\r#{'~'*17}^o^\\___/#{'~'*75}"; sleep 2; 20.times{ |i| STDOUT.write "\r#{'~'*(19-i)}\\___/#{'~'*(i+76)}"; sleep 0.2 }
view raw gistfile1.rb hosted with ❤ by GitHub

Share yours in the comment section! Do you have a better story to tell?

Posted by @amitsxena

Comments