sudo gem install --no-rdoc --no-ri --version 2.3.4 rails
The blog has moved to http://jessehouse.com/ ... Many google searches point here so I am leaving it operational, but there will be no new posts.
Tuesday, January 26, 2010
install older version of rails and without the docs
I always forget these
Labels:
rails
Monday, January 18, 2010
Neat site to generate graphics
I needed to generate a sign up button - this site is so much easier than opening photoshop
Thanks cooltext!
Wednesday, January 6, 2010
Ruby Http Get with Net::HTTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'uri' | |
def get_html_content(requested_url) | |
url = URI.parse(requested_url) | |
full_path = (url.query.blank?) ? url.path : "#{url.path}?#{url.query}" | |
the_request = Net::HTTP::Get.new(full_path) | |
the_response = Net::HTTP.start(url.host, url.port) { |http| | |
http.request(the_request) | |
} | |
raise "Response was not 200, response was #{the_response.code}" if the_response.code != "200" | |
return the_response.body | |
end | |
# this will fail with ArgumentError: HTTP request path is empty | |
s = get_html_content("http://www.google.com") | |
# these should be fine | |
s = get_html_content("http://www.google.com/") | |
s = get_html_content("http://github.com/search?q=http") | |
# above code does not handle redirects but raises exception for non-200 | |
s = get_html_content("http://www.yahoo.com/") # http 302 | |
Resources
require 'net/http'
require 'uri'
def get_html_content(requested_url)
url = URI.parse(requested_url)
full_path = (url.query.blank?) ? url.path : "#{url.path}?#{url.query}"
the_request = Net::HTTP::Get.new(full_path)
the_response = Net::HTTP.start(url.host, url.port) { |http|
http.request(the_request)
}
raise "Response was not 200, response was #{the_response.code}" if the_response.code != "200"
return the_response.body
end
# this will fail with ArgumentError: HTTP request path is empty
s = get_html_content("http://www.google.com")
# these should be fine
s = get_html_content("http://www.google.com/")
s = get_html_content("http://github.com/search?q=http")
# above code does not handle redirects but raises exception for non-200
s = get_html_content("http://www.yahoo.com/") # http 302
Labels:
ruby
Ruby Regex to remove script tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# remove all script tags | |
html_content = html_content.gsub(/<script.*?>[\s\S]*<\/script>/i, "") |
Resources
Subscribe to:
Posts (Atom)