Archive for the ‘Uncategorized’ Category.

JAVA_HOME on linux (at least for compiling ruby-hdfs)

Posting this as the links I found for setting JAVA_HOME seemed to erroneously state to set it to the full path to the java executable. I’m not sure if there is a case where you would want to do that, but if you want to compile the ruby gem ruby-hdfs, then JAVA_HOME should be set to the directory above where the java binary is located, ie

export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.24/

where the java executable is located at /usr/lib/jvm/java-6-sun-1.6.0.24/bin/java. Then the install is straightforward

$ gem install ruby-hdfs
Building native extensions. This could take a while...
Successfully installed ruby-hdfs-0.1.0
1 gem installed

ruby non-intuitive multi-dimensional array assignment

All I want to do is work with an array of arrays…

ruby-1.9.2-p290 :012 > a = Array.new(8,[]) # here lies the problem...
=> [[], [], [], [], [], [], [], []]
ruby-1.9.2-p290 :013 > a[1].push("a")
=> ["a"]
ruby-1.9.2-p290 :014 > a
=> [["a"], ["a"], ["a"], ["a"], ["a"], ["a"], ["a"], ["a"]]

Trying again…

ruby-1.9.2-p290 :019 > a = Array.new(8,Array.new()) # This doesn't solve it
=> [[], [], [], [], [], [], [], []]
ruby-1.9.2-p290 :020 > a[1][0] = 'a'
=> "a"
ruby-1.9.2-p290 :021 > a
=> [["a"], ["a"], ["a"], ["a"], ["a"], ["a"], ["a"], ["a"]]

Argh! Perl makes this so easy…

Ok, the problem was, that the first two ways of initializing the array, were just creating 8 pointers to the SAME array

Now do it the right way:

ruby-1.9.2-p290 :031 > a = Array.new(8) { Array.new(0) } # NOW we have an array of different arrays
=> [[], [], [], [], [], [], [], []]
ruby-1.9.2-p290 :032 > a[1].push('a')
=> ["a"]
ruby-1.9.2-p290 :033 > a
=> [[], ["a"], [], [], [], [], [], []]

Ahh…but I miss an interpreter that always tries to ‘Do The Right Thing’

And, I wish the two versions didn’t look so identical when inspected…

The most helpful message yet

My Canon iP4300 printer is exceptionally helpful when anything goes wrong:

“Error Number : 311 Printer is in use or an error has occurred. If an error has occurred, eliminate the cause of the error.”

If an error has occurred, eliminate the cause! Why didn’t I think of that!

Oracle has broken registration form…

All I wanted was an updated copy of berkeley db…

Oracle has it, its free, but you have to register. Ok, I’ll register. The form has lots of required fields…two of which are broken select drop-downs with no options! This is embarassing for multi-million dollar company with a supposed commitment to open source, no?

Here is the culprit:

https://myprofile.oracle.com/EndUser/faces/profile/createUser.jspx

See the drop-downs for Job Title and State/Province.

Oh, and I tried the live chat. The rep told me to call the help line :
“No I can do nothing, please call one of those numbers to log and start a ticket sir”

Argh.

Perl equiv to PHP’s md5(uniqid(rand(), true)

Trying to shoehorn some data from the back into the wp_connections database, I needed a perl equiv to the md5(uniqid(rand(), true) function. From some general suggestions at http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_26773756.html came up with the following snippet:

use Digest::MD5 qw (md5_hex);
use Data::Uniqid qw (suniqid uniqid luniqid );

sub gen_token {
# approx equiv to md5(uniqid(rand(), true));
return md5_hex(uniqid);
}

Will also need to use Scott Hurring’s http://hurring.com/scott/code/perl/serialize/ to get it fully into the needed format…

activescaffold column overwrite – ugly

Perhaps this is somehow due to my config…but if it happens to me, it could happen to you:

I have a model, say table_one with a belongs_to: table_two. It happens that table_one and table_two each have a column named ‘datafile’. The two columns are intended to refer to entirely separate datafiles, and thru lack of imagination I named both the same. Now when I edit a row from table_one, it shows the associated row from table_two, and uses an identical name for the input fields for both ‘datafile’’s! record[datafile]

The result is that the datafile for table_one is wiped out on edit, as it is replaced by the blank datafile input for the associated record for table_two. Ouch!

Workaround of changing the name of the column in table_two fixes the problem.

Using activescaffold 3.0.5 for Rails 3.0

best practice for getting things – a hell of a lot of things – done

Seems to me the key is creating a language that lets you efficiently express what you need to. Well-designed dsl’s (domain specific languages) have a lot of power. But these guys are the ones that apparently know:

http://www.readwriteweb.com/hack/2011/01/secrets-of-backtypes-data-engineers.php

Rails docs!

Found a real effort to doc the rails framework! Not all filled in, but a huge improvement over the tutorial-as-doc approach:

http://apidock.com/rails

ie link_to

Thanks APIDock!

The problem with important authors…

…is that they are too important to take time for the grunge work that makes a technical book useful.

Agile Web Development with Rails is essentially a book-length tutorial, and imho not worth either the money or time. The entire book is narrative. It admits as much in the introduction: “This book isn’t meant to be a reference manual for Rails…reference manuals are not the way most people learn.” Maybe so, but they are extremely helpful productivity tools when trying to do actual work! (The narrative itself is so patronizing and self-aggrandizing its painful to plow thru, though probably does have some value if you can stomach it.) An auto-generated code API is no replacement for a human edited reference manual with context. It seems Rails requires you to ‘read the code not the docs’ in order to do anything nonstandard, which works, but…not exactly productivity enhancing as advertised.

Browsing a good reference lets you see immediately the structure of a framework.

PHP.net is beautiful and so efficient, I’ve never bought a PHP book either – but for the opposite reason I’d advise not buying this one.

Ruby yes, Rails…not so much

The thing that is the most annoying about rails, after the general atmosphere of one-upsmanship, is that the general arrogance about being the best way to do things seems to lead to lack of good reference documentation. Tutorials for specific ways to do a particular task in ‘the Rails way’ abound, but reference docs are limited to the actual api for the code. Method-level references with clear explanations are just..nonexistent.

Everything is eventually possible, with much reading of code and blog posts, but clarity as to what is possible in a given context – missing.

Ruby is a beautiful, elegant language. Rails popularized the idea of scaffolding, and yes, if you want to do the standard shopping cart of database items you are done in 8 minutes. However….if you want to do something else entirely, every step needs to be painfully discovered by deep introspection….

Of course Joel says this so much better: Joel on Rails