I think I'm running up against a fundamental misunderstanding on my part of how threading works in ruby and I'm hoping to get some insight.
I'd like to have a simple producer and consumer. First, a producer thread that pulls lines from a file and sticks them into a SizedQueue; when those run out, stick some tokens on the end to let the...
I have VPS with 1GB of RAM. One ruby-app that runs on thin server takes about 60+ MB of RAM, no matter if application is used right now or not. Is there any way to control this? Because right now Im runnin' out of memory. Any suggestions are accepted. Thanks in advance.
...
In ruby, there are currently 3 ODM maintained:
MongoMapper
MongoID
MongoDoc
What is your prefered and why ?
...
When I first started reading about and learning ruby, I read something about the power of ruby symbols over strings: symbols are stored in memory only once, while strings are stored in memory once per string, even if they are the same.
For instance: Rails' params Hash in the Controller has a bunch of keys as symbols:
params[:id] or
par...
i just learned about static variables in php.. i was just wondering is there any thing like that in ruby...
say..
if we want to create a student class and for each student(object) we create, its id no should get incremented automatically..
I thought creating class variable as a static will do...
thanks,
regards,
levirg
...
I have problems to get rspec running properly to test validates_inclusion_of my migration looks like this:
class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.string :name
t.integer :parent_id
t.timestamps
end
end
def self.down
drop_table :categories
end
e...
I have code to run sql query in ruby as follows
sql =
ActiveRecord::Base.connection()
sql.begin_db_transaction
report = sql.execute("select * from users;")
sql.commit_db_transaction
So after this report is an Mysql::object. Now I want to extract all fields and its corresponding data to array or hash.
thanks,
...
I want to create an extremely simple web server for development purposes in Ruby (no, don’t want to use ready solutions).
Here is the code:
#!/usr/bin/ruby
require 'socket'
server = TCPServer.new('127.0.0.1', 8080)
while connection = server.accept
headers = []
length = 0
while line = connection.gets
headers << line
...
Hello to All,
We need one voice chat application integration in RoR application existing room users. How we can achieve that? Have any reference links or existing sample voice chat reference sites using mumble, it will help me lot.
Thanks,
Mars
...
I'm using seeds.rb to load some dummy data into my project as I develop it.
I'd like to use a random created_at date for my records, but the created_at date is always set to Time.now on create.
#seeds.rb
Project.create :name => 'Dummy Project',
:created_at => Date.today - rand(10).days
...
Hey guys, busy learning ROR... I wasn't quite sure how to look for this problem on stackoverflow so sorry if this has been asked before :p
Basically I'm in the Console environment busy reading all the rows from a table into a variable and I noticed that you can reference the results by specifing my_object.id OR my_object[:id].
Can some...
I have a string, populated from the *nix "hostname" command, that I need to parse for a number. That's the easy part. The difficulty comes from a need to have to Do Math(tm) on that captured number. Apparently regex captures are always of type MatchData, which doesn't have any math functions like 'add' or 'modulo', nor does it have a ...
The idea is as follows: when visiting a purchase page, the pre-initialized (using before_filter) @purchase variable receives save if the item in question is not free.
I make two gets, one for a paid item and one for a free item. purchase.expects(:save).returns(true) expects :save to be called only once, so the below test works.
But th...
Hey,
I am trying to access an instance variable which is set in the controller in the model. The controller is the products controller and the model is the products model. The instance variable is a instance of another model called account.
The instance variable is @current_account
When I run the code nothing happens, I do not get an ...
Hi
I'm trying to reuse methods in DataMapper classes. This might be as well a ruby question I think.
class Foo
include DataMapper::Resource
property :name
property ...
def self.special_name
self.all(:name => 'whatever')
end
end
class Bar
include DataMapper::Resource
property :name
property ...
def self.specia...
Hello, I'm trying to remove the object with the oldest updated_at value when the rjs is executed.
page.insert_html :top, :messages, :partial => @message
page[@message].visual_effect :grow
page[:message_form].reset
Message.old_messages.each do |m|
page.remove(m.id)
end
page.delay(1) do
page.select('.message').last.visual_effect :fad...
For cruft-removal purposes I would like to log whenever a method from one of my AR models is called.
I can get get all those classes with something like this:
subclasses = [] ; ObjectSpace.each_object(Module) {|m| subclasses << m if m.ancestors.include? ActiveRecord::Base } ; subclasses.map(&:name)
But then I need a list of only the ...
Hi,
it's about rMagick and the polaroid effect.
image = image.polaroid do
self.font = "Tahoma"
self.caption = name
#self[:caption] = name
self.shadow_color = "gray40"
self.pointsize = 12
end
This is how I tried to change it's caption, but both versions don't work.
Any ideas?
Yours Joern.
...
text = "I fixed bug #1234 and #7895 "
regex = /#(\d*)/
m = regex.match(text)
puts m.inspect #<MatchData "#1234" "1234">
In the above case why I am not seeing 7895? What's the correct solution?
...
I have a pieces of code where i spawn off children processes to make it more efficient. However, they appear to create all sorts of zombie processes which block sockets and bring down the site.
spawn(:method => :thread) do
if @login_user.suggested_group_info.new_record?
xxx
end
end
1) Why is this creating zombie processe...