Smart redirects Smart redirects
  • Home
  • Posts
  • Home
  • Posts

Smart redirects

After migrating my blog over to WordPress, files have moved around a bit. Sites that linked to files on my site (including Google Images, as a prominent example) now link into the void, which is a bit of a pain. As a partial solution, I’ve added some .htaccess rules to help route visitors to the right place:

Redirect 301 /feeds/index.rss2 http://atastypixel.com/feed
Redirect 301 /feeds/atom.xml http://atastypixel.com/feed

However, that doesn’t solve all problems – after I reorganised my uploads, files are located at a very different path to their original home. So, I added a short script which does a search for requested files if they can’t be found, then redirects visitors to the right file.

Here is the script, and an accompanying .htaccess file needed to hook into it:

redirection.zip

To use it, put the script and the htaccess file into a folder on your site where you want it to take effect (for me, it went into ‘wp-content/uploads’). Then, modify the htaccess file – just set the RewriteBase field to the directory you’re in – and rename it to ‘.htaccess’.

Read More

Re-organising/assembling uploads for WordPress

Migrating from Serendipity, I’ve had a few hiccups in data migration. It doesn’t help that I’m extremely OCD when it comes to data, so everything’s gotta be perfect.

I had a problem with the way my uploads (the resources linked into the blog) were organised from the old Serendipity days – all in one big ol’ folder – and wanted to re-arrange them the way WordPress does it, which is to arrange them into folders by year and month.

This is also useful if you’re changing your domain, or splitting up one blog into two. The entries link to the old domain/blog, and thus the alternative is to do keep the old site around or muck around with clever redirects.

My way’s neater.

So, I put together a script which goes through all posts, pulls out links to uploaded files, and moves/copies them into a better arrangement, fixing the link in the process. If it can’t find the files, it’ll use a ‘find’ command to attempt to locate them.

In case it’s useful to others, the script is here: reorganise-wp-media.php.zip

It goes in the WordPress webroot; put it there, then edit it to apply your settings. Give it a ‘dry run’ test, make sure all is well, then go for it. Beware, although I used it and it worked okay, I offer no guarantee that it won’t mangle your data, delete random files or eat your dog.

Read More

Serendipity (S9Y) importer for WordPress

Update 2: Jon reports that he’s improved on Carsten’s 1.3 version, and has released Version 1.4!

Update: Carsten Dobschat has continued the fine tradition and improved the importer further, adding support for extended posts, and tags.  Grab S9Y importer version 1.3 over at his site.

In the process of merging this site from Serendipity over to WordPress, I came across an importer which lets me migrate the data across. Unfortunately it was a bit buggy, not properly assigning categories and timing out when processing the post data.

I made some improvements, and here’s the new version, if anyone else finds it useful:

Version 1.2 of Serendity importer for WordPress (patch)

Read More

Replacing the existing Leopard PHP installation with a more complete version

The good folks at entropy.ch have packaged up a pre-compiled version of PHP to replace OS X 10.5 Leopard’s barebones installation. The entropy.ch build contains most of the good stuff that the Apple folks in their infinite wisdom didn’t see fit to include – entropy-phpinfo.pdf

See the instructions at Entropy’s forum, or read below.

sudo mv /usr/local/php5 ~/Desktop/php5.old
curl -O http://www2.entropy.ch/download/php5-5.2.5-6-beta.tar.gz
tar -xzf php5-*-beta.tar.gz
sudo mv php5 /usr/local/
sudo ln -sf /usr/local/php5/entropy-php.conf /etc/apache2/other/+entropy-php.conf
sudo apachectl restart

Read More

Convert text to iTunes audio book

200805071617.jpgAfter reading a hint on macosxhints on how to create an audio file from text, because I wanted to keep reading my book while I was driving, and figured that holding the book in front of me probably wasn’t the best option, I figured the process could probably be streamlined a bit.

So, I’ve made a service which appears in the Services menu and operates on selected text. So, select it in Safari, or from an eBook in Preview (or Textedit if it’s just plain text), and click ‘Speak to iTunes Audio Book‘ to speak the text into a track in iTunes that will appear in ‘Audiobooks’.

Read More

Nasty long sleep times with SleepWatcher

If you followed my prior hint on automatically ejecting volumes on sleep (@ macosxhints), I’ve just discovered that SleepWatcher adds about 30 seconds to the time taken to sleep. This has been a big frustration to me over the last month or so, and now I know why.

I’m removing the utility – I’d rather shorter sleep times than automatic volume ejection. What a shame, though.

Incidentally, while we’re talking sleep, recent Macs also save the contents of RAM onto disk when they sleep. For the purposes of comparison, my 2 Ghz Macbook Pro with 2 Gb of RAM takes about 18 seconds to sleep. There are a variety of ways to alter sleep behaviour, but the easiest is the SmartSleep utility, a preference pane that handles it for you.

My favourite feature is its namesake, smart sleep, which will only do a hibernate if the battery is below a pre-set level (default 20%) – that means fast sleep until it’s a good idea to actually backup the session to more long term storage, when the battery is about to fail. Voila, simultaneous cake have-age and eat-age.

Read More

Automatic genre identification and ‘similar track’ matching

200804101846.jpgI’ve got a bit of new music lately, and I’ve noticed that the genre is always a bit off. Genre is a pretty tricky thing to figure out for most modern music, as there’s so much ‘cross-pollination’ going on in the music world. Additionally, over a single album, several genres may be visited (eg. folk, acoustic, pop).

There’s no way anyone’s going to go through every track independently and assign a genre (unless they’re seriously O.C.D). So, automatic genre setting (a new AutoRate feature?).

It looks like there has been some work done in the field, although it looks like it’s all still at the early-research stage; I haven’t found any available software. So there’s another possible project.

Another use could be to build a database of tracks in the local music library, and offer similar tracks when playing, constructing an automatic playlist. The same could be done with an online database, similar to Pandora.

Read More

Automatically eject all disks on sleep, reconnect on wake

sleep-macbook.png

Using a laptop with permanent external drives can be a bit annoying when you leave the desk – you have to manually eject all your devices, otherwise you get that dreaded ‘Device Removal’ dialog. With a little bit of Terminal magic, you can automatically eject disks when you sleep the laptop, meaning you can just put the lid down and go. Disk are also reconnected automatically on wake, for when you’re just sleeping the computer without going places.

It’s all thanks to a little utility by Bernhard Baehr called SleepWatcher, which runs in the background and is triggered by sleep and wake events, calling scripts to perform required actions.

Download and install SleepWatcher and its StartupItem.
Next, you’re going to create ~/.sleep and ~/.wakeup files which SleepWatcher will call upon. Pull up your favourite text editor and paste the following in (should be just two lines):

#!/bin/sh
osascript -e 'tell application "Finder" to eject (disks where free space ≠ 0)'

Save the file – call it “sleep.txt”, and save it to the Desktop; make sure it’s plain text! Then put the following in another file, called “wakeup.txt”, saved to Desktop too (also just two lines):

#!/bin/sh
/usr/sbin/diskutil list | grep -e ' +[0-9]+: +[^ ]+ [^ ]+' | sed 's/.(disk[0-9].)/1/' | xargs -I{} /usr/sbin/diskutil mount {}

Next, open the Terminal (Applications, Utilities, Terminal), and type the following:

mv Desktop/sleep.txt .sleep
chmod a+x .sleep
mv Desktop/wakeup.txt .wakeup
chmod a+x .wakeup

Now, whenever you sleep your machine, the external drives will be ejected automatically; when the machine wakes again, all connected external drives will be reconnected.

Read More

Hi! I'm Michael Tyson, and I run A Tasty Pixel from our home in the hills of Melbourne, Australia. I occasionally write on a variety of technology and software development topics. I've also spent 3.5-years travelling around Europe in a motorhome.

I make Loopy, the live-looper for iOS, Audiobus, the app-to-app audio platform, and Samplebot, a sampler and sequencer app for iOS.

Follow me on Twitter.

Posts pagination

« 1 … 31 32 33 … 36 »
© 2021 A Tasty Pixel.