Archive for January, 2008

Inorrecto

Goin’ to California with the weekend in my heart

Robert Plant is joyous to return to the Pacific-kissing state.

ahem

Correcto

Goin’ to California with an achin’ in my heart

Robert Plant remembers great pains associated with a love he left behind in the Pacific-kissing state.

Imagined lives #1

Sunday, January 13th, 2008

I imagine this life…

A Parisian guy who owned a librarie-papetrie like the one in “The Science of Sleep”. Across the corner is a beautiful girl named Marie-Claire who knows his order: café, briôche.

The French I imagine too: “Ils barvardent tout le jours. Elle a des cheveux blondes et il sourit quand il fait ouvrire la porte.” I think that says something intelligible in French, yet.

The soundtrack to this life would be Brazilian Girls’ “Talk to La Bomb”. He rarely indulges in alcohol. He is not sure if he loves Marie-Claire, their relationship is comfortable, but it is not the sort of thing one makes a life out of, together, forever, before man and God is it? And why are they never at parties together, people you are to love, you see at parties (don’t you?). No, he thinks, she’s certainly not in love me.

The pens are arranged so neatly in the clear cube matrices.

These words:

  • .5 millimetre.
  • “Rouge”
  • “Vert”
  • “Noir”
  • “Encre”

Maybe she is in love with me. Or maybe it’s just the way you love regularity and the people that are involved in it.

Cat Power and hashish and beautiful dresses that have blue flowers in rich Georgia O’Keefe style on shimmery white thin draping. Parties should be like that, that’s where one finds loves, why isn’t Marie-Claire at such parties?

The moonlight dances across cobblestones in the rain on the lonely fall night, sunshine in thin winter air is wispy and reedy like the reams of A4 paper in a variety of colors:

  • Rouge
  • Vert
  • Noir

The lights go out as he pushes the switch, the locks, the keys, the jangling, the pull of the rideau-de-fer, closing the office products away for one more day. Until the sun, the café and peut-etre Marie-Claire…

Me lately…

Friday, January 11th, 2008

Rails…
…Lauren
Rails…
…work
Rails…
…school next week
Rails…
…Unicode
Rails…
…fingers hurt

[Rails] Cleaning up HABTM views (2/2)

Friday, January 11th, 2008

You may want to see the previous entry on this topic. We’ll be using that application.

The reality is that most people use Rails for web frameworks … the console manipulation stuff we explored in the previous post doesn’t really help us much. We need a web interface. While using the script/generate gave us some scaffolds that we can play with ( http://localhost:3000/candies or ../flavors ), it’s not really “integrated” and it doesn’t quite demonstrate the “has many”-ness.

First we’ll fire up the web server (script/server) and see what the ‘new’ view looks like:

ss2.

Hm, that’s certainly not giving us any place to enter some flavorful information. Let’s fix that in the view.

(more…)

The concept: “Many to Many” relationships

Many things in this life have a one to one relationship: a man has a wife ( Utah excepted ), a car has an owner, a dog it’s day. Many other things in life have a one to many relationship: a policy covers many people, a manager has direct reports, etc. But some things have a many to many relationship. People have surnames (“John Smith” is a Smith and so is “Jane Smith”;conversely, among the Smith clan there might be multiple Johns, 42 Janes, and 22 Larry’s ).

It is of this many to many relationship I will write and whose code I seek to share.

In this world there are many candies ( “Now and Laters”, “Sweet Tarts”, and “Kasugai’s Gummies” ) and candies have a flavor (chocolate, strawberry, cherry, and for my readers of an Oriental persuasion, lychee).

There are many candies which have a flavor, and a particular flavor has many candies which apply to it. This is a perfect, and simple example wherewith to demonstrate Rails’ ActiveRecord’s Associations.

(more…)

  1. Examine the Unicode standard’s code page collection for “Latin small letter a with macron”.

  2. Nets U0100.pdf

  3. “Latin small letter a with macron” appears on chart as 0101. This is a hexidemial number which points to U+0101 as its code point. Converting 0101 to decimal gets you 257, this is the same as the HTML entity code. Thus one can enter either ā or &amp#x0101; and get the right glyph [ā|ā]

  4. Put ā character into a view via Rails that is back-ended by a PostGres database.

  5. Using script/console, write the collection of models that contain this accented character to a YAML file.

  6. “Latin small letter a with macron” is stored in a YAML dump of accented charcters as: \xC4\x81

  7. Hm, OK that’s a start. Somehow 0101 or 257 is linked to C4 81. How? I know, BTW, the database that holds that entry is in UTF-8 as psql -l shows this.

  8. C4: 196

  9. 81: 129

  10. 196+129=325 != 0101. Hm, look at documentation.

  11. Be stumped.

  12. Send mail to mailing lists for help.


In the immortal words of Sid Meier’s “Civilization”: “Time Passes…”


  1. \xC4\x81 is the UTF-8 encoding for the Unicode code point U+0101.

  2. [Q:] Which table does U+0101 fall into?

    [A:] “So the first 128 characters (US-ASCII) need one byte. The next 1920 characters need two bytes to encode. This includes Latin alphabet characters with diacritics, Greek, Cyrillic, Coptic, Armenian, Hebrew, and Arabic characters. The rest of the BMP characters use three bytes, and additional characters are encoded in four bytes.”

  3. OK this means that the code point will be of the form: “110yyyyy 10zzzzzz

  4. We will now work to fill in the “y” and “z” values:

  5. Hexidecimal “U+0101” converts to binary: “100000001

  6. There are 5 y’s and 6 z’s. So let’s split the above number to match that form: “[00]100-000001”. Note, we moved from the right. Where the leading 0’s were required to turn 100 into 00100, they were pre-pended.

  7. Integrate and produce: “110” + “00100” : “10” + “000001” => 11000100 : 10000001

  8. Take THESE numbers and convert them back to hex => c4 81

  9. String notation for this is \xc4\x81 - violá!

  10. Figuring this out letter by letter is a major pain in the keester. A good URL resource is: Fileformat.info or, handily a URI of the form:

http://www.fileformat.info/info/unicode/char/<unicode char value>/index.htm

Special Thanks to: Michael Flester

This is more of a reminder to me for when I bang my head against the wall often and hard

>>reload!

Changes introduced by rake db:migrate and other tools will not be integrated into the console environment until you reload!

Rails: Loading test data with fixtures

Saturday, January 5th, 2008

Rails canonical story is:

  • “Fixtures are used to load sample data before a unit test”.
  • “Migrations are used to build DB tables and alter structure of contents thereof ( e.g., delete the “name” column and split the field on comma and put the resultant entries into the “firstname” column and the “lastname” column )”

But what if you need to bring in some good data — not test data, but data that you want for testing and seeing how things look with a “real” data set? What then smarties?

Here was my situation: I had entered data via the scaffolded interface and the the data included many unicode characters (&258;éæ, etc.). I wrote a little JavaScript table specifically to make entering these characters easy from an English keyboard.

I knew that I was going to invariably mess up the data and wanted to have the ability to get this preliminary data set back in ( it’s just safer that way ).

Furthermore the datas contained Unicode and I’ve just not had time to wrap my head around “entering Unicode values via command line into PostGres.

I dumped the data to a YML file with:

[code lang="ruby"]
x=File.open("models.yml")  
x.puts Model.find(:all).to\_yaml  
x.close  
[/code]

Looking at that Yaml data, I have my records.

I put that information into ../test/fixtures/models.yml

This file requires a bit of editing.

You will start with entries that look like:

    - !ruby/object:Model 
      attributes: 
        updated_at: 2008-01-04 19:32:10.874607
        id: "5"
        classification: Fourth
        created_at: 2008-01-04 19:32:10.874607
      attributes_cache: {}

You want to turn this into….

first:
  updated_at: 2008-01-04 19:32:10.874607
  id: "5"
  classification: Fourth

That is, reduce the indents of the “meaty data”, remove the “- !ruby” declaration and then put a numbering tag ( “first” ). This will help you import. You may find it handy to try the following in the console:

[code lang="ruby"]
directory="./test/fixtures"
require 'active_record/fixtures'
Fixtures::create_fixtures( directory, "models")
Conjugation.find(:all)
[/code]

Obviously, good data here is a good sign; errors, a sign of more work.

Then with rake db:load:fixtures I could get my data back in….but I wanted to make this addition hinge on a migration, so that I could move forward and backwards in the migration queue. Thanks to the skateboard book p.273 I found a way.

First I created a migration script/generate migration importBaselineData

Edit the 0xx_import_baseline_data.rb

[code lang="ruby"]
require 'active_record/fixtures'  
  
class LoadSampleData < ActiveRecord::Migration  
  def self.up  
    directory = File.join(File.dirname(__FILE__), "../../test/fixtures")  
    Fixtures::create_fixtures( directory, "models")  
  end  
  
  def self.down  
    Model.delete_all  
  end  
end  
[/code]

Thus with a rake db:migrate my migration with data entry gets entered.

I’m well past the age of seeing movies that are terrible for the purpose of throwing back a few beers and marveling at just how horrible it is.

But I remember that Mr. Shoemaker, at the beginning of UT football season, and I were both kinda excited to catch Shoot ‘em Up. We thought that, from the trailers, the gratuitous love of bullets would be an unashamedly bullet-heavy, ridiculous action-fest.

Through a moment of loopiness at the RedBox DVD kiosk, I found myself watching this with Lauren.

Now on paper my man-crush, and Lauren’s more conventional crush, Clive Owen will be afforded opportunities to excel all things he’s good at:

  1. Handsomely British
  2. Gun-wielding
  3. Jokey
  4. Will drive a BMW ( and no one drives a BMW like Clive see the BMW “Driver” series )

And my conventional crush, no opinions from Lauren, Monica Bellucci will be afforded opportunities to excel at things she’s good at:

  1. Being hot
  2. Being hot.
  3. Speaking Italian (although she really can act! See “Malena)

And the movie doesn’t fail to deliver as a send up of the ridiculous action-packed thriller ( “The Transporter”, oh hell, pretty much anything with Jason Statham). It doesn’t fail to afford the gunslinger a mysterious past, a vendetta, and a quick ( carrots, seriously ). And in this, the movie absolutely succeeds. Bullet casings fly, seas of bullets are dodged and human limits of pain are ignored. In this sense it is funny and fun.

But on another level, a plot level, it’s as intelligent as an episode of “Walker, Texas Ranger”, which, in college-times, was a favorite mark for cruel assessments of ridiculous characterization, lousy direction, and un-necessary slow downs of Chuck’s roundhouses.

In short, watch it when you can tolerate an absurd laugh or two.

Genetic Drift

Thursday, January 3rd, 2008

Wi 20010201 Dino de Laurentiis Granitz 141256

Guy on the right.

Sjff 03 img 1206

A siren.

Fran 9104270 59150

Have a daughter who has a daughter.

Giadaheadshot

Bless the power of of fame and money ( ça veut dire “resources” ) to improve the gene pool.

And this, my friends, is natural selection.