Created
July 7, 2010 13:19
-
-
Save alvin2ye/466673 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://gist.github.com/466673 | |
# upload your file to tu.6.cn | |
# short url by tinyurl | |
# copy the url to you clipboard | |
require 'rubygems' | |
require "win32/clipboard" | |
include Win32 | |
$filename = ARGV[0] | |
TYPES = %w{.jpg .gif .png .jpeg} | |
def upload_file(file) | |
puts "Your want to upload file #{$filename}" | |
cmd = "curl -s -F Filedata=@\"#{$filename}\" -F Filename=\"#{File.basename(file)}\" -F Upload=\"Submit Query\" tu.6.cn/flash/index/tu_user_temp/-5073549" | |
res = `#{cmd}` | |
res =~ /(.+?):::/ | |
$1.gsub(/\.nail/, "") | |
end | |
def file_ext_allow?(file) | |
TYPES.include?(File.extname(file).downcase) | |
end | |
def short_url(url) | |
cmd = "curl -s http://tinyurl.com/api-create.php?url=#{url}" | |
`#{cmd}` | |
end | |
if File.exists?($filename) && file_ext_allow?($filename) | |
url = upload_file(ARGV[0]) | |
url = short_url(url) | |
Clipboard.set_data(url) | |
puts url | |
puts "Tt is in you clipboard" | |
else | |
puts "File not exist / File is ext name must in #{TYPES.join(",")}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment