Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan danneu

  • Texas
View GitHub Profile
View google-scraper.rb
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 Aug 4, 2011
Ruby Koans 151 triangle.rb solution
View ruby_koans_151_solution.rb
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
View gist:1428374
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|
View new.html.erb
<%= 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>
View gist:1683586
tail -f log/development.log | grep -vE "(^\s*$|asset)"
View gist:1750191
# 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 Feb 21, 2012 — forked from anonymous/home
home
View home
<% @posts.each do |post|%>
<div id="recentpost">
<%= post.name %><br/><br/>
</div>
<% end %>
View gist:1897643
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]
View gist:2288102
# 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)
View gist:2357092
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/ {
You can’t perform that action at this time.