Skip to content

Instantly share code, notes, and snippets.

@therabidbanana
Created July 5, 2010 15:24
Show Gist options
  • Save therabidbanana/464461 to your computer and use it in GitHub Desktop.
Save therabidbanana/464461 to your computer and use it in GitHub Desktop.
A script to copy dropbox review urls to clipboard
#!/usr/bin/env ruby
# dont change anything below, unless you know what are you doing
require 'fileutils'
require 'cgi'
require 'base64'
class DropboxThingy
DROPBOX_URL="http://review.orangesparkleball.com/"
def initialize
@dropbox_url = DROPBOX_URL
end
def process_files(filenames)
urls = []
filenames.each do |file|
urls << process_file(file)
end
return urls
end
private
# finds single review url
def process_file(filename)
basename = File.basename(filename) # just the name of file
dirs = File.dirname(filename).split('/').reverse
path = CGI::escape(basename).gsub( /\+/, '%20')
# Find all dirnames not == OSB Review
for dir in dirs
if dir == 'OSB Review'
break
else
dir = CGI::escape(dir).gsub( /\+/, '%20')
path = "#{dir}/#{path}"
end
end
# encoded filename
url = @dropbox_url + path
return url
end
end
dd = DropboxThingy.new
filenames = ARGV
urls = dd.process_files(filenames)
u = urls.join("\n" )
exec( "printf \"#{u}\" | pbcopy" ) # -n prevents newline being appended
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment