Skip to content

Instantly share code, notes, and snippets.

@cho45
Created November 24, 2011 11:13
Show Gist options
  • Save cho45/1391118 to your computer and use it in GitHub Desktop.
Save cho45/1391118 to your computer and use it in GitHub Desktop.
Gyazo.app
#!/usr/bin/env ruby
require 'fileutils'
require 'pathname'
require 'uri'
require 'net/http'
require 'securerandom'
Net::HTTP.version_1_2
include FileUtils
DROPBOX = Pathname.new("~/Dropbox/Public/Screenshots").expand_path
URLBASE = URI.parse("http://dl.dropbox.com/u/673746/Screenshots/")
tmpfile = "/tmp/image_upload#{$$}.png"
imagefile = ARGV[1]
if imagefile && File.exist?(imagefile)
system "sips", "-s", "format", "png", imagefile, "--out", tmpfile
else
system "screencapture", "-i", tmpfile
if File.exist?(tmpfile)
system "sips", "-d", "profile", "--deleteColorManagementProperties", tmpfile
end
end
if !File.exist?(tmpfile) then
exit
end
filename = "#{Time.now.strftime("%Y-%m-%d.%H-%M-%S")}.(#{SecureRandom.hex(10)}).png"
mv tmpfile, DROPBOX + filename
uri = URLBASE + URI.escape(filename)
try = 0
begin
sleep 1
res = Net::HTTP.start(uri.host, uri.port) {|http| http.get(uri.request_uri) }
case res.code
when "200"
# do nothing
when "404"
raise "Uploading"
else
warn "Unexpected Error: %s" % res.inspect
end
rescue
warn "Uploading..."
if try < 3
try += 1
retry
end
end
system "open", uri.to_s
@primalmotion
Copy link

great dude! thanks

@primalmotion
Copy link

I've added the auto pasteboard stuff here https://gist.github.com/1443935 if you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment