Skip to content

Instantly share code, notes, and snippets.

@jamesu
Created July 4, 2011 13:32
Show Gist options
  • Save jamesu/1063338 to your computer and use it in GitHub Desktop.
Save jamesu/1063338 to your computer and use it in GitHub Desktop.
Need to find the BEST project on github? This will help!
#!/usr/bin/env ruby
# hubscore
# Scores a project on github based on keyword metrics.
# Higher score = faster/in fashion. Lower score = slower/out of date.
#
# Usage:
# hubscore socketstream/socketstream
#
require 'rubygems'
require 'open-uri'
require 'nokogiri'
WORD_SCORE = {
'redis' => 20,
'experimental' => 20,
'rapid' => 10,
'rails' => -10,
'rack' => 10,
'node' => 20,
'php' => -10,
'cakephp' => 20,
'mvc' => 30,
'ruby' => -5,
'javascript' => 10,
'js' => 10,
'coffeescript' => 5,
'websockets' => 5,
'speed' => 10
}
def score_project(name)
document = Nokogiri::HTML(open("https://www.github.com/#{name}")) rescue nil
if document.nil?
puts "Couldn't find project #{name}"
exit 0
end
input = document.css('#readme').first.content rescue nil
if input.nil?
puts "Invalid project #{name}"
exit 0
end
words = input.scan(/(\w+)/).map do |w|
(w[0]||'').downcase
end
score = 0
words.compact.uniq.each do |word|
score += WORD_SCORE[word]||0
end
score
end
if ARGV[0]
score = score_project(ARGV[0])
puts "Score: #{score}"
else
puts "Usage: hubscore <user>/<project>"
end
@saimonmoore
Copy link

you're missing 'nosql' in the word list ;)

@jamesu
Copy link
Author

jamesu commented Jul 4, 2011

nosql? of course!

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