Recovering your Mozilla Firefox bookmarks

My Windows installation recently ran into a blue screen of death. No problem. For many people that means a reboot. However, in certain rare cases, you can lose your bookmarks after something like this. I’d assume that most people would just start all over from scratch a little ticked off, but there is a way to get back your bookmarks.

Note: Your missing bookmarks might be due to other causes, like switching into the wrong profile (fix this by going into the Mozilla Suite Profile Manager). If you are sure this isn’t the case, feel free to continue reading. You can find more information at the MozillaZine Knowledge Base.

Firefox stores several daily backups of your bookmark files, but they are written over in a “rolling” fashion, such that eventually, all of your bookmark backup files will get overwritten.

According to the MozillaZine Knowledge Base, this occurs about five times in a day1, and they say that if you’ve lost your bookmarks that you should act fast.

If you are working on a corporate network or fortunate enough to have setup your home system to be imaged by something like Acronis True Image2 then it would probably be trivial (easy) to open up the latest image of your hard disk, and extract the bookmarks.html file from that.

step 1

To restore, first find a good working bookmarks.html file (if you have something like Acronis, you can find your bookmarks.html file in the same way). You can find these by searching for bookmarks.* as suggested by the MozillaZine KB article

On Windows XP:
Start->Search->All Files and Folders->All or part of the file name:->bookmarks.*

(I’m not certain if the same “structure” applies for Linux systems, but `find / -name bookmarks.*` might have the same effect. If you update your locatedb once in awhile, you can use `locate` to the same effect)

For some typical users, bookmarks.html will be in C:\Documents and Settings\(Your Windows User Name)\Application Data\Mozilla\Firefox\Profiles\.default

Search around in there for a working bookmarks.html backup, and move on to the final step.

step 2

Now, the final step is to simply replace your backup copy of bookmarks.html. But wait! There is a caveat! You must close Firefox while performing this step, otherwise your changes will have no effect (bookmarks.html will just be written with whatever Firefox closed with, which is nothing probably).

So close your browser window, and replace bookmarks.html by moving the current one elsewhere, then rename your backup to bookmarks.html. Open Firefox, and your bookmarks should be there.

1 You can modify the amount of bookmark backups stored by opening a Firefox browser window, typing in about:config in the URL box (hitting enter of course), typing in for filter backup (hitting enter again), and then modifying the browser.bookmarks.max_backups value to something other than 5.
2 Acronis True Image 7 was actually posted for free — and Acronis (as far as I last know) is still giving away serial keys for it. You may want to search around for it.

capistrano error: no such file to load — openssl (Ruby on Rails)

While setting up capistrano as suggested in Agile Development with Rails (2nd edition), you may run into the following error:
no such file to load — openssl

The full context of the error is below:

$ rake remote:setup
(in [deployment directory])
Capistrano/Rake integration is deprecated.
Please invoke the ‘cap’ command directly: `cap setup’
* executing task setup
* executing “mkdir -p -m 775 [deployment directory] [deployment directory]/releases [deployment directory]/shared [deployment directory]/shared/system &&\n mkdir -p -m 777 [deployment directory]shared/log &&\n mkdir -p -m 777 [deployment directory]/shared/pids”
servers: [“hostname”]
rake aborted!
no such file to load — openssl

On Ubuntu 6.06 (LTS) this means that the openssl ruby interface is missing, and that it needs to be installed:

$ sudo apt-get install libopenssl-ruby1.8

From the apt-cache description: libopenssl-ruby1.8 – OpenSSL interface for Ruby 1.8

Querying for a date range (Ruby on Rails)

Date ranges are very odd when you first scratch your head at them. Sometimes the first thought that comes to mind might be a solution that would select every single date, one by one in a loop.

It doesn’t have to be this way — with a date() column, it is possible to do a one line select of a range of dates, and return the rows in-between.

def self.date_range(from,to)
    Something.find(:all, :conditions => [ "BETWEEN ? 
AND ?", from, to])
 end

Drop that into a model, and where you need to, reference it:
@some_things = Something.date_range(from,to)

Update: As of 06-02-07 (Feb 06, 2007), you no longer need to do this. Its now built in if you upgrade to the latest and greatest Rails. The Ruby on Rails weblog gives the following example:

We’ve also brought over the enhancement to :conditions in Active Record that’ll allow you to pass in ranges and get them automatically converted to BETWEEN statements. Like:

Student.find(:all, :conditions => { :grade => 9..12 })

…which then becomes:

"SELECT * FROM students WHERE grade BETWEEN 9 AND 12"

Great!

Switching to from SQLite to MySQL (Ruby on Rails)

Ruby on Rails is a great thing. Migrations in particular, allow for schema-agnostic database setups in production and development (so using MySQL for development, and then using something like SQLite for production is extremely easy to do).

Migrations really start to rock when you run into pitfalls that come with using other databases (and need to ditch them quickly). SQLite in particular, has some concurrency problems that if not taken care of, may turn your cheery development release into a night of swearing, and sweat. Not to fault SQLite (as it really is a performance monster if you can use it), there have been some attempts at making concurrency better in Rails.

In the mean time, using a fully fledged database like MySQL can quickly turn your application around if it is running into concurrency problems. The question though, is how.

  • Getting into the switch
    The first step is to get MySQL setup via a package manager, or compile it. Since there are potentially hundreds of ways (with different combinations) of doing it, you may need to read up on the specific method required for your distribution or operating system.

    For example:

    Debian based distributions use: apt-get install mysql

    Fedora/Red Hat/CentOS distributions use: yum install mysql

    (Note that you may need to look up the precise package name since there may be multiple versions of MySQL available with apt-cache search mysql and yum search mysql respectively).

    After finishing up, (and making sure the root password is changed with mysqladmin -u root password newpassword1, etc), creating the database with `CREATE DATABASE myproject`, making sure MySQL is listening only where you want it to, and making another user for only that database (using GRANT), its time to edit database.yml.

  • Making database.yml play fetch
    Editing database.yml and setting development and production to point at your SQL database will do it here (or simply adding a space behind db:migrate and typing RAILS_ENV=production might do it too). The normal database.yml should be commented enough to show you the light–but beware, database.yml is very picky about formatting. In particular, I hear that it is very picky with spaces versus tabs (although i’ve never run into that problem using RadRails, as it appears tabs are converted to spaces).

  • Adding the MySQL gem
    You’ll need to add the mysql gem:
    $ sudo gem install mysql

  • Getting your database up
    Now the goodness of migrations come along. Go into your rails project root directory (that would be where you see “config, app” and others).

    $ rake db:migrate

    (or as above, rake db:migrate RAILS_ENV=production)

    If it worked without any errors, you’re on the path to glory. If not, look at what error got dumped out (sans the huge trace that follows), and take a stick to your problem.

  • Migrating your production data
    Here is the stickler. Although you can migrate SQLite data dumps by hand using:

    $ sqlite3 database.db .dump > dump-file

    $ perl -pne s/”//g dump-file > dump-no-double-quote

    $ mysql -u someuser -p somedatabase < dump-no-double-quote

    And replace all the things you get errors with (note that if you have things like booleans in SQLite, they’re represented in the database as t/f, and MySQL represents them as 1/0)..it becomes a pain with a huge amount of data.

    I have not tested it out (as I did the above search and replace pecking), but you may want to try this instead.

    1For the security oriented, you may want to either erase the history file with `history -c`, or do the password change the old way — via the MySQL client (documentation everywhere for that).