Geeking Out in Orlando

Posted by Mike Blake Thu, 26 Jul 2007 19:10:00 GMT

At some point in my childhood, one of my four younger siblings coined the phrase geeking out to call attention to someone was uncontrollably excited. If one of us started geeking out the rest of us would be quick to call them on it. The only known cure was to hurl the offender into a pile of freshly raked leaves, a snow bank, or a sprinkler.

Gregg Pollack, head of the Orlando Ruby User’s Group has now captured me geeking out in this video to promote BarCampOrlando.

Well I can’t deny it, I am very excited about attending BarCampOrlando. Come geek out with us at Taste on Sunday September 23rd and discover why Orlando is quickly becoming one of the top technology centers in the country. And no worries; there will be no leaves, sprinklers, and certainly no snow anywhere near Taste. Just a full bar, awesome food, and great presentations from some of the leading minds in Orlando (and me).

Posted in  | Tags ,  | no comments

The Philanthropic Programmers

Posted by Mike Blake Tue, 22 May 2007 21:16:00 GMT

Something fantastic is happening in the Ruby and Rails World.

Do unto others

Open source developers know from experience that what goes around comes around. Contributions to projects like Rails invariably come back to benefit everyone, including the contributor. The community is now thinking on a larger scale. Frameworks come and go, but love is timeless .

The Summer of Love

Whytheluckystiff is focusing his power on Hackety Hack an amazing application that teaches children programming. And it’s likely more zeitgeist than coincidence that a professor from MIT, where the generous open source license originated, has started the noble project called One Laptop per Child . Developers everywhere like Amy Hoy are giving back in order to share the passion.

Chad Fowler has challenged the entire community to harness our newfound passion to do great things. And the community has only just begun to respond. During RailsConf over $33,000 was raised for charity.

Witness the Transformation

Software evolves rapidly. Humanity seems to evolve at a slower pace, but if you watch carefully, with ruby colored glasses , you can see it happening.

Posted in ,  | Tags , ,  | no comments

The RailsEnvy Guys

Posted by Mike Blake Wed, 16 May 2007 12:32:02 GMT

Gregg and Jason from our local Orlando Ruby Users Group have really outdone themselves, and created a series of four Mac vs. PC like ads just in time for RailsConf.

Posted in  | no comments

Hibernate 3.x Migration Guide

Posted by Mike Blake Thu, 26 Apr 2007 11:30:00 GMT

Update 4/30

I finally did find the real Hibernate 3 Migration Guide. My fun with Hibernate is over though, I've found an easier persistence solution with the clients homegrown method. I believe every single java project I've worked on in the past 10 years has used a different and unique Persistence mechanism. My favorite was Francois' PersistentEntity at ViaFone.


I’ve been strugling for the last day trying to get a Java application working, mainly, trying to get Hibernate to see a DataSource. Now I’m at a point where I get this error message:

[junit] (cfg.Configuration 1312) configuring from resource: /hibernate.cfg.xml

[junit] (cfg.Configuration 1289) Configuration resource: /hibernate.cfg.xml

[junit] (util.DTDEntityResolver 30 ) Don’t use old DTDs, read the Hibernate 3.x Migration Guide!

A quick search does not turn up a Hibernate Migration Guide, so I decided to create this one.

The Hibernate 3.x Migration Guide

  1. Get Ruby

  2. Install Rails

  3. Rebuild your application.

  4. Have fun again!

Posted in  | Tags , , ,  | no comments | no trackbacks

Testing a Non-Rails Application Using Rails

Posted by Mike Blake Sat, 31 Mar 2007 13:11:00 GMT

Rails developers working on enterprise software projects are suprised to discover the lack of automated tests in many mature web applications. As frustrating as this can be, A lack of automated tests is also a tremendous opportunity to

  1. Learn your non-rails applications underlying database structure.
  2. Demonstrate to a devlopment team the power of The Rails Framework.
  3. Encourage automated testing.

Rails may be the quickest path to automate some basic test of your non-rails applications data model. These steps will get you all set up to write your automated tests in Ruby.

  1. Connect to Your Enterprise Database
  2. Set DB Conventions
  3. Safety Net
  4. Duplicate the Schema
  5. Extract Development Data

I. Connect to Your Enterprise Database from Rails.

Download and install any os driver, ruby gems, and rails adapters needed to connect to your database:

Supported Rails Databases:

MySQL
DB2
Oracle
Sybase
SQLServer
PostgreSQL
Firebird

II. Set Your Existing Database Conventions

Rails Recipes , Recipie #16 can walk you through this very quickly.

Identify any conventions used by your legacy database. Application wide conventions can be set in the config/environment.rb file. They are specified by calling the appropriate class methods available on ActiveRecord::Base. The methods you need to call depend on how your database is configured:

ActiveRecord::Base.table_name_prefix 'myapp_'
ActiveRecord::Base.table_name_suffix = '_def'
ActiveRecord::Base.sequence_name = 'dev_company'
ActiveRecord::Base.pluralize_table_names = false 
ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore # or :table_name

III. Safety Net

Load the SafetyNet Plugin into your rails app to prevent from destroying your development database.

IV. Duplicate Your Database Schema

OK , with your dev and test development databases set correctly, let’s try duplicting the schema.

rake db:test:clone

If this works right off the bat, you’re one of the lucky ones. Skip to Extracting Development Data

If you recieved errors from the clone command, do steps A through C .

A. You can now correct any errors you may have had by manually modifying schema.rb . See Oracle Errors for some problems I had with the Oracle Database. Since schema.rb is generated, it’s a good idea to rename it when you modify it manually.

B. The clone command above may have started loading data; you need may to purge the test db. rake db:test:purge

C. Tell rake to load your new schema file by passing the new name, relative to RAILS_ROOT in the SCHEMA environment variable:

rake db:schema:load RAILS_ENV=test SCHEMA=db/oracle_schema.rb

V. Extracting Development Data

Copy the code from Rails Recipe #42: extract_fixtures.rake to your RAILS_ROOT/lib/tasks directory.

TIP: If your develoment database has lots of data, Modify the SQL Select in this code to limit the amount of data you copy using the SQL limit statement:

sql = "SELECT * FROM %s limit = 100"

Or for a proprietary database, the equivalent command:

sql = "SELECT * FROM %s WHERE ROWNUM<=100"

Then run rake extract_fixtures

You’ve made your testbed so you can lie in it.

You now have and exact copy of your development database, and a collection of sample data in Yaml format, and are ready to begin writing some Unit Tests. Stay tuned for some examples. Rail on!

Posted in  | Tags , , , , ,  | no comments

Rails on Oracle

Posted by Mike Blake Thu, 29 Mar 2007 21:15:00 GMT

When rails on jruby and connecting to Oracle via JDBC ,the following error eventually appears:

Update: java.sql.SQLException: Io exception: Broken pipe

Fix:

You need a dedicated connection from Oracle. Change the url: line in database.yml from url: jdbc:oracle:thin:@localhost:1521:XE

to

url: jdbc:oracle:thin:@(DESCRIPTION = (ADDRESSLIST = (ADDRESS =(PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))) (CONNECTDATA =(SERVER = DEDICATED) (SID = XE)))

Workarounds

Duplicating an existing Oracle Database using the build in task rake db:test:clone presented a few problems. Here’s what I did to work around them.

ORA-01727: numeric precision specifier is out of range

OCIError: ORA-01727: numeric precision specifier is out of range (1 to 38): CREATE TABLE employee (id NUMBER(38) NOT NULL PRIMARY KEY, createddate DATE DEFAULT NULL, startdate DATE DEFAULT NULL, jobid DECIMAL DEFAULT NULL, totalhours NUMBER(126) DEFAULT NULL)

Fix:

For some reason whne rails dumps the schema, it reports Oracle type FLOAT as NUMBER(126), so you just need to changed that back to FLOAT if you want to import that schema.

OCIError: ORA-00972 identifier is too long:

OCIError: ORA-00972: identifier is too long: CREATE SEQUENCE gametime_responsibility_ref_seq START WITH 10000

Fix:

Rails tries to create sequences in Oracle to handle AUTOINCREMENT id fields. It uses TABLENAME = ’SEQ’ for the sequence name. If a sqequence name is too long then you have to shorten it in schema.rb .

OCIError: ORA-00907: missing right parenthesis

OCIError: ORA-00907: missing right parenthesis: CREATE TABLE board (id NUMBER(38) NOT NULL PRIMARY KEY, name VARCHAR2(150) NOT NULL, name VARCHAR2(150) NOT NULL, parent VARCHAR2(150) DEFAULT NULL, loglevel DECIMAL DEFAULT NULL, modifieddate DATE(6) DEFAULT NULL, token DECIMAL DEFAULT NULL)

Fix:

For some reason Rails assigns Date fields a size in schema.rb . You’ll need to change all occurances of DATE(6) to DATE .

Posted in  | Tags , , ,  | 1 comment

Columbia City Paper and Mephisto

Posted by Mike Blake Mon, 05 Mar 2007 17:35:00 GMT

Ideas from the Margins

My brothers alternative news weekly in Colombia, SC focuses on stories no one else would write about including a regular feature called Bum of the Week, or and occasional interview with a Nazi.

Content Management

He asked me to help him find an open source Content Management System, and after exploring a few, we choose Mephisto. I was impressed with Mephistos usability and online documentation. I also noticed that there we’re several integration tests written for it’s caching system, and used them as an example in a recent presentation. It has slickly designed admin interface, and the writers at City Paper love it. My brothers not afraid to edit some HTML or CSS, so he quickly got comfortable with the design templates.

Surprise

But the best surprises came after we went live with the site last week. First the visitors to the site began commenting on stories like never before. For some reason the Ocadia template we chose with it’s subtle use of color was inviting.

Ironically one commenter who said

I’m not going to make this a forum for debate. Those who want to debate me can come onto a regular white website …

went on and on after that to post the largest comment posted by anyone, and made that article a forum for debate. It turns out that integration of color is much more appealing to him than he ever knew.

College Football Frenzy

The second surprise came just 2 days later. Editor Todd Morehead published a story early Friday about USC’s quarterback keying a car in the school library parking lot. The story was index by Google’s news bot, and went on to get picked up by the the local daily paper that night, hit the Associated Press wire, and was then published on Sport’s Illustrated’s site along with dozens of sites nationwide.

City Paper received a record number of unique visits over the weekend. Mephisto’s caching performed beautifully. It was a great weekend here in the margins. Congratulations to City Paper for breaking a national new story, and to Mephisto for not breaking.

Posted in ,  | Tags , , , , ,  | 2 comments

How Do You Get to Silicon Valley?

Posted by Mike Blake Thu, 22 Feb 2007 14:50:00 GMT

Practice.

Music

When Tony Macaluso invites me to play bass at a gig, I need to prepare. Before I even start rehearsing songs, I break out my Rickenbacker and warm up with some scales.

Programming

When I’m invited to help out with a software project I’m expected to hit the ground running. Each project might require a different area of expertise. How do I warm up? I usually have reserched the problem domain beging even before interviewing for the gig. But now there’s a more precise method analogous to playing scales.

Pragmatic Programmer Dave Thomas has begun a blog called CodeKata . He already has about 15 different exercises created to help us programmers practice our craft.

The Kata touch on a variety of common problem domains in software development. There are the standard programming 101 issues including Sorting it Out and Karate Chop. And there are several design exercises like Hashes vs. Classes and Supermarket Pricing.

Posted in  | Tags , , ,  | no comments

Undefined method assert_select

Posted by Mike Blake Mon, 19 Feb 2007 18:23:00 GMT

The assert_select method for testing views was added in Rails 1.2, so the first thing to check if you’re getting the error below is that you’ve upgraded to 1.2

>  2) Error:
>test_expire_old_ads(AdExpirationTest):
>NoMethodError: undefined method `assert_select' for #
> c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/test_process.rb:432:in `method_missing'

Now I upgraded to 1.2 and still kept getting the above error. The problem was that my application was set to use Rails 1.1.6 in the config/environment.rb file:

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '1.1.6'

So the solution is to comment out that line, or alternatively ,set it to the latest version. Also make sure you’re not frozen to a specific Rails version in the vendor directory.

Posted in  | Tags , , ,  | no comments

The Unselfish Act of Writing Tests

Posted by Mike Blake Wed, 14 Feb 2007 21:07:00 GMT

ORUG

At this months Orlando Ruby User’s Group meeting, I did my Testing on Rails presentation. In it I touched on just some of the benefits of having an automated suite of Unit, Functional, and Integration tests.

Benefits of Testing

Later I thought of another major benefit. Tests help other people on the project, in addition to the author of the test.

Good Habits are Contagious

Recently I had the opportunity to work on a project with Harris Reynolds. Harris did something very important that sadly, you don’t see on every Rails Project. He wrote a unit test. Lot’s of us wrote tests , but this particular test stood out for two reasons. The first was when it was written.

Writing Tests First

Harris had found a bug in a model object that I had created. To notify me, he checked in an assertion that failed, then emailed me. This saved me time searching thought and remembering code I had written. I simply typed rake test:recent which runs all recently changed tests in a Rails application . The error took me right to the problem, and I immediately fixed the bug.

Testing a Deployment

The second reason I remember this test happened at least a month later. The application was being deployed to a new machine, and the test failed. The particular model object being tested pointed to a different database that the rest of the application, and it turned out that that database hadn’t been installed correctly on the new machine. Harris’s test told the problem straight away, and saved time once again.

Unit Testing: the gift that keeps on giving.

Thanks Harris!

Posted in  | Tags , , ,  | no comments

Older posts: 1 2 3