We are using Sinatra and Sequel for a small API implementation. The problem we have however is that on every page request Sequel opens new connections to MySQL, and keeps them open till they timeout, or you restart Apache.
There's not a lot of documentation on how to reuse connections, so any help, explanations, and/or pointers in the r...
I previously worked a lot with Java and now I am working more with Ruby. One thing I cannot figure out though is what is the ruby equivalent to the Java "NullPointerException"? I want to test variables when I enter a function and if they are nil I want to raise this type of exception. Is there a specific ruby error class to raise this...
I know there is ongoing work for in this regards but what is the exact status of JRUby 1.3 compatibility with Ruby 1.9.1 ? I am slightly confused if I can dwnload jruby 1.3 and start working with my ruby 1.9 installation.
The JRuby homepage says :
* Ruby 1.8.6 compatible now
* Ruby 1.9 compatible soon
Wikipedia says the foll...
Hi, I have a question regarding the ruby roo library. There is a method for opening the Excel document Excel.new . How to close this document, having worked with it?
...
I have this code:
def setVelocity (x, y, yaw)
setVelocity (Command2d.new(x,y,yaw))
end
def setVelocity (vel)
......
end
vel is a Command2D class that has 3 attributes, is Comparable and defines + , basically is a convenient class for me to manage those 3 attributes, so I want to use it internally in my library (dont want to make the...
Do I need to create a database table to implement captcha on a registration form?
...
hi is there a ruby modul for colorize strings in a linux terminal?
...
I am developing a poll using ruby, but the answer that i get is incorrect, i am looking for the answers that will results in 100% but my answers are sometimes 101% or 99% and i am sure is the rounding off of my floats but i just can get them right because without the rounding off the answers are very long floats. my code of calculating t...
I want to define a class method that has access to a local variable. So this would be different for each instance of the class. I know you can make a class method dynamic with lambda like when you use it with named_scope. But can this be done for values that are specific to an instance?
In detail it is the has_attached_file method for...
I wonder about installing the latest version of Ruby on Ubuntu 9.04. Now I can run through the ./configure and make stuff fine, but what I wonder about: how to avoid conflicts with the packaging system? For example if some other package I install depends on Ruby, wouldn't the package manager install the (outdated) Ruby package and in the...
I need a small unstructured database for my Ruby scripts. Not Sqlite, something more like a persistent hashtables would work perfectly, as long as it can store basic Ruby structures (arrays, strings, hashes etc. - all serializable) and won't get corrupted when Ruby scripts crash.
I know there's plenty of solutions like that for Perl wit...
If using the Ruby/MSQL library I returned an object of type Mysql::Result, how would I construct a string that loops through the object and constructs a valid MySQL query? I am having trouble figuring out how to drop the final comma from the output below, and how to pass this output back to the query() method.
require 'mysql'
dbh = Mysq...
I'm trying to get the output of the query 'SHOW TABLES FROM database_name' into an array using the ActiveRecord database connection. I can't seem to figure out how to do this. can someone please enlighten me?
-C
...
Is it possible to define an instance method in ruby from a string (the method name) and a block (the method's contents)?
I imagine this will need to use instance_eval(), but I haven't figured out how to mix the two data types yet. Both the string and the block are dynamically determined, so it would work to create the block with the "de...
I have a datetime column in db that I want to transform into a simple date when I show it to users.
How can I do that?
def shown_date
# to_date does not exist, but is what I am looking for
self.date || self.exif_date_time_original.to_date
end
...
I'm writing a non-Rails ruby application (gasp!) and would like to be able to include all the gem dependencies which the application requires in a vendor subdirectory. This would be similar to how http://gemsonrails.rubyforge.org/ works for Rails apps.
The goal here is to avoid the situation my team currently experiences when a new dep...
I periodically fetch the latest tweets with a certain hashtag and save them locally. In order to prevent saving duplicates, I use the method below. Unfortunately, it does not seem to be working... so what's wrong with this code:
def remove_duplicates
before = @tweets.size
@tweets.delete_if {|tweet| !((Tweet.all :conditio...
I'm hoping this question has a very simple answer. I can think of ways to do with with boring, annoying looping, but I'm hoping there's a more elegant solution.
If I have the following two variables:
hash = {:a => 1, :b => 2, :c => 3, :d => 4}
keyset = [:a, :c]
How can I get the following two hashes in the simplest way possible?
has...
I'm using Hpricot for traversing an XML packet. For each node I'm on, I want to get a list of the immediate children . However when using
(current_node/:section)
I'm getting ALL descendant sections, not just the immediate children.
How can I get around this?
...
I think I understand how a flip-flop works thanks to this tutorial, but the example there is contrived just for teaching. Can anyone give an example of how you have actually used or would use a flip-flop?
Edit: I'm looking for a real-world application, not just another demonstration. What problems can this tool solve?
...