Archive for the ‘Uncategorized’ Category.

search by article length/features

Google knows stuff about pages, but its not exposed for users to search on.  Trying to read something in depth on a nontechie topic (parenting) results in a lot of shallow SEO-aimed pages.  Searching for longer, authored articles would probably help, or specifying print magazines, or .edu only.   Books are still much much higher quality than the highest-ranked web pages for most non-technical topics.

Test::Unit::Assert(qr/pattern/,…) seems to fail on multiline strings

Recently had to change a number of lines from

$self->assert(qr/some_pattern/, $string, $message)

to

$self->assert($string =~ qr/some_pattern/m, $message)

Not sure why – the $string was a multi-line XML fragment, and the pattern was a phrase containing / and . chars. May need to do some more testing to isolate the reason. Works with the change. /m should not be necessary to match against a multiline string, but failed without this switch for my particular test cases.

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!