Find and eliminate illegal characters

I’ve been looking for a solution to a problem that a friend of mine has, with a bunch of files spread across several different folders which as gotten some really nasty characters in their file names, most likely because they used to reside on a windows partition.

While searching for a solution I came across this one app called detox which worked perfectly, and here is how I did it:

cd /path/to/folder/with/bad/files
find . -exec detox --dry-run {} \;

This will actually scan recursively, and the –dry-run flag won’t change any thing but it will give you a list of suggested changes, just remove the flag and re-run if you want to execute them.

Hope this could be of some help to others finding themselves in the same boat.


Tired of watching sloppy video playback from YouTube? I was, and it got me pretty exited when I came across this project called minitube.

It’s basically a browser for YouTube, you can search content (of course), add playlists, share videos to your Twitter/Facebook account but also via e-mail. But best of all, it can float on top of your screen so you can do some productive work while watching your favorites:) Pretty awesome when you want to follow a tutorial or just general multitasking. The app runs on Linux (GTK), OS X & Windows. The user interface is clean and simple, no clutter;)

One of the other things I found which is a huge plus and worth to mention is that the playback is flawless! And this has never been the case for me.

Gnome Shell Extensions

For everyone using Gnome 3 (the awesomest DE!) they have launched a pretty wicked shell extension site, it’s still in alpha but worked great for me.

You can create an account, write comments and even upload your own extension, but the main thing is they feature a one-click installer for existing extensions, just hit that link and the selected extension is installed and even loaded directly, no download/install/restart crap. It will also detect currently installed extensions, this thing is just awesome! One thing I miss though, is the ability to search for extensions, but I am sure they will fix this:) Check it out here.

Traq, the new kid on the block.

I was looking for something like trac the other day, because trac is a pain to set up and just a little too much for my small company. After browsing around for a while I came a cross this new project that simply runs on php/mysql, it’s called traq and my first impressions are positive.

I haven’t given it much testing yet, but I added a couple of our projects and successfully connected them to their dedicated svn repo. At a first glance it appears to have everything I am looking for in a ticket system, it can handle all the stuff I find most important like:

  • access control
  • users & groups
  • tickets
  • roadmap
  • changelog
  • wiki

You can browse the source of your repos, view revisions and you even get some graphs. The interface could use some polishing but overall it looks pretty nice, and if it does the job, I really don’t care:) A couple of other things worth to mention is that it also has support for themes and 3rd-party plugins.

Honestly I wish I could write a little bit more detailed, but I’ve only scratched the surface yet, so we’ll see. Visit traq for more information.

WordPress jquery form plugin, json parsing and IE

I have just recently written a Web Shop plugin for some clients, but after upgrading one of their sites to WordPress 3.2.1 it made my checkout code flip backwards in ie7 and ie8.

After some debugging and googeling I found out that older versions of IE has some problems handling application/json mime type (This is the correct header content-type by the way). So instead of content-type application/json I had to change it to text/plain, pass the data as an array and then json_encode, this worked for IE9 but still not for IE7/8. So after a few hours of more debugging I came to realize that this thing works fine using WordPress 3.1.3, so I began to compare the differences. It turns out that the jquery form plugin I was using in WordPress 3.2.1 was not working so well, after copying over from 3.1.3 it was all good, even down to IE7.

So if you want to make IE happy, stay away from jquery form plugin 2.7.3 and use content-type: text/plain in your headers, below is an example of how I do this for the klarna gateway module to make it work:

// Ajax Form Options.
var options = {
	target: '#shop-ajax-response',
	beforeSubmit: validate,
	success: respond,
	url: shop_frontend_ajax.ajaxurl,
	data: {action: 'checkout_order'},
	dataType: 'json',
	cache: false

// Bind form using 'ajaxForm'.

$feedback .= '<p class="shop-message">'.$shop_gateway_msg.' | '.$klarna_result.'</p>';
if(defined('DOING_AJAX')) {
	$response = array('success' => false, 'modal' => true, 'feedback' => $feedback);
	header('Content-type: text/plain; charset=utf-8');
	header("Cache-Control: no-cache, must-revalidate");
	header("Expires: 0");
	echo json_encode($response);

I know this is a half-way solution, I intend to notify about this problem so it can get fixed:)

wpshell & debugging wordpress

I came across this handy little shell tool yesterday while I was looking up a WordPress function… A couple of days earlier I was actually checking out a variety of debugging plugins for WordPress, the best one that I found at the time was the one I already had been using for a while, it’s called blackbox debug bar. While this plugin is really nice and more informative than the others, it doesn’t have the ability to limit debugging for admins:/

wpshell looks very promising and could be quite useful for debugging, if you are like me and feel more comfortable and in-control using the shell, you need to check it out: Easy to install and easy to use, It will be interesting to see how many different scenarios it could be used:)

Using custom fields to sort posts

Recently I’ve been working with a client that wanted me to create a way to sort recipes into different types of food and under different types of dishes. This had me thinking about custom fields where you have meta_key and meta_value for each key. The client also wanted to use this in other scenarios so basically i started thinking it should be sorted on categories as well. The function takes one argument which is the category slug, it will then loop through meta_keys belonging to that category, secondly the meta_values and third each posts matching that specific value.

It’s a whole new take on the custom field principle, since you basically start with the meta_key and not the post itself. Probably not the prettiest code in the world, but it does the job:) And it uses definition lists which is ideal here, below the function there’s a css example aswell.

To use this code, put it in your theme’s functions.php and fetch it in your desired template with

function cfMenu($catID) {
global $wpdb, $post;
$catID = get_cat_id('Mat');

$queryKey = "SELECT DISTINCT meta_key FROM $wpdb->postmeta
	LEFT JOIN $wpdb->term_relationships AS tr ON $wpdb->postmeta.post_id = tr.object_id
	LEFT JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
	WHERE SUBSTRING(meta_key,1,1) != '_' AND tt.term_id = '$catID'";

	$cfKeys = $wpdb->get_results($queryKey, OBJECT);

	echo '<div id="cfMenu">';
	foreach ($cfKeys as $cfKey) {
		echo '<dl>';
		echo '<h3 class="cfKey">'.$cfKey->meta_key.'</h3>';

		$queryValue = "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = '$cfKey->meta_key'";
		$cfValues = $wpdb->get_results($queryValue, OBJECT);

		foreach ($cfValues as $cfValue) {
			echo '<dt class="cfValue">'.$cfValue->meta_value.'</dt>';

			$cfPosts = get_posts('meta_value='.$cfValue->meta_value);
			foreach ($cfPosts as $cfPost) {
				$permalink = get_permalink($cfPost->ID);
				echo '<dd class="cfTitle">&raquo; <a href='.$permalink.'>'.$cfPost->post_title.'</a></dd>';
		echo '</dl>';
	echo '</div>';

Here’s a CSS example to get you started

#cfMenu {
	float: left;
	display: inline;

#cfMenu h3 {
	margin: 0 0 0 0;
	padding: 0 0 0 0;

#cfMenu dl {
	float: left;
	width: 230px;
	margin-right: 10px;
	margin-bottom: 20px;

#cfMenu dt {
	font-weight: bold;
	margin: 5px 0 0 0;
	padding: 0 0 0 10px;

#cfMenu dd {
	margin: 0 0 2px 0;
	padding: 0 0 0 10px;
	font-size: 90%;

A Smarter Menu for WordPress

With the release of wordpress 3.0 this function is no longer needed, I’d like to thank everyone showing interest in it:) I’ve always thought it would be nice to combine pages and categories all inside one menu, and recently I was looking for a nice way to add subtitles as well. So I thought it would be cool to write my own menu function to suit my own needs. Continue reading A Smarter Menu for WordPress