Skip to content

Instantly share code, notes, and snippets.

@rwilcox
Created June 11, 2014 20:46
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 rwilcox/a787b9a8a139dcb0f674 to your computer and use it in GitHub Desktop.
Save rwilcox/a787b9a8a139dcb0f674 to your computer and use it in GitHub Desktop.
show a random AAWWWWWW image in your favorite editor (bbedit)
#!/usr/bin/env ruby
# FOR MAX EFFECTIVENESS:
# Put in ~/(Dropbox or Library)/Application Support/BBEdit/Scripts
require 'net/http'
require 'json'
http = Net::HTTP.new('www.reddit.com')
response = http.request(Net::HTTP::Get.new("/r/aww.json"))
json = JSON.parse(response.body)
if json['data']['children'].count <= 0
#send_event('aww', image: placeholder)
our_path = "http://img1.wikia.nocookie.net/__cb20130517022805/witch/images/9/97/Nyantocat.gif"
else
urls = json['data']['children'].map{|child| child['data']['url'] }
# Ensure we're linking directly to an image, not a gallery etc.
valid_urls = urls.select{|url| url.downcase.end_with?('png', 'gif', 'jpg', 'jpeg')}
our_path = valid_urls.sample(1).first
end
File.write("/tmp/bb_aww.png", Net::HTTP.get(URI.parse(our_path)))
`/usr/bin/osascript -e 'tell application \"BBEdit\" to open POSIX file \"/tmp/bb_aww.png\"'`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment