Skip to content

Instantly share code, notes, and snippets.

@gstark
Created May 19, 2015 19: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 gstark/8aba444b9d3ebdb55268 to your computer and use it in GitHub Desktop.
Save gstark/8aba444b9d3ebdb55268 to your computer and use it in GitHub Desktop.
Kittens in your terminal, how awesome!
require "base64"
require "open-uri"
def url_to_terminal_image(url)
raw_image = open(url).read
encoded_image = Base64.encode64(raw_image).gsub(/[\n\r]/,'')
"\033]1337;File=size=#{raw_image.length};inline=1:#{encoded_image}\a\n"
end
class Kitty
include Enumerable
def each
10.times do
width = 200 + rand(200)
height = 200 + rand(300)
url = "https://placekitten.com/g/#{width}/#{height}"
image = url_to_terminal_image(url)
yield image
end
end
end
kitty = Kitty.new
kitty.each do |image|
puts image
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment