Skip to content

Instantly share code, notes, and snippets.

@gwang
Last active August 9, 2016 19:41
Show Gist options
  • Save gwang/c58158065b0c033fc40bfaa5c9f037e2 to your computer and use it in GitHub Desktop.
Save gwang/c58158065b0c033fc40bfaa5c9f037e2 to your computer and use it in GitHub Desktop.
Search your gist host on gist.github.com
require 'open-uri'
require 'open_uri_redirections'
require 'certified'
require 'json'
require 'pp'
USERNAME = 'gwang'
query = ARGV.first.downcase
# gists = JSON.parse(open("http://gist.github.com/api/v1/json/gists/#{USERNAME}", :allow_redirections => :all).read)['gists']
url = "https://api.github.com/users/#{USERNAME}/gists"
#gists = JSON.parse(open(url, :allow_redirections => :all).read)['gists']
gists = JSON.parse(open(url, :allow_redirections => :all).read)
gists.each do |gist|
#pp gist['files']
#files = "(%s)" % gist['files'].join(', ')
files = "(%s)" % gist['files'].keys.join(', ')
description = gist['description']
#pp description
#pp files
unless description.to_s.downcase.include?(query) || files.downcase.include?(query)
next
end
puts description if description
puts files
pp gist.keys
#puts "https://gist.github.com/gists/#{gist['repo']}"
pp gist['html_url']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment