ruby

Make Date#parse assume a US format instead of an EU format.

With 1.9.2p0, Date#parse assumes an UE format. Check out format.rb, line: 1042 if you don't believe me. Anyways, how can I make it assume a US format, so that: > Date.parse("10/4/2010") => Mon, 04 Oct 2010 Instead of April 10th. I've tried this: class Date def _parse_eu(str,e) _parse_us(str,e) end end but no luck. Any...

undefined method `each' in a factory_girl / rspec2 scenario

I'm trying to Factory a Post associated with a Vote. So that Post.votes would generate the Vote's that are associated with it. Factory.define :voted_post, :parent => :post, :class => Post do |p| p.association :votes, :factory => :vote end And my rspec2 is relatively straightforward : describe "vote scores" do it "should show me t...

Infamous 'byte sequence" error with local install of gitorious on Ruby 1.9.1

I am trying to install gitorious on my personal server but I am not very familiar with Ruby or the frameworks and scripts involved in getting to the finish line. I am following the following instructions to install gitorious on my CentOS 5.4 server: http://www.tikalk.com/alm/blog/installing-gitorious-centos-55 The site comes up but a...

what packages do I need to install on Ubuntu to get ruby-opengl to compile?

I am trying to use the ruby-opengl package, when I install it the compliler complains that it cannot find the correct header files. What Ubuntu packages (9.10) do I need to make this work? ...

Rails - Local Variables versus Instance Variables

Hello, while learning Rails, I keep hearing Local vs Instance but I can't find a definition of the two & the differences. And I'd like to avoid making assumptions. What are the two and how are they different? Thanks ...

Ruby `when' keyword does not use == in case statement. What does it use?

x == User returns true, but case x statement does not run the block associated with User. What's happening here? u = User.new # => #<User:0x00000100a1e948> x = u.class # => User x == User # => true case x when User puts "constant" when "User" puts "string" else puts "nothing?" end # => nothing? ...

How would I go about reading bittorrent pieces?

Hello, I'm currently developing a torrent metainfo management library for Ruby. I'm having trouble reading the pieces from the files. I just don't understand how I'm supposed to go about it. I know I'm supposed to SHA1 digest piece length bytes of a file once (or read piece length bytes multiple times, or what?) I'm counting on your h...

Is this regex sufficent in stripping malicious code from a command line input?

I'm generating text images using imagemagick by passing user inputs via command. I'm concerned that a user could enter something malicious. # regex pattern [^\s\w\.&!?"] # image generation code, in Ruby "convert -quality 100 -background black -fill red -font Times-Bold -size x50 label:'#{@line1}' output.jpg" ...

Ruby "Base" classes

It seems commonplace to name classes "Base" in Ruby. I'm not sure why, nor how I feel about it. Consider, for example, ActiveRecord. ActiveRecord is a module that contains a number of classes such as Observer and Migration, as well as a class called Base. What's the benefit of this, as opposed to having an ActiveRecord class that contai...

Open source Twitter clone (in Ruby/Python)

Hello everyone, Is there any production ready open source twitter clones written in Ruby or Python ? I am more interested in feature rich implementations, not just bare bones twitter like messages (e.g.: APIs, FBconnect, Notifications, etc) Thanks ! ...

Alternative to eval()

Hi all, I'm looking for an alternative to that code: expl = eval "BeEF::Modules::Exploits::#{klass.capitalize}.new" Here the eval is totally insecure. Is there an alternative I could use to generate dynamically classes without using eval? As in, klass is always different. So my code stays generic. Thanks for your time. ...

How reliable is Heroku for a sensitive app?

Hi, How reliable is Heroku for a sensitive app? Can they be trusted for a very important app? Have you used it for a long time? What's your opinion? Thanks ...

Rails irb default directory

I'm trying to include a source code file when I run irb but irb is unable to find it. For example, say I am in the following directory in terminal: /dan/rubyapp/ Assume I have a file named "firstapp.rb" in /dan/rubyapp/ I startup irb and from the irb prompt I type > require "firstapp.rb" but the file can't be found. If I type "Di...

avoid http checking when installing a home made gem

Hi, I'm working on a set of gems for my application. When installing any of my own gems, the gem program will check rubugems specs (possibly for dependencies). With a verbose flag I can see messages like : GET http://rubygems.org/latest_specs.4.8.gz 302 Found GET http://production.s3.rubygems.org/latest_specs.4.8.gz 200 OK GET http...

Parse dmidecode with ruby

Given the output of dmidecode Handle 0x0025, DMI type 13, 22 bytes BIOS Language Information Installable Languages: 1 en|US|iso8859-1 Currently Installed Language: en|US|iso8859-1 Handle 0x0026, DMI type 16, 15 bytes Physical Memory Array Location: System Board Or Motherboard Use: System Memory Error Correction Type: Sing...

What is the equivalent of "require" (Ruby) in Python?

I am coming to python from ruby. What is the equivalent statement of require (Ruby) in Python? ...

Is there any method available to find changed attributes for objects?

I want to fetch only changed attributes of an object. Is there any method available which returns all the updated attributes? ...

Ways around ActiveRecord connection pool

I'm writing an Adhearsion component that uses ActiveRecord. The problem is that the component may be running for several minutes (the length of a call). During that time the component has an ActiveRecord object as an instance variable. This object uses up one database connection from the connection pool. Depending on the number of caller...

Split Ruby regex over multiple lines

This might not be quite the question you're expecting! I don't want a regex that will match over line-breaks; instead, I want to write a long regex that, for readability, I'd like to split onto multiple lines of code. Something like: "bar" =~ /(foo| bar)/ # Doesn't work! # => nil. Would like => 0 Can it be done? ...

Connecting to mysql in ruby produces wrong number of arguments error (4 of 0) - how to debug?

I'm trying to connect to a hosted MySQL database from my Ruby script. require "rubygems" require "mysql" con = Mysql::new('host', 'user', 'pass', 'database') Running this results in: ArgumentError: wrong number of arguments (4 for 0) method initialize in untitled at line 4 method new in untitled at line 4 at top level ...