Archive for the 'Ruby' Category

2007 Programming Language Popularity

Posted in Information related, Software, Pseudo Psychology, Perl, Ruby on February 5th, 2007

Interested in what’s hot (according to the TIOBE Index) in Programming Languages?

Check out TIOBE Programming Community Index for February 2007

From the TIOBE site

The TIOBE Programming Community index gives an indication of the popularity of programming languages. The index is updated once a month. The ratings are based on the world-wide availability of skilled engineers, courses and third party vendors. The popular search engines Google, MSN, and Yahoo! are used to calculate the ratings. Observe that the TIOBE index is not about the best programming language or the language in which most lines of code have been written.

Originally found while cruzing Oreilly’s “PHP vs. Ruby on Rails. An evolutionary story of a Web Developer and his tools.“.

Ruby and MySQL lost connection weirdness

Posted in Software, Ruby on December 21st, 2006

I had a bit of grief with a rails application connecting to a MySQL 4.1 DB.

I shared my insight over at MySQL+Database+access+problem on the Ruby on Rails Wiki.

Here’s what the error was and my solution is.

Lost connection to MySQL server during query was the error I was encountering.

Someone above mentioned passwords, and this was the cause for us.

Our development environment was not using a password to authenticate to a MySQL 4.1 installation. There were many explanations for ”lost connection” on the mysql site, but none that really it came down to passwords as others had mentioned.

In the /etc/my.cnf comment out the old password line:

#old_passwords=1

Then I changed the password again

mysql> set password for ‘bergo’@'localhost’ = password(’WHATEVER’);

BTW - that’s not really my DB user …

Using the OLD_PASSWORD mysql command did not seem to work either.

Changing the database.yaml to user/password combo and it all worked a treat.

If you need old passwords I’m not sure what the solution is for you.

A little config gotcha .. no reason for us to be worried about old_passwords at all, it was a green fields app, but this is the way it’s installed by default. Strange though, MySQL admin had no trouble connecting under either configuration .. possible it tries both.

Junebug and Nginx

Posted in Tech, Information related, Software, Ruby, Wiki, Reviews on December 19th, 2006

I found two new applications today, Junebug (a wiki) and Nginx (a webserver).

So Junebug was discoverd through Redhanded but while I was trauling throught the installation section I stumbled up Nginx.

Having partially written a wiki (in Perl) myself, I am still amazed when I see a new/another wiki crop up. Junebug is based on the Camping Framework, another Ruby web framework.

I have been looking at Xavante (Lua Language) webserver just for technologies sake. There always seems to be more fringe applications and frameworks than one would imagine. I guess the thread I see from newer frameworks is a focus on simplicity, light footprint (memory, code base). Nginx is claiming a much smaller memory footprint that Apache, Lighttpd, et al when acting in a reverse proxy mode. Before today, I would not have known it existed.

Back to Junebug though, one great feature it has .. download and run. Embedded webserver, you don’t need the Apache or Nginx instructions. This is important to quickly get the feel for an application. The download and run is a great feature I also liked that Instiki has. Junebug looks like a great little wiki, but I always think I need a cross between a Wiki and a bookmarking service (like del.icio.us) .

They have a simple focus:

Junebug is a simple, clean, minimalist wiki intended for personal use.

All the regular features of Access Control, Page Versioning and DB backing (through SQLite).

I think it’s worth a bit more a a serious look.

Timezones, MySQL and Ruby

Posted in Software, Ruby on June 11th, 2006

I have two problems, MySQL wasn't storing Timezone information and Active::Record is automagically loading objects with TIMESTAMP as a localtime, and not the UTC time that it is.

This problem came about because at work we're getting two different sources of events to log, with more than one timezone (Australian EST and UTC). I first came across this in February, and it surfaced again a couple of weeks back so I thought I'd record how I solved the problem (for me anyway).

The following little piece lets ActiveRecord know that we stored them in UTC, and retrieve the timestamps accordingly.

RUBY:
  1. ActiveRecord::Base.default_timezone = :utc 

Simple as that.

Placing this inside the Model file fixes the localtime problem, now I know it will be UTC and can format the time when I need to.

Parsing a datestring to UTC just did not seem simple enough

RUBY:
  1. def parse_to_utc( some_date_string )
  2.  
  3.         parsed_time = ParseDate.parsedate(some_date_string)
  4.  
  5.         a_time =  Time.gm(*parsed_time)
  6.         dt =  DateTime.parse(some_date_string)
  7.         new_time = a_time
  8.  
  9.         if dt.zone != 'Z'
  10.  
  11.             hours = dt.zone[1,2].to_i
  12.             minutes = dt.zone[3,4].to_i
  13.             total = (hours * 60 * 60) + (minutes * 60)
  14.        
  15.             if dt.zone[0].chr == '+'
  16.                 new_time = Time.utc(*parsed_time) - total
  17.             elsif dt.zone[0].chr == '-'
  18.                 new_time = Time.utc(*parsed_time) + total
  19.             end
  20.  
  21.         end
  22.  
  23.         return new_time
  24.  
  25.     end 

This above block seems to work, but there must be an easier way of doing this?

Information resources: