Drupal to WordPress Migration

Keeping up with security updates on Drupal is exhausting. Not because there are many updates, but because the update process is more time consuming than you would want for a simple blog. So as much as I like Drupal, it’s time I move this blog to WordPress (WP) and give that a go.

So far so good. I Had WP up and running in minutes and my only concern was migration of content. There are some random scripts and also professional commercial solutions for this migration, but I wanted to stick with out-of-the-box options (that are free). So here is what I did:

  1. Drupal has a great default front page RSS feed that it publishes to yoursite.com/rss.xml. So the first thing is to go into the admin/content/rss-publishing and change the settings to output as many pages as possible with Full Text. Then save down the rss.xml file for your site. This will give you an RSS file with all your basic posts.
  2. Then on your WordPress site go to Tools -> Import -> RSS (you might have to download and enable the plugin). Then simply load up the rss.xml file you saved in step 1 and voila! You’ve got your posts in WP.
  3. Now go through and fix up any images your content used. These are not imported with this process so you’ll have to upload them into WP manually and edit your articles to include the images instead of broken links.

Catches:

  • This only really works for basic content. All user details, comments, media and static pages are not migrated.
  • The migration works fine with WP v3.5.1 and Drupal 6.x.

Case-insensitive Autocomplete in Bash

I use auto complete on the command line all the time to avoid having to type the full name of a file. Love it. What I hate is how it’s case-sensitive in bash, so I can’t do “cd ~/desk” to go to the “~/Desktop” folder.

The fix for this is to use the shell input options file: .inputrc
Just set this one option and restart your shell:

echo 'set completion-ignore-case On' >> ~/.inputrc

If you happen to have a system wide inputrc settings ( /etc/inputrc ) and want it included then you should add the following to your .inputrc file:

$include /etc/inputrc

Enable HTTP Authentication on Dreamhost

If you are using Dreamhost, or other similar shared server host, and are having problems with HTTP authentication then this is something to try. In my case I had a RAILS application where I was positive I was sending the appropriate HTTP Basic Authorization header (from PHP) like so:

$urlNew = curl_init();
...
curl_setopt($urlNew, CURLOPT_USERPWD, $strAuth);
curl_setopt($urlNew, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
...

However the server would repeatedly reply with Not Authorized (401 error). It turned out that the Authorization header was not being passed from Apache to the FastCGI application. So where I had this rewrite rule in /public/.htaccess:

RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

I just changed it to this:

RewriteRule ^(.*)$ dispatch.fcgi [E=X-HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L]

And all was well.

Publisher 2007 PDF export loses text color

I ran into a bizarre issue yesterday. I had a Publisher 2007 document, with various different text colors utilized, and every time I exported it to PDF (using the 2007 Microsoft Office Add-in: Microsoft Save as PDF) all the colors were lost. I ended up with black and white text.

Printing worked just fine, and printing to the Adobe PDF print driver worked fine, but I wanted to save to PDF directly from Publisher (which gave me the best control over image quality). After a bunch of testing it turned out that the problem was that I had a black and white laser printer set as my default printer. So even though I wasn't printing to it, Publisher picked up the color properties of the default printer and applied them to the PDF.

So in the future, remember to set your default printer to something with color before saving to PDF.

SlickEdit and Emacs

Everyone has their favorite code editor. Different editors suit different needs, but I personally like two of them currently: SlickEdit and Emacs. Both are extremely flexible and efficient editors offering:

  • Column editing. If you aren't aware of this, you should look into it now. Here is a good column editing video.
  • Macro recording and playback.
  • Tagging.
  • Efficient code viewing/editing (side by side pages, etc), and editing. I.e. mostly keyboard driven and customizable.
  • Integration with debuggers.
  • Support for many programming languages.

The big difference between SlickEdit and Emacs is that SlickEdit is commercial software and Emacs is open source. If you are on a budget Emacs is a good solution and also lets you run the editor from a console (emacs -nw), which is handy.

If you go down the Emacs road you will need a little configuration. Below is a minimal set of settings I often use. Pick and choose, and then place these in your .emacs file (in your home directory on Linux, or in your Application Data folder on Windows).

;; ~/.emacs
;;

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(inhibit-startup-screen t)
 '(tool-bar-mode nil)
 '(transient-mark-mode t))

;; Resize window on load
(setq initial-frame-alist
      `((left . 0) (top . 0)
        (width . 100) (height . 60)))

;; Common User Access - Ctrl-X/C/V
(cua-mode)

;; In every buffer, the line which contains the cursor will be fully
;; highlighted
(global-hl-line-mode 1)

;; Prevent Emacs from making backup files
(setq make-backup-files nil) 

;; for emacs to insert spaces instead of tab chars
(setq-default indent-tabs-mode nil);

;; bind macro recording
(global-set-key [f7] 'start-kbd-macro)
(global-set-key [f8] 'end-kbd-macro)
(global-set-key [f9] 'call-last-kbd-macro)

;; scroll two line at a time with mouse scroll wheel, no acceleration
(setq mouse-wheel-scroll-amount '(2 ((shift) . 2) ((control) . nil)))
(setq mouse-wheel-progressive-speed nil)

;; column numbers
(setq column-number-mode t)

;; format title bar to show full path of current file
(setq-default frame-title-format
   (list '((buffer-file-name " %f"
             (dired-directory
              dired-directory
              (revert-buffer-function " %b"
              ("%b - Dir:  " default-directory))))))) 

;; allow use of the x-windows clipboard
(setq x-select-enable-clipboard t)
(setq interprogram-paste-function 'x-cut-buffer-or-selection-value)

;; ruby                                                                         
;; based on http://www.rubygarden.org/Ruby
;; /page/show/InstallingEmacsExtensions  
;;                                                                              
(add-to-list 'load-path "~/.emacs.d/site-lisp/ruby")

 (autoload 'ruby-mode "ruby-mode"
     "Mode for editing ruby source files")
 (add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode))
 (add-to-list 'auto-mode-alist '("\\.rhtml$" . html-mode))
 (add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode))
 (autoload 'run-ruby "inf-ruby"
     "Run an inferior Ruby process")
 (autoload 'inf-ruby-keys "inf-ruby"
     "Set local key defs for inf-ruby in ruby-mode")
 (add-hook 'ruby-mode-hook
     '(lambda ()
         (inf-ruby-keys)))
 ;; If you have Emacs 19.2x or older, use rubydb2x                              
 (autoload 'rubydb "rubydb3x" "Ruby debugger" t)
 ;; uncomment the next line if you want syntax highlighting                     
 (add-hook 'ruby-mode-hook 'turn-on-font-lock)

Adding Flash video to your website

If you want to set up a Flash video on your website, and you are using Linux, then this post is for you. I’ll cover the steps one by one. Keep in mind that there are many different solutions and I have only documented one.

1. Istanbul Desktop Session Recorder
Download Istanbul using “sudo apt-get install istanbul”. Istanbul will let you record either complete windows, or regions of the screen, and save them as Ogg media files. Use it to record your desired video.

2. FFmpeg
Download FFmpeg and use it to convert the Ogg file to a Flash video file (.flv).

ffmpeg -i input_file.ogg -f flv output_file.flv

3. Flowplayer
Now all you need is a Flash player to embed into your HTML page and play the Flash video file (this lets users pause, rewind, etc). There are many different options here, but one good option is Flowplayer. Download the package from their website. Place the following files from Flowplayer onto your website:

  • flowplayer-3.1.0.min.js
  • flowplayer-3.1.0.swf
  • flowplayer.controls-3.1.0.swf

Also upload your flash video file (output_file.flv in our example) up to your website. Note that Flowplayer won’t run by default if you try and run it locally. Then just add the following into your HTML page:

<script src="flowplayer-3.1.0.min.js"></script>
<a href="output_file.flv" style="display:block;width:425px;height:300px;" id="player"></a>
<script language="JavaScript">
flowplayer("player", "flowplayer-3.1.0.swf");
</script>

Note that the “player” parameter to flowplayer() must match the id value in the <a> tag. You can change the size around as much as you like.

Australian TLD registration

If you are looking to register an Australian top-level domain (TLD) you have many choices for a registrar and host. Your first stop should be www.whatsinaname.com.au to compare the prices between all the different registrars. Obviously you want to select a registrar and host combination (they may be different) to meet your requirements for support, up-time, cost, and features.

If you already have a host set up (it can be anywhere, not necessarily an Australian host), and you simply want to buy the .com.au TLD and redirect it, I would recommend hostess.com.au. In my experience they were fast and efficient. The signup asked whether I wanted a redirect and what the DNS info was, so there was nothing to configure, and the paperwork (including invoice) was emailed to me within minutes.

Signing jars with a Netbeans Ant script

Digitally signing a jar file is one step among many before releasing your jar to the world. It can help you identify your program as one that genuinely came from you. It can also make it harder for people to alter the program (although not impossible). I recently went through this process with OBZVault where I integrated signing into the build process (Ant scripts generated by NetBeans).

Firstly you should do some background reading. There is a great article at onjava.com that covers Java vs .NET Security mechanisms. If you are familiar with .NET Security this is a very good intro into the Java world. The tool that does the signing of jars is called jarsigner, and key stores are created with keytool.

Next you need to:

a) Create the keystore with keytool.

keytool -genkey -alias -keyalg RSA -keystore -validity 365

The keystore filename is usually a jks file, but you can call it anything. Remember the alias name you used for later. To check that the store is created correctly use the following command to view the contents:

keytool -list -v -keystore

b) Integrate jarsigner into your build system. If you developed your application in NetBeans 6.5 you will have a build.xml file in the root of your project. Add the following targets to build.xml:

<target name="-post-jar" depends="signjar">
</target>

<target name="signjar" depends="">
<echo message="Signing ${dist.dir}/application.jar ..."/>
<exec dir="${work.dir}" executable="jarsigner">
<arg value="-verbose" />
<arg value="-keystore" />
<arg value="keystore_file.jks" />
<arg value="-storepass" />
<arg value="store_password" />
<arg value="-keypass" />
<arg value="keypass" />
<arg value="application.jar" />
<arg value="alias_name" />
</exec>
</target>

That’s all folks. Next time I’ll discuss code obfuscation which can be integrated into build.xml as well.

TSVNCache.exe process slowing down Windows

I regularly use Subversion (version control system) along with the Tortoise SVN shell client. I mostly stick to the command line tools, but its nice to have some shell integration occasionally. Tortoise SVN provides this integration well.

Just recently however I noticed a runaway process called “TSVNCache.exe” using up a lot (in my case one whole processor) of CPU cycles. I saw this happen on both Windows XP and Vista. TSVNCache.exe is the Tortoise SVN process that is responsible for all those icon overlays in Explorer when you view your SVN repository. The process sits there and scans the status of your files and updates them with appropriate icons to indicate state (i.e. modified, added, etc). For some reason it started misbehaving on my machine and grinding everything to a halt (Tortoise SVN version 1.6.1).

tsvncache

The simple workaround is to turn these overlays off. You can do this by going to the Settings menu (right click somewhere in your repository and select TortoiseSVN->Settings), and turning “Status cache” to None (see above).

There are three settings for the overlay cache:

  • Default: Uses TSVNCache.exe to process icon overlays
  • Shell: Lets the explorer process handle and cache overlays
  • None: Turns overlay status cache off

In my case I didn’t care too much for the overlays so I just turned them off. You still get the green tick for checked in folders, but nothing else. Alternatives for improving the performance are to exclude and include paths for Tortoise SVN to monitor (in the same settings dialog again), and/or to show overlays only in Explorer (top checkbox).

Software shortcuts

How many times have you used your code editor to look for some text and either didn’t find what you were after, or worse yet – were told that it’s not there when in fact it was? I bet this has happened to us all at some stage, and after some struggle you master the editor and life goes on, however I want to go over some basic tools/commands that you can always fall back to.

One of the most useful is searching through files. In the windows world you should all know about findstr. In particular the following variation:

findstr /snip /c:"string to look for" *.cpp

This command will go through all sub directories, ignoring case, looking through all cpp files for the specified string. And it never lies. In the linux world you want to use something like this:

find . | xargs grep 'string to look for'

If you find yourself repeating steps like this often, place the command in a script. Here is the one I use (it ignores SVN hidden folders and uses color output):

#!/bin/bash
find . ! -path "*.svn*" | xargs grep "$1" --color=always

You can perform all the above searching by using only grep as well:

grep 'string to look for' * --exclude-dir=".svn" -R --color=always