We have different types of hyphens/dashes (in some text) populated in db. Before comparing them with some user input text, i have to normalize any type of dashes/hyphens to simple hyphen/minus (ascii 45).
The possible dashes we have to convert are:
Minus(−) U+2212 − or − or −
Hyphen-minus(-) U+002D -
Hyphen(-) ...
I'm using this little bit of ruby:
File.open(ARGV[0], "r").each_line do |line|
puts "encoding: #{line.encoding}"
line.chomp.split(//).each do |char|
puts "[#{char}]"
end
end
And I have a sample file that I'm feeding in the file just contains three periods and a newline.
When I save this file with a fileencoding of utf-8 ...
This seems horrible inefficient. Can someone give me a better Ruby way.
def round_value
x = (self.value*10).round/10.0 # rounds to two decimal places
r = x.modulo(x.floor) # finds remainder
f = x.floor
self.value = case
when r.between?(0, 0.25)
f
when r.between?(0.26, 0.75)
f+0.5
when r.between?(0.76, 0.99)
f+...
In my controller I have some methods which return json as well as xml data.
I need to test those actions. For testing the json part I found this reference and it is working fine. Now I am need of testing the actions for the XML part.
Anyone who can help or suggest something are most welcome I've been scratching my head for an hour now bu...
I'm learning Ruby, and have just gotten into some stuff about arrays and ranges. I've run into something about slices that, while it makes sense at first glance, confuses me a bit when i look deeper into it.
irb says that (2..-1).to_a is an empty array. Meaning no values in the range, right?
But if i use that same range in [:a, :b, :c...
I want to replicate any given Javascript loop , class , function to into its Ruby Equivalent
and e.g would as follow
suppose I passed the following Javascript function.
function define() {
var x = 0;
for(var i=0; i < 10 ; i++) {
var x += i }
alert(x); } define();
then I should get replicate to ...
I can't seem to get past this error when setting up devise.
Routing Error
wrong constant name Devise/registrationsController
or
Routing Error
wrong constant name Devise/sessionsController
I'm using Ruby 1.8.7, Rails 3.0 and Devise 1.1.3
Everything else on my app works, I recently upgraded my app from 2.3.8 and was previously usi...
How could I make this shorter and extendable:
def overview
puts "All As:"
for f in @a
puts f
end
puts "\n"
puts "All Bs:"
for f in @b
puts f
end
end
...
I am not sure what is the best strategy for this. I have a class, where I can search the filesystem for a certain pattern of files. I want to execute Find.find("./") only once. how would I approach this:
def files_pattern(pattern)
Find.find("./") do |f|
if f.include? pattern
@fs << f
end
end
end
...
I have a Ruby on Rails project with what seems to be a memory leak. It keeps using more and more memory until it crashes. Dumping the amount of objects per class using ObjectSpace I've found this:
Name Count
---------------------------------------------------------------------...
In rails default controller the new method makes an object, and the create method is used later to save that.
I want to set a mod_user field in the DB, without it being input into the form.
Based on this link http://api.rubyonrails.org/classes/ActiveRecord/Base.html I've tried adding the following to my pages controller.
def new
...
I remember seeing a ruby application for managing background jobs, I just forgot the name and I cannot find it anymore. I remember it having a nice homepage with a big picture of a blue octopus handling many jobs. Anyone have an idea?
I think it supported RabbitMQ too. Anyone have an idea?
...
Hi!
I'm adding Resque-Scheduler in my app on Heroku
So... I need ONE alone and distinct worker acting as the scheduler and
many doing the jobs.
This is how I've done it :
I've a distinct Heroku App which does nothing but has 1 resque-scheduler worker, running 24/7, adding Resque tasks to the Redis DB of the "distant" main App.
(I do t...
Hi all, I' trying to do a validates_length_of, but specifying the range/minimum/maximum at run time.
For instance, we have a parent model:
class Parent < ActiveRecord::Base
has_many :children
# with attributes min_length, max_length
end
And a child model:
class Child < ActiveRecord::Base
belongs_to :parent
# with an attrib...
I am basically asking the same question as http://stackoverflow.com/questions/2504445/spawn-a-background-process-in-ruby, except I need to spawn a background process in a Windows environment! Unfortunately, my research has revealed that Windows doesn't support Ruby forks (only spoons. Rimshot!).
...
I use builder for my buildprocess.
I have some java classes in my src directory as well as some *.qvto files. These files just need to be copied to target/classes. However, this should be done as part of the compilation process, as these files represent some part of code that does not need to be compiled. Currently, I am stuck and do n...
I have a program that creates 10000 threads at once, and runs 8 at the same time.
But ruby doesn't have a ThreadPool built-in as Java. Is there a good reason?
...
I use buildr for my build process.
My project setup:
Project A -> Project B
Project A requires ant.jar
So, I want to create an output looking the following:
target/a.jar
target/lib/b.jar
target/lib/ant.jar
So far, I only managed to create a.jar inside target/
How can I persist the dependent jar files?
...
It is very difficult for me to find Rails tutorials (or books are also great) for my requirements:
Stupidity
Ruby 1.9 or lastest 1.8
MySQL
A Game (simple roll play)
JQuery front
Thanks you!
...
I wrote a script here to access a Google Spreadsheet by name using Ruby:
http://gist.github.com/606488
I'm trying to use gdata as per the instuctions here:
http://code.google.com/apis/gdata/articles/gdata_on_rails.html
How come I'm getting a 401 error "Token invalid" when using the gdata gem?
It works fine when I use the methods descr...