Is this a ruby bug?
target_url_to_edit = target_url
if target_url_to_edit.include?("http://")
target_url_to_edit["http://"] = ""
end
logger.debug "target url is now #{target_url}"
This returns target_url without http://
...
I'm trying to learn Ruby, and am going through some of the Project Euler problems. I solved problem number two as such:
def fib(n)
return n if n < 2
vals = [0, 1]
n.times do
vals.push(vals[-1]+vals[-2])
end
return vals.last
end
i = 1
s = 0
while((v = fib(i)) < 4_000_000)
s+=v if v%2==0
i+=1
end
puts s
While that work...
UPDATE 2: For posterity, this is how I've settled on doing it (thanks to Jorg's input):
100.step(2, -2) do |x|
# my code
end
(Obviously there are plenty of ways to do this; but it sounds like this is the most "Ruby" way to do it; and that's exactly what I was after.)
UPDATE: OK, so what I was looking for was step:
(2..100).ste...
Tried doing http://davidwparker.com/2008/09/17/site-wide-announcements-in-rails-using-jquery-jgrowl/
Am really bad with JS. Think I am messing up on the last part where it says "This code goes in your application.js file (somewhere in $(function){ //here })"
Am I not suppose to do a link_to_function and create a function with this cod...
I have the following RSpec (1.3.0) task defined in my Rakefile:
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
end
I have the following in spec/spec_helper.rb:
require 'rubygems'
require 'spec'
require 'spec/autorun'
require 'rack...
Hello, I am currently trying to save information for an invoice/bill. On the invoice I want to show what the total price is made up of. The procedures & items, their price and the qty. So in the end I hope to get it to look like this:
Consult [date] [total_price]
Procedure_name [price] [qty]
Procedure_name [price] [qty]
...
I have rvm installed on a Mac OS X 10.6 system with the system ruby and 1.9.1. I also have this basic ruby script:
#!/usr/bin/ruby
require 'curb-fu'
I need the script to use the system ruby regardless of what rvm's using at any given time; I'm assuming that I've got that right, at least.
I've switched to the system ruby (rvm use sys...
There seems to be several technology demos such as http://rails-primer.appspot.com/ on how to run Rails on App Engine. What would be the easiest way to run Rails on App Engine?
...
I'm having issues requiring 'digest/sha1'.
~$ ./configure --prefix=$HOME/usr --program-suffix=19 --enable-shared
~$ make
~$ make install
~$ irb19
irb(main):001:0> require 'digest/sha1'
LoadError: dlopen(/Users/matan/usr/lib/ruby19/1.9.1/i386-darwin9.8.0/digest/sha1.bundle, 9): Symbol not found: _rb_Digest_SHA1_Finish
Referenced from: ...
I have a website where I need a javascript version of the "current user" object along with the ruby version. I have been assigning these variables doing something like this...
Application Controller:
def get_user
begin
@current_user = User.find(session[:user_id]) if session[:user_id]
@current_user_json = @current_user.t...
In Ruby, why does defining a class evaluate to nil? Same goes for defining a method: why does it evaluate to nil? Wouldn't it be useful if defining a class would evaluate as the class?
...
I am writing a script that grabs the external IP address along with some other information about each iface. I can't figure out how to make ruby send traffic over a specific iface(eth0 and wlan0 for example). I am currently using the open-uri library to open http://whatismyip.org and read it into a variable.
def get_external_ip
begin
...
I love RVM. I realize that the main use case for it is letting different users switch between different versions of Ruby. But let's say I'm deploying a Rails app to a server and I just want a single version of Ruby running. In particular, I want 1.9.2, which is a breeze to install with RVM but a pain without it. Is there a way that I can...
is there any way to make my currently jruby script into a standalone single executable like jar or exe ?
...
First the xml:
http://api.chartlyrics.com/apiv1.asmx//GetLyric?lyricId=90&lyricCheckSum=9600c891e35f602eb6e1605fb7b5229e
doc = Nokogiri::XML(open("http://api.chartlyrics.com/apiv1.asmx//GetLyric?lyricId=90&lyricCheckSum=9600c891e35f602eb6e1605fb7b5229e"))
Successfully will grab the document content.
After this point i am unab...
I want to include a hash and list inside a YAML file that I'm parsing with the following command:
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")
My YAML file looks like this:
feeds: [{:url => 'http://www.google.com', :label => 'default'}]
But this doesn't seem to work.
How would I go about achieving such a thing?
T...
I have a gem installed in my home directory on a laptop (eg not THE server). I have installed ruby 1.9.1 and also some other gems, notably right_aws - which allows access to s3, etc with ruby.
All works, except there is a bug when I do a query on SimpleDB, and the returned list of items includes an item with any two byte utf-8 characte...
I have two models: companies and expenses. Companies have many expenses and expenses belong to companies. My expense model has an 'amount' column.
I was wondering if there is a way to perform a find based on a date range and the amount column of the expenses. Something like top 3 companies by total expense amounts over a 7 day period.
...
I looked through the YAML for ruby documentation and couldn't find an answer.
I have a list of several employees. Each has a name, phone, and email as such:
Employees:
Name | Phone | Email
john 111 [email protected]
joe 123 [email protected]
joan 321 [email protected]
How would I write the above information in YAML to end up wit...
Hi,
This is a quick question. I have the following ruby code, which works fine.
def add_zeros number, zeros
number = number.to_s
zeros_to_add = zeros - number.length
zeros_to_add.times do
number = "0#{number}"
end
number
end
But if I replace
number = "0#{number}"
With
number.insert(0, "0")
Then I...