Archive for the 'Computers' Category

Add ‘Related Products’ to the Product Template in the Shopp WordPress Plugin

Problem: Today I needed to add some code to a Shopp (ver 1.1.9) product.php template so that related products (that have same ‘Tag’) would show up at the bottom. The ‘Related Products‘ template tag was not behaving as I expected it to.. i.e. it was stopping the product page rendering anything at all. Fix: After chatting to some [...]

Type a degrees symbol “°” on an iPhone

Fix: You don’t need to enable Japanese input languages or anything like that, just press and hold the zero ’0′ key and a ° symbol will pop up.

Flush DNS Cache on OS X (10.5+)

Open Terminal type “sudo dscacheutil -flushcache” (without double quotes) press Return, you’re done.

Launch Google Chrome Incognito from the terminal or a shortcut in OSX

Problem: Ok not really a problem, but I want to be able to launch Google Chrome straight to Incognito mode from a shortcut. This is useful when logging into multiple bank accounts, Google Apps accounts, or testing session based websites. etc etc etc. Fix: Thankfully the Google Chrome.app can be launched with the –incognito switch [...]

Reboot Mac OS 10.* to BOOTCAMP from a desktop icon

Problem: I want a quick way to restart my macbook and boot to the Bootcamp partition with one or two clicks, for the next boot only. The two existing ways are: Restart OS X then hold the option key after the startup sound to bring up the boot options. This can be a pain if [...]

Convert eregi_replace to preg_replace in old class.phpmailer.php scripts

Problem: I have lots of legacy php code on old sites that uses eregi_replace to format up an HTML email body. As eregi_replace is now depreciated it can be replaced with preg_replace. This is tricky sometimes because the formatting is quite different. Fix: Here’s a common line from class.phpmailer.php scripts: $emailBody = eregi_replace("[\]",”,$emailBody); To convert that you’ll need to do this: [...]

WordPress replaces double and triple hyphens (– or —)

Problem: The other day I was trying to type two hypens (–) in a post, and when I saved/published the post, WordPress reformatted the hypens to display as an ‘en dash‘ (–). More Info: After some searching about, and some helpful info provided in the WordPress Codex, I found out about a WP function called ‘wptexturize’ which is applied each [...]

Batch rename file extensions from .jpg to .png in terminal

Problem: A client sent me 164 images with incorrect extensions on them. I needed to change them all from .jpg to .png. Fix: Open up terminal, navigate to the directory containing all the images and type: ls *.jpg | awk ‘{print("mv "$1" "$1)}’ | sed ‘s/jpg/png/2′ | /bin/sh ..that should do it! This one-liner makes [...]

Add ‘Drafts’ sorting to Shopp Products list

Problem: There is no ‘drafts’ view filter in the Shopp (>1.1.9) Product Manager, i.e you can’t quickly list all the products that have ‘draft’ status in one go. Fix: I made this mod to answer a question in the Shopp Helpdesk forum, it’s not very tested, but seems to work perfectly! Open ‘wp-content/plugins/shopp/core/flow/Warehouse.php’ and replace [...]

Swap days and months in PHP – quick and dirty MM/DD/YY to DD/MM/YY

Problem I have a ton of date strings in the stupid US style dd/mm/yy format. i.e. 12/24/09 being 24th September 2009. I need to convert them to the UK style dd/mm/yy. Solution 1 As a string in PHP is really just an array of characters, the simplest fix was to address the individual number characters [...]