Older blog entries for johnnyb (starting at number 161)

Red Hat Archives

Someone on IRC just gave me this link: Red Hat Archives. It goes back to every release of Red Hat Linux that RH ever produced (i.e. through 9).

I had an issue on an old RH8 server that I needed to reinstall RPMs, and this worked fabulously. Thanks, RedHat!

And, if you want to know what RH looked like when it started, it goes all the way back to 1.0!

23 Jan 2007 (updated 22 May 2007 at 01:45 UTC) »
onchange and Remote Forms in Rails

The problem with remote forms is that they use onsubmit to submit them. Unfortunately, Javascript does not fire onsubmit() when submit() is called :(

This causes problems with form_remote_tag in Rails, because that uses the onsubmit handler to work its Ajax magic. However, if you try to use Javascript to submit these forms (which I like to do from onchange handlers in select boxes), the onsubmit() function doesn't get fired.

Therefore, to work around, I use the following code:


collection_select("objname", :key_method, the_collection,
:id_accessor, :text_accessor, {}, {:onchange =>
"if(onsubmit()) { submit(); }"})

I haven't tested this beyond FireFox, but it seems to be working so far.

UPDATE: A more cross-browser version of the last parameter is shown below (submitted by a reader):


{ :onchange => "var f = document.forms['#{form_id}'];
f.onsubmit();" }
PS3 Linux

For those of you interested in Linux on the PS3, I just started a new article series at IBM DeveloperWorks describing how to program the PS3 under Linux. Here is the first article:

Programming high-performance applications on the Cell BE processor, Part 1

Just figured out a cool little metaprogramming trick for ruby on rails. In application.rb, put the following code:


        def self.pages(*pgs, &block)
                if block == nil
                        pgs.each do |pg|
                                class_eval <<-EOF
                                        def #{pg}
                                        end
                                EOF
                        end
                else
                        pgs.each do |pg|
                                define_method pg, &block
                        end
                end
        end        
Now you can define actions much, much easier. For example, if I have pages with no actions, I can just do page :index, :another_page, :another_page2 rather than def/end'ing each method. In addition, if you have a common action for a controller (in my case, initializing the @user variable) you can just do:

        pages :edit, :show, :whatever_other_action_i_want do
          @user = User.find(params[:id])
        end
And viola! Instant actions automatically defined!
Rails Rocks

Just started Ruby on Rails. I'm still a newbie, but I think a good 3/4 of the code on my last project could have been unnecessary because of ActiveRecord. And the AJAX stuff that installs with it is just fantastic. While those libraries are available on their own, I would have never known about them without Rails, and then would NEVER have been able to do those types of things.

RAILS ROCKS!

I've been having a Ruby on Rails PostgreSQL issue. I installed ruby, rubygems, and rails. I used gem to install postgres and ruby-postgres. However, after installing both of these successfully, when I try to access them via my rails app, I get the following:


rake aborted!
no such file to load -- postgres
I reinstalled both, but to no avail. It turns out, on some Linux dists, postgres has trouble linking with libpq.

However, thankfully there is a ruby-only version of the driver. Therefore, to solve the problem I did:


#Uninstall postgres and ruby-postgres
gem uninstall postgres
#Install ruby-only postgres driver
gem install postgres-pr
#Install rails adapter
gem install ruby-postgres
And my problem was now solved!

My Mac broke, and now its in for repair. Which means I had to borrow a computer. And the only computer available for borrowing was a Windows box. And each day I remember just how much I hated Windows. Thankfully, my wife is wonderful and let me borrow her iBook when working form home. So not all is lost.

What to do if you can't turn off magic_quotes_gpc on your host:

if(get_magic_quotes_gpc()) {
        foreach($_REQUEST as $key => $value) {
                if(is_array($_REQUEST[$key])) {
                        $_REQUEST[$key] = array_map("stripslashes", $_REQUEST[$key]);
                } else {
                        $_REQUEST[$key] = stripslashes($_REQUEST[$key]);
                }
        }
        foreach($_POST as $key => $value) {
                if(is_array($_POST[$key])) {
                        $_POST[$key] = array_map("stripslashes", $_POST[$key]);
                } else {
                        $_POST[$key] = stripslashes($_POST[$key]);
                }
        }
        foreach($_GET as $key => $value) {
                if(is_array($_GET[$key])) {
                        $_GET[$key] = array_map("stripslashes", $_GET[$key]);
                } else { 
                        $_GET[$key] = stripslashes($_GET[$key]);
                }
        }
}  
Getting Screwed by Register.com

Starting last week, I was unable to log in to my register.com domain. Not only that, it did not even list my login or domain in the "forgot username or password" form. I became a non-existant person.

So I contacted their support, who sent me a "change password" link. I filled it out. After filling it out, it logged me in, and I thought all was well.

The next week, I tried logging in again -- same result. I could not log in, and neither my username nor my domains were listed in the "forgot password" form. And now their support chat people were not even sending me links.

So, I had the person who the account is registered through call them. Well, it turns out that their old customers have to log in THROUGH A DIFFERENT URL. Well, gosh, THANKS FOR TELLING US ABOUT IT! Perhaps that message should be included where it says "No account was found for the username". Or even in the Password FAQ. But no, they just don't let you login and then stop returning your support requests. Thanks a lot.

For those of you in the same situation, the old login URL is http://mydomain.register.com/

We are now in the process of moving all of our domains somewhere else.

PHP has the MOST TERRIBLE defaults of any language, and MySQL drives me nuts

First of all, magic quotes should not even exist. Much less should they be ON BY DEFAULT. And they could AT LEAST do us the courtesy of providing a standard function to de-magic-quote everything if and only if they are on. It should be called undo_magic_quotes_if_they_are_on_so_i_dont_kill_the_webmaster_of_my_host()

The semicolon has been recommended as a standard parameter separator FOR OVER A FREAKING DECADE. Can we not set arg_separator.input to "&;" by default? And why do webmasters not do this? It's been OVER A DECADE since the recommendation was made!

Register globals should be off. I can't remember what the default is set to.

And WHY ON EARTH do different database drivers have different representations of "true" and "false"?!?!?!?! I don't care what you do but PLEASE BE CONSISTENT!

That's all I can remember for the moment. I know there are more, though.

But really, what psycho set these defaults to begin with. Who on earth, without knowing what application is going to be run on the data, automatically munges it for a specific application (databases, in this case -- specifically databases where the programmer is too lazy to be bothered with parameterized queries!)

And then MySQL. Goodness! You can't call a function in a default value? Why the @#$@ not? And timestamps can only default to CURRENT_TIMESTAMP if they are the _first_ timestamp column in the table? Are you freaking kidding me? And no sequences? Why on earth! They aren't that hard to implement. Oh -- that's right -- you would need functions as default values to make use of them!

Grrrrrrr.....

This is why I don't let other people host my stuff.

152 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!