nokogiri: Get shortcut icon from a page
How can I do that? ...
How can I do that? ...
In /initializers/time_formats.rb I have this: Time::DATE_FORMATS[:profile] = "%m / %d / %Y" However this obviously produces dates such as: 09 / 08 / 2001 Google tells me my best bet is to use some kind of gsub regular expression to edit out the 0's. Is this true or is there a better alternative? ...
I've always thought this sort of thing ugly: require File.join(File.dirname(__FILE__), 'hirb/config') Is there a prettier alternative, maybe one written for Rails? require_relative 'hirb/config' require_relative '../another/file' ...
We have two servers with the same home-brewed RPM of ruby installed. One one server, the search path is different, and it fails the following snippet. #!/usr/bin/env ruby require 'openssl' require 'digest/md5' puts OpenSSL::Digest::MD5.new Broken server output: /tmp/test.rb /tmp/test.rb:6: uninitialized constant OpenSSL::Digest::MD5...
I've got a Ruby + Merb webapp that needs to quickly estimate (or count exactly) how many row a spreadsheet has. It accepts every format that the roo library supports, including .xls, .xlsx, .ods, and text-based formats like CSV and TSV. CSV/TSV is easy and fast: `cat #{filepath} | dos2unix | wc -l`.to_i However, using the roo library...
Let's say I have a loop like this: items.each do |x| if FIRST_TIME_AROUND # do something end # do the rest of stuff end is there a way in Ruby to write if FIRST_TIME_AROUND? I vaguely recall reading something about this once, but I can't recall. EDIT: I do know about the (many) standard ways of doing this... I'm after the m...
Anyone heard of a good standard template library in Ruby? Or any wrapper exists? Thanks! ...
xpath for selecting html tag ? <select> <option value="first option"> 1 </option> <option value="second option"> 2 </option> <option value="third option"> 3 </option> </select> Would below suffice ? html/body/form/select[@name='options' and @value='first option'] ...
Is there some utilities available so that I could easily encapsulate form fields passed in requests in an object or do I have to create it myself by parsing fields from params in every request? ...
I don't know if this a Ruby question or a Rails question but in this example of a use of nested resources in Rails, how is it possible to assign an event object to an event_id? The event object would seem to represent a larger set of values than the event_id does. <%= link_to 'Tickets', event_tickets_path(:event_id => @event) %> ...
Okay, I have been messing around with different sorting algorithms in Ruby; mainly variations quicksort. I have a version of dual pivoted quicksort that picks random pivots. So when the random pivot lands at the beginning or end of the array weird things start happening. I did some investigating and have boiled it down to this strange ph...
In python, you can do >>> import sys >>> sys.executable '/usr/bin/python' to get at the executable's location. Can you do the same thing just using something built-in to ruby? It can be a special variable, method, etc. If there isn't, what is the cleanest, most reliable way of determining the ruby executable's location in a cross-pla...
Hi, I am working on selenium for automation web application testing. I want make a key stroke event while entering the values in the textfield I tried the following @browser.type(auto_complete_field_locator, auto_complete_field_value) @browser.type_keys(auto_complete_field_locator, auto_complete_field_value) and it worked in the ...
I'm writing a small program in Ruby to parse a hand history log from a poker site. The log is split over several lines and looks a bit like this: Table 123456 NL Hold'em $1/$2 5 Players Seat 3 is the button Seat 1: randomGuy112 $152.56 Seat 2: randomGirl99 $200 Seat 3: PokerPro $357.12 Seat 4: FishCake556 $57.19 Seat 6: MooMoo $188.98 D...
I need a set of ruby problems + solutions that require solutions involving more than a few interacting classes. The point is to teach OOP in ruby to a beginner. Sites like rubyquiz tend to have problems that require clever algorithms, rather than OOP design. The best I can think of so far is to do a very simple game like pong, but Rub...
I have an array of integers. For example: array = [123,321,12389] Is there any nice way to get the sum of them? I know, that sum = 0 array.each { |a| sum+=a } would work. ...
For example, if I typed "ds.35bdg56" the function would return 35. Is there a pre-made function for something like that or do I need to iterate through the string, find the first number and see how long it goes and then return that? ...
let's say when I'm comparing values in ruby, i have a value in mind that no matter what I want, using sort on that value and anything else returns a -1 (so this value is default sorted as smaller than everything). for example, let's say i want '100' to sort smaller 100% of the time against 99. so that if i'm sorting values in an array, ...
for multiple selectdown form, how can you express multiple options selected ? <select name="sweets" multiple="multiple"> <option>Chocolate</option> <option selected="selected">Candy</option> <option>Taffy</option> <option selected="selected">Caramel</option> <option>Fudge</option> <option>Cookie</option> </se...
Assume I have the entire HTML of a Google search results page. Does anyone know of any existing code (Ruby?) to scrape/parse the first page of Google search results? Ideally it would handle the Shopping Results and Video Results sections that can spring up anywhere. If not, what's the best Ruby-based tool for screenscraping in general...