Skip to content

Instantly share code, notes, and snippets.

def scrape
require 'nokogiri'
require 'open-uri'
# keyword = "nokogiri is my favorite"
# domain = "tenderlovemaking.com"
keyword = self.text.split.join("+")
domain = self.website.url
user_agent = get_random_user_agent
@danneu
danneu / ruby_koans_151_solution.rb
Created August 4, 2011 22:09
Ruby Koans 151 triangle.rb solution
def triangle(a, b, c)
raise TriangleError if a<=0 or b<=0 or c<=0
raise TriangleError if a+b<=c or b+c<=a or a+c<=b
return :equilateral if a==b and a==c
return :isosceles if a==b or b==c or a==c
:scalene
end
require 'open-uri'
require 'nokogiri'
zipcode = ARGV[0] || 78705
url = "http://www.weather.com/weather/hourbyhour/graph/#{zipcode}"
doc = Nokogiri::HTML(open(url))
raise('Zipcode not found') if /can't find the page you requested/ =~ doc.text
hours = doc.css('.hbhWxHour')
hours.each do |hour|
<%= form_tag registration_index_path do %>
<%= fields_for User.new do |u| %>
<%= u.label :phone %>
<%= u.text_field :phone %>
<% end %>
<p>
<%= label_tag :workout %>
<%= check_box_tag :workout %>
</p>
<p>
tail -f log/development.log | grep -vE "(^\s*$|asset)"
# Better way to write this?
module TopicsHelper
def tags_for(topic)
tags = ""
topic.tags.each do |tag|
tags << content_tag(:span, tag.name)
end
tags.html_safe
end
@danneu
danneu / home
Created February 21, 2012 01:02 — forked from anonymous/home
home
<% @posts.each do |post|%>
<div id="recentpost">
<%= post.name %><br/><br/>
</div>
<% end %>
def urlToString(url)
require 'net/http'
uri = URI(url)
data = Net::HTTP.get(uri)
return data
end
def writeToFile(image_url)
require 'open-uri'
file_name = image_url[0][31..48]
# navigating to /sitemap.xml for the first time:
Start GET "/sitemap.xml" for 127.0.0.1
Processing by SitemapsController#index as XML
Post Load (1.2ms) ...
Category Load (0.7ms) ...
...
Renderedsitemaps/index.xml.builder (1231.4ms)
Write page /sandbox/public/sitemap.xml (19.5ms)
Completed 200 OK in 2301ms (Views: 1523.8ms | ActiveRecord: 31.7ms)
upstream unicorn {
server unix:/tmp/unicorn.blog.sock fail_timeout=0;
}
server {
listen 80 default deferred;
# server_name example.com;
root /home/deployer/apps/blog/current/public;
location ^~ /assets/ {