Skip to content

Instantly share code, notes, and snippets.

@toluju
Created January 1, 2010 06:15
Show Gist options
  • Save toluju/267061 to your computer and use it in GitHub Desktop.
Save toluju/267061 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'uri'
require 'json'
languages = ["java", "c++", "c", "perl", "ruby", "python", "javascript", "html", "css",
"scala", "xml", "xslt", "xquery", "php", "actionscript", "flash", "flex",
"vbscript", "applescript", "erlang", "objective-c", "smalltalk", "haskell",
"c#", "boo", "f#", "go", "processing", "arduino", "pd", "qc", "vimscript",
"as3", "assembly", "sh", "obj-c", "sql", "coldfusion", "lex", "yacc",
"scheme", "lisp", "bourne", "awk", "tcl", "d", "ocaml", "elisp", "clojure",
"bash", "noop", "wix", "rdl", "javafx", "groovy", "abap", "sml", "asp.net",
"asp", "visualbasic", "basic", "shell", "matlab", "hql", "rhino", "rebol",
"forth", "cocoa", "awk", "sed", "vb.net", "vb", "lua", "delphi", "fortran"]
counts = {}
languages.each { |w| counts[w] = 0 }
(1..15).each { |i|
response = Net::HTTP.get(URI.parse("http://search.twitter.com/search.json?q=%23code2009&rpp=100&page=#{i}"))
json = JSON.parse response
json['results'].each { |r|
text = r['text'].gsub(/\(.*?\)/, '')
text.downcase.split(%r{,?\s+}).each { |w|
if w[0] == ?#
w = w[1, w.length]
end
if w[-1] == ?. or w[-1] == ?,
w = w[0, w.length - 1]
end
if languages.include?(w)
counts[w] = counts[w] + 1
end
}
}
}
counts.sort {|a,b| b[1] <=> a[1]}.each { |key, value| puts "#{key}: #{value}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment