Skip to content

Instantly share code, notes, and snippets.

@citizen428
Created June 9, 2010 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save citizen428/432255 to your computer and use it in GitHub Desktop.
Save citizen428/432255 to your computer and use it in GitHub Desktop.
require 'httparty'
class GitHub
include HTTParty
base_uri 'http://github.com/api/v2/yaml'
API_METHODS = {
:watched => '/repos/watched/' }
class << self
def show_watched
@user = ARGV[0] || 'citizen428'
get_watched_repos.shuffle.reject{ |r| r[:owner] == @user }.each do |r|
puts "%30s: %-55s (%d)" %
["#{r[:owner]}/#{r[:name]}", shorten_desc(r[:description]), r[:watchers]]
end
end
private
def get_watched_repos
self.get(API_METHODS[:watched]+@user)["repositories"]
end
def shorten_desc(str)
str.length < 50 ? str : str[0..49]+'...'
end
end
end
GitHub.show_watched
@kotp
Copy link

kotp commented Jan 27, 2012

str.length < 50 ? str : str[0..49]+'...'

I had a bug come out on this

Fixed it with

(str.nil? ? 0 : str.length) < 50 ? str : str[0..49]+'...'

@citizen428
Copy link
Author

How about this?

(str && str.length < 50) ? str : str[0..49]+'...'

@kotp
Copy link

kotp commented Jan 27, 2012

I thought about that, but thought it might require a second look later to remember why.

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