I have a file called "output.txt":
"name": "abc",
"age": 28,
"name": "xxx",
"age": 11,
"name": "yyyb",
"age": 15,
I want to read the file and print the name and age values on one line, one after the other:
abc 28
xxx 11
yyyb…
I have a sorted 2D array as follows:
a = [[1, 2011], [3, 1999], [4, 2014], [6, 1998], ...]
How can I transform this into a hash with the key being the year and the value being the number in front?
{2011 => 1, 1999 => 3, 2014 => 4, 1998 => 6, ...}
I have a excel sheet(.xlsx) format which has only text data,I want to count the no of rows as well read the text data from the excel sheet in ruby
using win32ole gem only.I have gone through many of the post in stackoverflow which represent these…
I've done a little bit of reading and I can't seem to find a good answer to this question. I wanted to know if somebody could comment if there are any known dangers to using Rails LTS (https://railslts.com) with an unsupported (i.e. unpatched) Ruby…
I understand what the following warning means:
-:1: warning: useless use of a variable in void context
But I don't understand why ERB in Ruby 1.8.7 generates code that uses _erbout variable in void context:
$ rvm use ruby 1.8.7
Using…
I have this in model:
belongs_to :merchant_owner, :polymorphic => true
I want to make query like this:
@search = Merchant.includes(:merchant_owner).search
@merchants = @search.order
But I get this error in views:
You can't create a…
The original array likes this:
[{:age=>28, :name=>"John", :id=>1}, {:name=>"David", :age=>20, :id=>2, :sex=>"male"}]
Order of existing keys:
[:id, :name, :age] or ['id', 'name', 'age']
The result should be:
[[1, "John", 28], [2, "David",…
I am trying to learn some ruby http request response code from this tutorial -
http://danknox.github.io/2013/01/27/using-rubys-native-nethttp-library/
Code so far -
require "net/http"
require "uri"
uri = URI.parse("http://api.random.com")
http =…
I am writing a rake task for importing data from Csv, Xls and Xlsx for with Roo '1.9.1' ruby '1.8.7' and Rails '2.3.18'.
It works fine with all the data import and processing.
At the top of the file I have
require 'iconv'
require 'roo'
I am…
I use Ruby 1.8.7
I have a regex that is valid in Ruby 1.8.7 to match all emoticons
/\|?>?[:*;Xx8=<(%)D]-?'?,?o?\_^?[-DOo0S*Ppb3c:;\/\\|)(}{\]><]\)?|\(/
However , I want to match all set of symbols except the ones in this regex
For example,the…
For example,
input = ['a','b','b','b','a','a','b','c','c']
output = ['a',['b','b','b'],['a','a'],'b',['c','c']]
Here, if there are more than one same elements then those are put into sub-array.
Can you please help me out?
I'm trying to validate UK zip codes in Ruby. I stumbled upon this regex on stackoverflow:
(GIR 0AA)|((([A-Z-[QVX]][0-9][0-9]?)|(([A-Z-[QVX]][A-Z-[IJZ]][0-9][0-9]?)|(([A-Z-[QVX]][0-9][A-HJKSTUW])|([A-Z-[QVX]][A-Z-[IJZ]][0-9][ABEHMNPRVWXY]))))…
I need to insert the contents of a file into the database during a migration (Rails 3.2.13). What's the proper way to reference a file that is elsewhere in the project?
db/migrate/the_migration.rb
class ...
content =…