I have a config file full of this....
- if current_page.include? "test_string_one"
- @total_index = 3
- @next_location = '../random_string/page0.html'
- @next_name = 'title 2'
- if current_page.include? "test_string_two"
- @total_index = 10
- @next_location = '../another_random_string/page0.html'
...
I have an array:
[0, 0, 0, 0, 0, 0, 0, 1, 2, 3]
I need to figure out index of the minimal element which is not zero. How do I do that?
...
I recently did a class assignment where I made a really hacky data structure. I ended up using nested hashes, which seems like a good idea, but is really hard to iterate through and manage.
I was doing general stuff, like one tag maps to a hash of items that map to prices and stuff like that. But some of them were getting more complicat...
I've written two simple calculations with Ruby which match the way that Microsoft Excel calculates the upper and lower quartiles for a given set of data - which is not the same as the generally accepted method (surprise).
My question is - how much and how best can these methods be refactored for maximum DRYness?
# Return an upper quar...
I'm working with some serialized data from a MySQL database and I need to deserialize this using Ruby (the serialized data is used to build up a WHERE clause for a database query). PHP has the unserialize() method which will convert it into an Array; what is the Ruby equivalent of this?
The data in question looks like this, if it helps...
Ruby will not play nice with UTF-8 strings. I am passing data in an XML file and although the XML document is specified as UTF-8 it treats the ascii encoding (two bytes per character) as individual characters.
I have started encoding the input strings in the '\uXXXX' format, however I can not figure out how to convert this to an actual...
I'm struggling myself trying to change that default message once you insert invalid credentials as username:password on rails using authenticate_or_request_with_http_basic.
For example if I make a curl request on a method that need this authentication, once I insert the wrong username and password it returns HTTP Basic: Access denied.
...
I'm trying to encrypt some data using the Ezcrypto gem in Ruby. Things work perfectly when running under MRI, but I'm getting strange results when running the same code using JRuby.
Executing the following should produce the same output with repeated called.
Output from MRI:
irb(main):007:0> Base64.encode64(EzCrypto::Key.encrypt_with_...
How can i remove a repeating string keyword from all elements in an array ?
...
I am recieving the following error when trying to use MacVim:
~$mvim index.php
dyld: Library not loaded: /usr/lib/libruby.1.dylib
Referenced from: /Applications/MacVim.app/Contents/MacOS/Vim
Reason: no suitable image found. Did find:
/usr/lib/libruby.1.dylib: mach-o, but wrong architecture
/usr/lib/libruby.1.dylib: mach-o,...
begin
#some routine
rescue
retry
#on third retry, output "no dice!"
end
I want to make it so that on the "third" retry, print a message.
...
I am generating a CSV file from Ruby. The problem is a column string will contain double quotes, single quotes. How can I escape these things?
"Mary had a little so called \"lamb\"","34","none"
"something is not \"right\"","23","none"
Each column is enclosed in double quotes followed by comma (and no space), and written into a file.
...
Hello!
I am quite new to ruby but enjoying it so far quite immensely. There are some things that have given me some trouble and the following is no exception.
What I am trying to do here is create a sort of 'super-directory' by sub-classing 'Dir'. I've added a method called 'subdirs' that is designed to list the directory object's fi...
I have the following problem:
In Rails I have two Objects: Categories and Items
One category has many items and one item belongs to one category.
Okay. There are no problems.
But now, I want to display all existing categories in a sidebar on every page in my project.
I tried to do display them like:
<div class="sidebar">
<% @catego...
I want to make a full integration testing for a web application. I want to test many things like AJAX, positioning and presence of certain phrases and HTML elements using several browsers. I'm seeking a tool to do such automated testing.
On the other hand; this is my first time with integration testing, is there any specific recommendat...
Is there a better way for
result = []
function_that_yields{ |value| result << value }
...
I am doing a find in Rails model as follows:
@jobs = Job.find(:all, :conditions => ["job_id = ?", params[:id]])
The result of this query also brings back data from an associated model JobResponses (there are multiple JobResponses for each Job record). Once I have the JobResponse results I am calculating a number of different averages/...
I have auto registration working with authlogic using gaizka's version of authlogic_openid which I found on Github since pelle's original addition of the feature seemed to cause issues.
http://github.com/gaizka/authlogic%5Fopenid
http://stackoverflow.com/questions/1476953/using-authlogic-to-auto-create-users-bypassing-explicit-user-r...
I've written a feature for my library Rubikon that displays a throbber (a spinning as you may have seen in other console apps) as long as some other code is running.
To test this feature I capture the output of the throbber in a StringIO and compare it with the expected value. As the throbber is only displayed as long as the other code...
I've the following category structure:
- Transport (10)
- Cars (5)
- Audi (2)
- BMW (3)
- ...
- Spare Parts (5)
- Audi (5)
- Audi glass (1)
- Carburetors (4)
- Mirrors
- ...
- Buses
- Spare Parts (5)
- Audi (5)
- Audi glass (1...