Skip to content

Instantly share code, notes, and snippets.

@SamirTalwar
Last active October 3, 2020 08:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamirTalwar/f0fd3b23fb98a3ecf197 to your computer and use it in GitHub Desktop.
Save SamirTalwar/f0fd3b23fb98a3ecf197 to your computer and use it in GitHub Desktop.
A really simple command-line Ruby application, for https://monospacedmonologues.com/2016/02/docker-part-three-running-software/.
FROM ruby
RUN mkdir /app
WORKDIR /app
COPY Gemfile Gemfile
RUN bundle install
COPY google.rb google.rb
RUN chmod +x google.rb
ENTRYPOINT ["./google.rb"]
CMD ["docker"]
source 'https://rubygems.org'
gem 'nokogiri'
#!/usr/bin/env ruby
require 'cgi'
require 'nokogiri'
require 'open-uri'
query = ARGV[0]
html = open("https://google.com/search?q=#{CGI.escape(query)}") { |io|
Nokogiri::HTML(io)
}
results = html.css('.g')
results.each do |result|
header = result.at_css('h3')
puts header.text if header
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment