Wednesday, September 17, 2008

Murphy's Law of Variable Names

There are at least six appropriate names for any given variable, method, column, or table.

You will not choose one of them.

Wednesday, September 10, 2008

You might be a geek if

..."too much rails" sounds grammatical to you.

Friday, August 1, 2008

Composite Primary Keys (CPK) and RSpec Fixtures

I was banging my head against the proverbial wall all week.  This morning's travail was an error like this in my specs:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.first
/path/to/rails/app/vendor/gems/composite_primary_keys-1.0.5/lib/composite_primary_keys/base.rb:239:in `find_from_ids'

...After some digging, I found a page that explained the problem, and revealed that you need this in your spec/spec_helper.rb file:

load 'composite_primary_keys/fixtures.rb'

I feel much better now.

Tuesday, July 29, 2008

Repetitive Stress

So, I've been programming pretty much non-stop for the past few months.  My wrists ad neck were suffering.

Rather than start wearing braces again, I opted to try this program (Mac-only) that interrupts you every so often.  ...I have it set for 12 seconds every few minutes, and 10 minutes every hour.  I started using it about a month aogo

It seems to have done wonders for my hands and wrists, so I highly recommend it.

Ain't done squat for my neck, though.  ...And some days, it gets really bad. : \

Wednesday, July 23, 2008

Wednesday, July 2, 2008

Using Vim and MySQL to Create Fixtures (for Rails)

...I've had to build a lot of fixtures using extant data from a MySQL database.  I don't want the whole database in my fixtures... just a subset, based on some examples I use in my specs.

So I run a query to get the subset I want, being sure to grab all the contents from a given table (and ONLY one table).  Something like this:

SELECT st.*
  FROM a_fancy_table ft
    JOIN some_table st ON (ft.id = st.a_fancy_table_id)
  WHERE ft.id IN (1, 2, 3)\G


The \G is essential, here.  I then copy the output of that to the some_table.yml file, created with vim.

Then:
  1. <ap multiple times, until everything is left-justified, then
  2. >ap once, so that it's all indented 1 level, then
  3. :%s/  \*\+ \(\d\+\). row \*\+/^Msome_prefix_\1:
  4. finally, rename any of those that are really significant.
...Of course, the ^M is really ^v[ENTER], and the some_prefix is whatever you want to name your objects.

...If that makes sense, you'll find it's a huge time-saver.  Unless you're copying entire tables, in which case you can use Dmitry's script.

Thursday, June 12, 2008

ZenTest and autotest in Windows with RSpec and Rails

I've been trying to monkey-patch ZenTest's autotest for over a month now.  Originally, I was trying to get it to work (well) with snarl, but that just seems frivolous at this point.  My focus now is just to get the damn tests working as they should.

First of all, Windows doesn't let you break out of the loop.  ...At least, not that I've ever seen.  I haven't heard a SINGLE person on the web talk about this, which is frustrating.  Maybe I'm missing something stupid, but I know other people that this is happening to.

Anyway, the fix for that is to change the "Kernel.sleep 1.5" on line 291 of autotest.rb... it works if you change it to this:

    30.times { Kernel.sleep 0.05 }

I don't know why, but I'm assuming it has something to do with how sleep is implemented on Windows that causes it to lose the scope of self.interrupted.  Or something.  Whatever: this works.

Next, I'll try to find a regex that will actaully find the right files to run, when there has been a change!  Grr.