Skip to content

Instantly share code, notes, and snippets.

@mindreframer
Created January 8, 2013 12:34
Show Gist options
  • Save mindreframer/4483382 to your computer and use it in GitHub Desktop.
Save mindreframer/4483382 to your computer and use it in GitHub Desktop.
somebody's starred projects
require 'dbm'
require 'github_api'
class Cache
attr_accessor :db
def initialize
@db = DBM.open('starred', 666, DBM::WRCREAT)
end
def load(key)
if data = @db[key]
Marshal.load(data)
end
end
def store(key, value)
return unless value
db[key] = Marshal.dump(value)
end
end
CACHE = Cache.new
def get_cached(page)
user = "some_user"
key = "stared_#{user}_#{page}"
if r = CACHE.load(key)
return r
else
r = Github.activity.starring.starred(:user => user, :page => page)
CACHE.store(key, r)
return r
end
end
def print_project(project)
puts "-- " * 20
puts "#{project.name.ljust(30)} #{project.url}"
puts "#{project.description}"
end
def show_page(num)
get_cached(num).each do |p|
print_project(p)
end; nil
end
def fetch_pages(num)
num.times do |i|
show_page(i+1)
end
end
fetch_pages(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment