Skip to content

Instantly share code, notes, and snippets.

@jbpotonnier
Created June 14, 2012 23:14
Show Gist options
  • Save jbpotonnier/2933598 to your computer and use it in GitHub Desktop.
Save jbpotonnier/2933598 to your computer and use it in GitHub Desktop.
Grep in gist description and display url
require 'net/http'
require 'uri'
require 'json'
def github(*list)
URI('https://api.github.com/' + list.join('/'))
end
def get(uri)
request = Net::HTTP::Get.new uri.request_uri
Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
JSON::parse http.request(request).body
end
end
def find_gists(user)
get github 'users', user, 'gists'
end
def grep(user, arg)
gists = find_gists(user)
gists.select {|g| g['description'] =~ /#{arg}/}.map {|g| "- #{g['html_url']} : \n #{g['description']}" }
end
user = ARGV[0]
arg = ARGV[1]
puts grep(user, arg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment