Monthly Archives: July 2012

Client-side Rendering of RSS Feeds in Drupal

So I wanted to display the RSS feed of my latest Blog posts in the sidebar of my main website, which is powered by Drupal. Normally this would be trivial, if my Blog was also hosted by the same Drupal site. However, my Blog actually lives on a separate WordPress site running on the same web server. I wanted to learn both Drupal and WordPress, which is why I elected to have two separate CMSs (yes I realise this is just making life harder, but this is how we learn!).

Initially I installed the standard Feeds module, but for some reason it couldn’t aggregate the RSS feed from my Blog site. I eventually tracked the problem down to my web host Heart Internet. It seems they block loopback connections, which is preventing the underlying fsockopen() PHP call that powers the Drupal Feeds module from reading my Blog’s RSS file on the same server. Since all Drupal RSS modules use the same server-side socket connection model to read the RSS feeds, my only option was to use a client-side RSS aggregator.

After some research, I came across the PaRSS module, which uses the PaRSS jQuery plugin to actually do the work on the client. The installation is slightly complicated by the fact the jQuery plugins site is currently inaccessible due to development work, but you can download the necessary PaRSS files here. Once you’ve installed the module and library files, it’s quite easy to create a link (using the Link module) to represent the RSS feed URL, and then plug that in to a Drupal block with the formatter set to ‘PaRSS’ to ensure you get a nice jQuery-powered rendering of the RSS feed.

You can see my results in the left-hand sidebar of my main website, where it says “My Latest Blog Posts”. That is being populated on every page load by the PaRSS client-side library. This is not as elegant a solution as the Feeds module, but it offloads the effort from the Drupal server, and overcomes the restrictions of my web host. Sometimes you just gotta do what you gotta do.

Unlock your TrueCrypt Encrypted Device without the Exact Password

So here’s the rather embarrassing story…

A couple of years ago, I encrypted a USB stick using TrueCrypt encryption to store some important/valuable files. I then put it in my bag and forgot about it. This weekend I came back to it and realised I had forgotten the password. I could remember using a combination of a couple of other passwords for increased security, but I couldn’t remember which passwords I had used, or in what order or combination. After numerous manual attempts to find the right combination, I gave up resigned to the fact that I would just have to wipe the device and start again.

Then something occurred to me – “Hang on a minute, I’m a programmer!”. And then I thought “How could I lose such an important password?”. Since I encrypted this USB stick, I’ve become a disciplined user of KeePass and LastPass, and to be fair this is the only password not in my password database. But still, it must be possible for me to solve this problem.

The first piece of the puzzle was the command-line interface to the Windows version of TrueCrypt. This is more than adequate to be wrapped with a script. The second piece of the puzzle was the itertools Python module, which provides some very nice functions for iterating over various permutations/combinations of values.

So the stage was set – how easy will it be to write a Python script to solve this problem? It turns out the answer is pretty easy. I found the itertools.product() function to be the best fit for my requirements, as it will generate the Cartesian product of an iterable list of possible password components with itself, giving me every possible combination of the specified password components.

The other critical part of my solution was discovering the right combination of command-line arguments to provide TrueCrypt. Here is the magic Python statement, which will attempt to mount the specified device as drive letter “T:” using the given password in a non-interactive manner:

truecrypt_command = ""%s" /q /s /v %s /lT /m ro /a /p "%s" /b" % ( truecrypt_exe, truecrypt_device, password )

The rest was just glue code to read in the list of possible password components from a separate text file, and then loop over every possible combination/permutation until the password is found (or we run out of options).

Good news – the script works, and it found my missing password! The script is very basic and still uses some hard-coded settings, but you can download TrueCryptPasswordHunter.py if you think it will be of any use to you. It was written and tested with Python v2.7.3 32 bit on a Windows 7 64 bit machine.

Usage

Create a text file called password_components.txt in the same directory as the script, and populate it with possible password components, one per line. For example, if you think your missing password might be “monkeydoghorse” or “horsedogmonkey”, or something similar, then your password components file should contain the following:

monkey
dog
horse

Then just run the script and cross your fingers.

How to Override Inline Styles from an External Stylesheet

All web developers know that by default, inline styles take precedence over styles in external stylesheets. For example, the following inline style declaration:

<span style="color: red;">Red text</span>

will ensure the “Red text” is coloured red, even if the following is included in an external CSS file, or in the <head> styles:

span { color: blue; }

Now it is generally not a good idea to use inline styles, as one should avoid mixing markup (responsible for the content and structure) with styles (responsible for the presentation format). Sometimes this is out of our control, for example if you are using a CMS which generates HTML with inline styles. In this case, how do you override these inline styles to ensure the page looks right?

Fortunately, this is easily done by using the following CSS magic:

span[style] { color: blue; }

The presence of the magic [style] attribute ensures that this style declaration overrides whatever inline styles are specified for the <span> elements.

I know this trick is generally well known, but it’s useful enough to restate it, just in case you’ve somehow not discovered it yet! In addition, please note that as with most useful CSS techniques, I believe this is not supported in Internet Explorer 6 or 7.

A slight aside – you can also use the “!important” CSS rule to assign greater priority to specific styles, regardless of where they are declared, but this approach is frowned upon as it can interfere with style customisations made for accessibility reasons, and can also be a sign of poorly defined or structured CSS.

Rename/remove the default “Home” menu link in WordPress Twenty Eleven Theme

If you’re using the “Twenty Eleven” Theme in WordPress and you want to either rename or remove the default “Home” link in your main menu bar, this is what you need to do:

  1. Create a child theme of “Twenty Eleven”. You only need a basic child theme with a default style.css file and an empty functions.php file.
  2. Add the following code to your functions.php file:
add_filter('wp_page_menu_args', 'twentyelevenchild_page_menu_args', 20);

function twentyelevenchild_page_menu_args( $args )
{
    $args['show_home'] = {value};
    return $args;
}

where {value} is either:

  • “new name” – to give the “Home” link a new custom name, or
  • false – to disable the “Home” link altogether.

It’s possible that this approach will work for other Themes, but I have not tested that – please add a comment if you find out!

Reclaim space by removing Windows 7 Service Pack 1 Backup Files

Once you have confirmed that Windows 7 Service Pack 1 is working correctly, after using it for a few weeks without any problems, you may as well uninstall the backup files it left behind. Most people can reclaim 500MB to 1GB of free disk space by doing this. If you’re running on a small hard drive (e.g. a brand new SSD!) this may well be really useful.

Here is the easiest way to remove the backup files left over by the Windows 7 Service Pack 1 installation:

  1. Open an elevated privileges Command Prompt by right-clicking on “Command Prompt” in the Start Menu and selecting “Run as Administrator” from the context menu.
  2. Run the following command in the new Command Prompt window to remove the SP1 backup files:
dism /online /cleanup-image /spsuperseded

After a few minutes, if the process is successful you will see the following message:

Service Pack Cleanup operation completed.
The operation completed successfully.

NOTE: After removing these backup files, you will no longer be able to uninstall Service Pack 1, so please make absolutely sure everything is working correctly before removing the backup files.

If you would prefer to use a GUI to remove the Service Pack backup files, this is now possible using the built-in “Disk Cleanup Tool”:

  1. Open the Start Menu and type “cleanup”, then click on the “Disk Cleanup” program when it appears.
  2. Select the C: drive from the list.
  3. Click on the “Clean up system files” button at the bottom of the dialog.
  4. Select the C: drive again (if prompted).
  5. Scroll down the list and ensure the “Service Pack Backup Files” checkbox is selected.
  6. Click “OK”.
  7. Accept the warning message.
  8. The files will now be deleted.

How to remove the “Leave a Reply” Comment Box from a WordPress Page

For the standard WordPress “Twenty Eleven” Theme in WordPress v3.4.1, it’s very easy to remove the standard “Leave a Reply” box from a given page:

  1. Edit the page in question.
  2. Select the “Screen Options” drop-down menu from the top-right corner of the edit interface.
  3. Select the “Discussion” checkbox to make the Discussion options appear at the bottom of the screen, below the page editor.
  4. Scroll down to the “Discussion” options and uncheck both the “Allow comments” and “Allow trackbacks and pingbacks on this page” checkboxes.
  5. Then “Update” the page as normal.

The “Leave a Reply” box should now be gone! Now that you’ve enabled the “Discussion” options panel by default, you will easily be able to disable comments for any page by unchecking the same two options below the page content editor.

Quickest way to animate PowerPoint 2010 bullets

When used effectively and in moderation, animations can improve a slideshow by adding some visual interest and offering the presenter more control over the rate at which new points are displayed to the audience.

I’m new to PowerPoint 2010, so I’m making more of an effort to learn how to use it efficiently than I did with PowerPoint 2007 (which we’re still using at the office). I was making some slides in a hurry this afternoon and wanted to make a set of bullets “Fly In” one after the other. I knew how to do this manually, by animating each one in turn, but I’ve worked out how to do this with a few group selections, so here goes:

  1. Write all your bullets.
  2. Group select all bullets to be animated (i.e. left-click on the first bullet, hold down the “Shift” key, then left-click on the last bullet).
  3. Click the “Animations” tab in the Ribbon, then click on “Fly In”.
  4. Show the “Animation Pane” by clicking the button of that name in the Ribbon.
  5. All animation steps in the “Animation Pane” are already selected by default. Simply right-click on one of them and select “Start On Click” from the context menu.
Screenshot of the PowerPoint 2010 "Animation Pane"

They are now set to animate one after the other, rather than all together. The exact same technique will work with any other Entrance animation, e.g. “Appear” or “Fade”.