Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Created April 2, 2011 18:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ttscoff/899757 to your computer and use it in GitHub Desktop.
Save ttscoff/899757 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
%w[fileutils ftools set zlib].each do |filename|
require filename
end
# Load the Marshal dump to a hash
def load file_name
begin
file = Zlib::GzipReader.open(file_name)
rescue Zlib::GzipFile::Error
file = File.open(file_name, 'r')
ensure
obj = Marshal.load file.read
file.close
return obj
end
end
HOME_DIR = ENV['HOME']
DB_LOCATION = "#{HOME_DIR}/Dropbox/Sync/Bookmark"
obj = load(DB_LOCATION + "/bookmarks.stash")
tag = 'presentation'
bookmarks = []
obj.each {|bookmark|
if bookmark['tag'] =~ /\b#{tag}\b/i
bookmarks << {
'title' => bookmark['description'],
'url' => bookmark['href']
}
end unless bookmark['tag'].nil?
}
puts "<ul>"
bookmarks.each{|bookmark|
puts %Q{<li><a href="#{bookmark['url']}">#{bookmark['title']}</a></li>}
}
puts "</ul>"
# wanted_keys = %w[presentation]
# p bookmarks.reject { |bookmark| !wanted_keys.include? bookmark['tag'] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment