Skip to content

Instantly share code, notes, and snippets.

@toshia
Created December 24, 2014 13:02
Show Gist options
  • Select an option

  • Save toshia/245f9857c990c8914ae3 to your computer and use it in GitHub Desktop.

Select an option

Save toshia/245f9857c990c8914ae3 to your computer and use it in GitHub Desktop.
やめるやめる詐欺
# twitpic
defimageopener('twitpic', %r<^http://twitpic\.com/[a-zA-Z0-9]+>) do |display_url|
connection = HTTPClient.new
page = connection.get_content(display_url)
next nil if page.empty?
doc = Nokogiri::HTML(page)
result = doc.css('img').lazy.find_all{ |dom|
%r<https?://.*?\.cloudfront\.net/photos/(?:large|full)/.*> =~ dom.attribute('src')
}.first
open(result.attribute('src'))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment