Categories: ,
Posted by: bjb

I wrote a small app to allow people to sign up to declare publicly, in a theme-based community, their intention of completing a project by a certain date. It was good practice to learn about django users and authentication and forms.

I wanted to allow the users to sign up and make their own accounts — but obviously I didn’t want them to mistakenly use a username that was already taken. But there is no obvious way to do that in the Django framework. The form validation takes place in a class that does not have access to the request information (where the user id is kept).

Fortunately for me, Ian Ward has already run into that problem and has solved it, both for plain old forms and for modelforms, in a very neat and elegant way.

Categories: ,
Posted by: bjb

I run Debian Sid on my laptop. Sid is the unstable or “Still in development” release of Debian. Just recently (on Jun 14, likely) grub was updated in a way that broke my boot. The symptom was that my laptop passed the BIOS, but printed something like “unaligned pointer 0x4c19a146” and then stopped. No grub menu, no graphics, no console, nothing. And of course, no response when you type stuff.

The (short-term, non-participative) solution is to downgrade grub until the problem is fixed. I got a question as to how to do the downgrade when your system won’t boot. So ….

First you find a CD that you can boot from. I used the Debian netinst CD. I had an iso image lying around for Debian 5.02, but pretty much any live CD that lets you have a shell will do. Stick the CD in the machine and reboot. If necessary, change the BIOS settings to boot from the CD first (not the hard disk).

The Debian netinst CD wants to do an install. Press Ctl-Alt-F2 to get another console, and press enter to get a prompt.

If you have one of those fancy-pantsy live CD’s that mounts your disks for you, you might have to unmount them first. At least you’ll know what the names are, in that case …

umount /dev/sda1
umount /dev/sda5
umount /dev/sda6
umount /dev/sda7
umount /dev/sda8

Now you want to mount your hard disks onto the running system and chroot to the root of the hard disk hierarchy. In my case, I have several partitions. I can never remember what the partitions are called — are they hda, hdb, sda, sdb or something else? So I look for disk-related entries in the output from dmesg:

dmesg | egrep '[sh]d'

or

dmesg | grep disk

or even

dmesg | grep '<'

Don’t forget to quote the angle-bracket on that last one.

It turns out my partitions are:

/dev/sda1  /boot
/dev/sda2  /
/dev/sda5  /usr
/dev/sda6  /var
/dev/sda7  /home
/dev/sda8  /srv

So I created a directory /mnt/target, and mounted the partitions:

mount -t ext3 /dev/sda2 /mnt/target
mount -t ext3 /dev/sda1 /mnt/target/boot
mount -t ext3 /dev/sda5 /mnt/target/usr
mount -t ext3 /dev/sda6 /mnt/target/var
mount -t ext3 /dev/sda7 /mnt/target/home
mount -t ext3 /dev/sda8 /mnt/target/srv

Then chrooted to the top of the disk hierarchy:

cd /mnt/target
chroot .

Then mount the proc partition (needed for dpkg later)

mount -t proc proc /proc

I looked in the logs to see what version was broken and what version it replaced. Looked in /var/log/dpkg.log … found that grub-pc_1.98-20100614-2 was the one that had just been installed and it was replacing grub-pc_1.98-20100602-1 which used to work just fine. I have been running apt-cacher on the laptop, and looked in the cache to see if the old package was still there — it was.

Then I was able to run dpkg to install the older version of grub. I found it with

ls /var/cache/apt-cacher/packages/*grub*

because that directory has a _lot_ of files in it and I was only interested in grub packages.

grub-pc depends on grub-common so I installed them both:

cd /var/cache/apt-cacher/packages
dpkg -i grub-pc_1.98-20100602-1-686.deb grub-common_1.98-20100602-1-686.deb

That command took care of the grub-install command for me ….

Then I rebooted and when it came up again, I saw a nice grub, and grub started up Linux and all was good. This way of rebooting will unmount the disk partitions nicely. It doesn’t matter that the netinst disk thinks you’re still in the middle of an install.

shutdown -r now

The last step is to tell dpkg and apt and the whole package management chain not to ever install a different grub version. Edit /etc/apt/preferences to contain:

               Package: grub-pc
               Pin: version 1.98-20100602-1-686
               Pin-Priority: 1001

               Package: grub-common
               Pin: version 1.98-20100602-1-686
               Pin-Priority: 1001

You’ll have to remember to change that at some time in the future so you’ll get grub updates. Personally, I’m not in a rush for that.

Note that I wrote this mostly from memory so paths and version numbers might not be exactly correct. Keep your eyes open, if you’re following these instructions!

Categories: , ,
Posted by: bjb

Not surprisingly, the blog spam commenters found my blog. Now I am investigating ways to ensure that only people comment on my blog.

With a little searching, I found that recaptcha is the recommended method these days. However, since Google has bought the recaptcha organization, you have to agree to a large legal agreement between yourself and Google to use it.

I’m not really up for that. It’s too bad as I might have liked to contribute to the “digitize old books” effort. So now I’m looking into regular captchas.

Categories:
Posted by: bjb

db migration:

When creating several tables in one migration, put them all in the same class. Give the class the same name as the migration. For example:

file: 001_create_tables.rb

class CreateTables < ActiveRecord::Migration

  def self.up

    create_table :sites do |t|
      t.string      :name     
      t.integer     :group_id,      :null => true
      t.integer     :moh_id                      
      t.integer     :playlist_id                 
      t.timestamps                               
    end                                          

    create_table :songs do |t|
      t.string         :title 
      t.integer        :site_id,     :null => true
      t.timestamps                                
    end                                           

    create_table :groups do |t|
      t.string        :name    
      t.timestamps             
    end

    create_table :playlists do |t|
      t.string       :name
      t.integer      :song_id,    :null => true
      t.timestamps
    end
  end

  def self.down
    drop_table :sites
    drop_table :songs
    drop_table :groups
    drop_table :playlists
  end

end

If several migrations are placed into one file like this:

files: 001_create_tables.rb


class CreateSites < ActiveRecord::Migration
  def self.up

    create_table :sites do |t|
      t.string            :name
      t.integer           :group_id,         null => true
      t.integer           :moh_id
      t.integer           :playlist_id
      t.timestamps
    end

  def self.down
    drop_table :sites
  end

end

class CreateSongs < ActiveRecord::Migration
  def self.up
    create_table :songs do |t|
    end

  def self.down
    drop_table :songs
  end

end

… etc

Then this error is likely: uninitialized constant CreateTables

(I guess because there wasn’t a class called “CreateTables” in the create_tables migration.)

Categories:
Posted by: bjb

Glen Newton writes about a study done on bug-fixing speed and reliability for econometric software packages. Five proprietary packages were measured in 2004 with a common set of tests, those five packages and one open source package were measured again in 2010.

The study concludes that the open-source software has fewer known bugs at any given time (they are fixed shortly after being found) while more than half the proprietary software had many of the bugs discovered in 2004, still open in 2010. For example, after applying the basic set of tests to the open-source project, they found: “all of the errors were corrected within a week of our reporting.” But, after all those tests were applied to the proprietary projects in 2004, only two of the vendors had solved all of those problems by 2010.

They might have picked a model open-source project for this study, but still it shows what can happen if you pick a good open-source product.

Still, when you are choosing your suite of software, choose carefully (even if every candidate for your suite is free). Try to pick the lively, active projects (but not the ridiculously lively ones, that don’t bother to go back and fix their bugs at all).

Categories:
Posted by: bjb

The pressure to know stuff quickly in high tech is enormous. I was glad to run across this article about the absurdity of it.

Categories:
Posted by: bjb

The byteflow community has a user mailing list and a hacker mailing list:

  1. users mailing list
  2. hackers mailing list

There is more info on the byteflow wiki and in the docs directory of the sources.

Also they talk on jabber: byteflow@conference.jabber.ru (logs)

Categories: ,
Posted by: bjb

The first two steps in fixing the html on my page have been taken. I’ve decided that no, I’m not going to fix it the easy way (by getting rid of the category cloud). And I upgraded my byteflow to the latest development version.

I looked at mercurial, and decided I didn’t want to learn yet another revision control system, so created a local git repository for my copy of byteflow, and checked the latest byteflow into it. Then created a branch for my changes and put my customizations into it. I have a separate sandbox where I can check out the latest from hg, test it, and check in to the main git repo. That’ll be fun.

Next, will be to report the problem to the byteflow people, and possibly try to fix it myself (if they don’t do it first).

UPDATE:

byteflow ticket 152

Categories: ,
Posted by: bjb

The Redhat-ish way to start and stop daemons is to use the service command. I just learned the Debian-ish way to do that is with the invoke-rc.d command. For example:

$ sudo invoke-rc.d apache2 reload

04/7: byteflow

Categories: , ,
Posted by: bjb

I tried validating (see below) the html on my new(ish) blog — it didn’t validate. It seems the category cloud is non-compliant. But I fixed up the CSS and that validates now.

I will check into the category cloud later.

<a href="/bjb/tag/android/"
title="Click to filter by android"
alt="count: 2"
class="tag-2"
rel="tag">android</a>

<a href="/bjb/tag/apache/"
title="Click to filter by apache"
alt="count: 1"
class="tag-1"
rel="tag">apache</a>

...

The validator doesn’t like “alt” tags on the “a” elements, for starters. The question is, why is it there? Of course it could be commented out (it’s in templates/tagging/tag_cloud.html) but what would break? … Stay tuned.

 continue reading