Slow BrowserSync in OS X with apache or nginx?

I’ve been testing out gulp.js some with BrowserSync for front end development on a new project. I saw a nice a video about it and got the feeling it would be a really nice workflow. But my BrowserSync proxy setup towards my local Apache site (php+mysql) was for some reason really really slow. The video showed an example using Node.js which was instant so to test that out I created a Node.js site and started gulp towards it. And the difference was like a really slow night and a really fast day. It was instant.

After much search and many Google I found this thread on Stack Overflow about someone having an issue with slow localhost/virtualhost load/resolve. And this reply:

I had the exact same problem and it was driving me crazy!

Put all your hosts file entries for localhost into one line like so: localhost myproject.dev myotherproject.dev
::1 localhost
fe80::1%lo0 localhost

Worked like a charm for me. Seems like a bug in Lion.

Because of my many web projects and my fondness of local development I have a lot of different virtual hosts. All pointing to All on different rows. So I went in to my /etc/hosts file and changed it. And behold. It worked. So now I can do my BrowserSync, sass powered, js minifying, gulp induced, front end development without coffee breaks in between changes. Which is really nice. I don’t even drink coffee.

Posted by David

111 111 songs scrobbled!

The 5th of December in 2004 I joined Audioscrobbler.com. It was (and still is, kind of) a service which let you log, or scrobble, all songs you listened to through your music player. In the beginning I was still stuck in Windows and I was using Foobar 2000 to listen to MP3 files which may or may not have been ripped legally from my own CD collection. I’ve always loved statistics and when I started to see weekly and monthly top lists of my most played songs I knew I had found a service I would stick with for as long as I could.

At the time I don’t think I even knew of Last.fm but when they finally merged the sites in 2005 I started using their Internet radio streaming type of service, which obviously also scrobbled everything, and my affection for the service grew deeper. I loved that you could like and unlike songs and that Last.fm from it could generate radio stations just for me. Radio stations that played songs that I liked. By connecting me to friends and people who liked similar music I discovered a lot of new music and bands that I still hold close to my heart. Last.fm also was the first online service I payed for and it may or may not have made me rip less of my legally bought CDs.

Unfortunately, due to different reasons, Last.fm had to change the rules and requirements for online streaming. And after receiving a beta invite to Spotify in 2008, just a month before it opened its doors to paying subscribers, I started to loose interest in the Last.fm streaming service. But I kept on scrobbeling.

Today, just 3 130 days later, I’ve reached 111 111 scrobbled songs! And this is cause for a celebration … Yay!

  • 111 111 songs in 3 130 days or 35.5 songs per day
  • If each song is about 3.5 min long, I’ve listened to 270 days, 1 hour, 28 min and 30 sec of music
  • Or 8.6% of the time
  • My most played artist is Grandaddy [Spotify] with 2 470 plays
  • My most played song is Jed’s Other Poem (Beautiful Ground) [Spotify] by the same band with 191 plays
Posted by David


Every Wednesday at 1500 hours it’s time for #redbullonsdag (Red Bull Wednesday).

This post is not in any way endorsed by Red Bull … But it should be … Do you work at Red Bull? Contact me!.

Posted by David

On the road to a WordPress core patch

One of my goals for 2012 is to to get credit for a patch in the WordPress core. It feels like it would be neat. Nerdy… But neat.

This vacation week, when I was going to play Skyrim, but ended up watching all Alien movies on Bluray and coding some WordPress, I might have found my bug. A user in a WordPress dev Facebook group asked if anyone had received pingbacks on custom post types. He hadn’t and was starting to believe something was wrong within WP. I thought it sounded like a fun thing to investigate. So I did. And it turns out it is… I think.

The reason seams to be that the XML-RCP server uses a function called url_to_postid() to get the post ID from the pinged URL. So if the ping is for a regular post and the site is using permalinks it might be something like feedmeastraycat.net/2012/01/08/on-the-road-to-a-wordpress-core-patch/ in which case /2012/01/08/on-the-road-to-a-wordpress-core-patch/ is sent in and the post id is returned. The problem seams to be that it doesn’t handle custom post type urls.

If there is a CPT named “products” and you have a post with the slug/name “macbook” you might have the url test.com/products/macbook/. The url_to_postid() function goes through the rewrite rules and tries to find a match. Which it should do. It then creates a query for that match, which in this case looks like this:

    [products] => macbook
    [page] => 

The problem here is that this query will fail. WP_Query requires a ‘post_type’ => CPT_Name parameter as well. It should look like this:

    [post_type] => products
    [name] => macbook

During a regular page call, this is made in WP->parse_request() (here). Not in WP_Query.

Well. I created a ticket and I’ve also added a suggested patch. In a comment. Cause I don’t know how to do it as a real patch… I hope that I haven’t missed anything. And that the higher up:ers like my patch suggestion. It would be nice to get a patch in early and free up 2012 for new goals.

Posted by David

Internet won… I’m now stuck in Skyrim

And it feels pretty good! It actually runs really well on my 12 GB RAM, 27″ display, mid 2010, iMac. In 1080p with settings on high … But I think I might have a smal bug with some face texture display thingy.


Edit: 2011-11-27 — Seams like Bethesda has released a patch during the night. Looks much better now! :-D

Posted by David

Steve Jobs – 1955-2011

RIP Steve.


Posted by David

WP: get_author_posts_url() in MU with sub-directories

Just a little tip here. We did a project with a multi site setup with sub directories. There was a photo blog on blogs.example.com/photo/, a food blog on blogs.example.com/food/ and the main/default site gets blogs.example.com/blog/ by default by WordPress. On the main site we wanted a list of the latest posts across the network. A couple of UNION SELECTs solved the data fetching. A loop with switch_to_blog() solved The Loop. But we had a problem with get_author_posts_url(). For some reason it added the default /blog/ sub-directory to all blogs. So instead of blogs.example.com/photo/author/feedmeastraycat/ we got blogs.example.com/blog/photo/author/feedmeastraycat/.

I guess the “problem” here is that switch_to_blog() doesn’t change the WP_Rewrite object. So when get_author_posts_url() calls $wp_rewrite->get_author_permastruct() it get’s the permalink for the main site blog plus the permalink for the selected blog.

Not sure if this is a bug. Or just a way that it have to work. Either way, I created a filter for author_link which solved the problem for us.

function my_author_link($link, $author_id, $author_nicename) {
	global $blog_id;
	if (is_main_site($blog_id)) {
		return $link;
	else {
		return str_replace("/blog/author/", "/author/", $link);
add_filter('author_link', 'my_author_link', 11, 3);

What we do here is getting the global $blog_id variable which contains the current blog’s id number. We run it through is_main_site() to see if this is for example the photo blog, or the food blog, or if it is the main site. If isn’t the main site, we do a string replace on /blog/author/ to just be /author/. But if it’s any other site we return the $link parameter as it is, unchanged.

Disclaimer: Not sure if the problem exists if you don’t have permalink structure. Haven’t even tested. :)

Posted by David

WordPress snippets

I’ve added a page here for some WordPress snippets I’ve created recently. Just for fun. They are small pieces of code where I doesn’t really feel the need to put them into plugins. The plugins feature in WordPress is great. Obviously. But sometimes when you do themes it’s nice to skip the initial fifteen odd plugins that all do one or two, small things. I’ve added the code to my Github repository. I’m a Github newbie. But it’s a lot easier to keep the code there, and make sure it’s updated, instead of posting it on the blog. And you can follow me there as well to see when I post updates… ;)

  • WPSettings — a set of classes to create a WordPress settings page for a Theme or a plugin.
  • WPCustomPostTypeArchive — add archive functionality to custom post types.
  • WPGetLatestTweet — a simple lib to get and cache the latest tweet for a username.
Posted by David

Happy Socks <3 Minecraft

These are so nice…




Posted by David

Google+ invite bug?

I just got Google+. There seems to be a bug in the invite system. If you share a link with someone who doesn’t have Google+ they can join. Without invites. Use it before Google fix it! :)

Added explanation:

1) Find someone who has Google+
2) Have them share a link with you (or someone who hasn’t got Google+)
3) Click the link in the e-mail sent
3) Join from that page

If it doesn’t work, Google might have fixed it! :)

In other news I’ve added ShareThis and Flattr. So Flattr me and I’ll use the money for good. I promise!

Updated – Twitter says that Google has closed the backdoor now. It was fun while it lasted … :)

Posted by David

Umlauts in hash tags in Twitter Tools – part 2

A couple of days ago I wrote about my problems with Å, Ä and Ö in my Twitter import. Read that post first…

Have you read it? No? Ok. I’ll wait a couple of minutes more then…

Done now? Good.

With the help of my co-worker Per I have now a fixed version of Twitter Tools that seams to work 100% with all allowed Twitter tags. The new regexp is as follows:


I have also remove the double space insert/remove thingy. So the whole thing looks like this:

$tweet = preg_replace_callback(
	, create_function(
		, 'return aktt_hashtag_link($matches[2], \' #\', \'\');'
	, $tweet

I’ve made another small change though to the aktt_hashtag_link() function. Which use to look like this:

function aktt_hashtag_link($hashtag, $prefix = '', $suffix = '') {
	return $prefix.'<a href="'.aktt_hashtag_url($hashtag).'" 
	class="aktt_hashtag">'.htmlspecialchars($hashtag).'</a> '.$suffix;

See that trailing space after “</a>”, that should be removed. With that extra space the tag “#åsa-nisse” gets a space after “#åsa”, and looks like this: “#åsa -nisse”.

So here is the final look in my Lifestream (red color was added to links for this image only):

Compared to how Twitter does it on their page:

I think that’s a success!? I’m gonna go ahead and send this to Crowd Favorite and see if they can implement it into the plugin.

Edit 2012-08-20 I’ve noticed that there still are some issues with this. I would recommend that you use the Twitter APIs entities to check what should be replaced and where. I’ve done that in the latest update to a small WordPress script that you can see here.

Posted by David

Umlauts in hash tags in Twitter Tools

I use the plugin Twitter Tools to import tweets into my blog which I put in my “Lifestream” to the right. It works really good, except that it seams to have a problem with Swedish characters like Å, Ä or Ö. I haven’t had the time or the will to try to fix it. But tonight … I did.

So here is the problem:

The tag should be #GöteborgsVarvet.

I started with The Google and found this thread on the WordPress support forum. But I didn’t like the look of it since it just adds to the reg exp character list. I could have just added my missing characters. But what if a Norwegian dude gets Internet and starts using The Twitter. That won’t do.

So I searched some more and came up with this solution. First I changed the reg exp to this:


It will search for any “word character” using unicode. Which should make it find å, ä, and ö. But also “the other ones”. From other languages. Then it breaks the tag when it finds any non-word character. For example a “-” or a “(” or something like that. This brings it closer to how Twitter does it:

What we see here is that Twitter gets all the strange tags, even with å or ö in them, but it breaks at the dash character.

However, I still had a problem with the reg exp. It couldn’t find tags in a row. If the tweet had three tags in a row it only matched the first and the last. I solved this, ugly, by first changing all white spaces to double white spaces. And after the hash tag match I change them back. So the full code now looks like this:

$tweet = preg_replace("/(\s)/", "  ", $tweet);
$tweet = preg_replace_callback(
	, create_function(
		, 'return aktt_hashtag_link($matches[2], \' #\', \'\');'
	, $tweet
$tweet = preg_replace("/(\s\s)/", " ", $tweet);

The only problem left now is that if you have a tag with a dash, it will remove the dash. So instead of “#åsa-nisse” with a link on “åsa”, like Twitter does. It outputs “#åsa nisse” with a link on “åsa”. Like this:

All tags are found, but the dash is missing from “åsa-nisse”.

Now I just hope that the guys over at Crows Favorite sees my e-mail and fixes this in the official release. Hopefully with an even nicer solution.

By the way…

To fix this hack, from home, on a Saturday, I finally bought Coda in the Mac App Store. It’s a bit expensive. I’m using Eclipse at work, which is free and has more features. I really miss the autocomplete features. But for quick hacks on Saturdays, Coda is really nice. Eclipse is bloaty and slow. I hope I can find some good plugins for autocomplete or that Panic can add it. I would love to be able to Switch. Coda feels more like Xcode 4. I would love to be able to do all my work in Xcode 4. But since I code PHP and not Objective-C at work … Well. Let’s give Panic some money by buying Coda and hope for the best! /rant

Time to go and give my Emma some cuddle before she gets totally bored out of her mind. Peace.

Posted by David

Custom Gelaskin by Smäm, again!

Ordered a new custom Gelaskin, designed by Smäm (still), this time for my iPhone 4. It looks almost as good as last time… I also put a front cover on it. All of a sudden I feel like those old people who keeps plastic cover on their sofas. But… Well. After hearing how Apple and the phone companies treat warranties on these things, I’m keeping it on for at least a year!

Posted by David

Small Twitter Tools extension to exclude twitter posts in feed

I’ve been using an old and modified version of Twitter Tools on my blog to import my tweets. They are imported as blog posts and then viewed on the Lifestream sidebar. I had to modify it cause the version I downloaded had a bug and a missing feature. It included @-replies, even though I told it in the settings not to. And I wanted to be able to exclude all twitter posts in the feed for any RSS subscribers.

A couple of days ago the old version of Twitter Tools stopped working though. It was missing oAuth. I downloaded the latest version and the bug had been fixed, it ignored @-reply like it where suppose to, but I still couldn’t remove the posts from the feed. (Which I had forgotten all about when my girlfriend asked me why all my tweets where appearing in her NetNewsWire all of a sudden).

This time thought, instead of hacking the plugin to fix my feature, I’ve created a small plugin extension. If you also uses Twitter Tools and wishes to exclude the twitter posts in your feed, you can check it out here or go straight to the download page.

Posted by David

Installing Boot Camp 3.1 on Windows 7 (64bit)

It was time for me to replace Vader (my black, big, loud breathing, evil Windows, PC). So I bought myself an iMac 27″ Core i7 2,93 GHz. Anakin is here. And he is a thing of beauty.

Most games I play these days are available for Mac. Which is good. But I recently bought Monkey Island™ 2 Special Edition: LeChuck’s Revenge™ on Steam, which is only available for Windows. So I started to install Boot Camp… Which was troublesome. Apparently the iMac and Windows 7 64bit isn’t compatible. Trying to install Boot Camp in Windows from the Snow Leopard DVD just gave me an error. I found out that I needed Boot Camp 3.1. Which can be downloaded from apple.com. However. To install 3.1 I first need 3.0. And we already know that 3.0 can’t be installed… Damn you Joseph Heller.

However. I found this guide which solved my Boot Camp installation issues. Cliffs:

  1. Open the Snow Leopard DVD in Windows
  2. Open Boot Camp\Open Drivers\Apple\
  3. Right click on the “BootCamp64” application and click “Troubleshoot compatibility”
  4. Windows 7 will recognize that it can run this application by disabling Boot Camp’s Version Check – Install Boot Camp
  5. Run Apple Software Update (might need to install it from the DVD also if BootCamp didn’t install it, not sure, I installed it before I managed to install Boot Camp) to install Boot Camp 3.1

Now my only issue is that I can’t use the native resolution of 2560 x 1440. It doesn’t recognize that it’s a 16:9 screen and is stuck on 1920 as max horizontal pixels. I’ll update if I find a fix for this …

Disclaimer: Sure, I could install Parallels, which I own … And I will … But I want both options. I want to be able to start Windows 7 inside OS X when I just need it to play easy going games or other stuff. Where I don’t need all the power. But I guess that Boot Camp will give Windows 7 better performance. So I want to have that option to.

Disclaimer 2: I’ve tried Apples display driver. Windows default drivers. And ATI Catalyst for Radeon HD, Mobility Radeon HD and their old Boot Camp specific drivers… The ATI Radeon HD 5750 in the iMac, apparently, in reality, is a Radeon HD Mobility 5850.

Update 2009-08-12 – Got a tip about which driver to download. Actually, I got two. Can’t get it working though. The drivers install fine. But I can’t access the catalyst settings. And it is still maxed out at 1920×1440. It runs fine in Parallels though. But if I switch between Boot Camp and Parallels I need to re-activate Windows. Which might make it sad and lock me out. Rumors has it Ultimate does not require this. I might upgrade. But for the time being I will stay in Parallels. Only need Windows for Monkey Island at the moment anyway. (And my girlfriend need it for poker).

Posted by David

Gelaskin by SMÄM

Ordered a custom Gelaskin, designed by Smäm, for my iPad. It looks perfect! Now I don’t need to keep TheBrad in a case all the time for fear of scratches on the back!

Posted by David

The separation of iPhone and iPad

So I got myself an iPad and I must say I like it. I still miss some Swedish characters on the keyboard. And iOS4 would be nice. But that will come. It would be nice if I didn’t have to jailbreak any of my devices to share my 3G connection from the iPhone. But I know that isn’t going to happend any time soon.

One thing I really don’t like though is some app developers separation of iPhone and iPad. I understand that some games are different on the two devices. It’s still kind off cheap but I’m ok with buying an excellent game like Plants vs. Zomies twice. I played it on my iPhone and it was such a fun ride I was more then ok with spending money on it again for the HD experience. I didn’t buy Angry Birds on the iPhone. But I did on the iPad. But when an app just changes the layout in the iPad version I’m a bit annoyed.

I got Net News Wire on the iPhone. Bought it again on the iPad. I really like Beejive on my phone and even though I spent over 100 SEK on it for the phone I bought it again for 75 SEK for my new device. But I’m not happy about it. But I use these softwares alot so. Ok. I can let it go. Somewhere I draw my line though. When Weather PRO want my money again I have to say now. It’s a really good weather app and I use it quiet alot on the phone. But I’m not buying it again just to get a new layout. Nooo sir. Not having it. That’s just wrong.

I wish more devs where like Twitterific. The new app is an universal app. It’s the same app you install on both devices. And if I upgrade to the ad free, which is an in app purchase, on one device. I can upgrade for free on the other. Kudos. You’re still a bit ‘effed if you bought the old version of the app though. But I’m ok with paying for new major upgrades. Like from Leopard to Snow Leopard.

I understand that devs have to get payed. And changing apps from one device to another can’t be done without the devs. But. No. I’m not having it. I don’t like it. So some apps will have to stay iPhoney on my iPad. And we can just hope that this won’t streach to iPhone pre 4 vs. iPhone 4. Non retina vs. retina. But I guess we would have seen it already. So. I guess my iWhine can stop. For now.

Still loving the iPad though.

– Sent from my iPad.

Posted by David

Update Services in WPMU and WordPress 3 Multisite

I heard that WordPress, for some reason, removes the ability to change the ping sites through the Update Services form under Settings > Writing in the admin area. I dug around a bit, I asked a WordPress developer and I found out that you can add a filter to get it back. It was westi who showed me the way. And said:

@westi: @DMRsweden The best thing to do is to use the add_filter but with priority 11 that way it will run after the default filter and win

So basically this is all the plugin needs to do:

add_filter(‘enable_update_services_configuration’, ‘__return_true’, 11);

But you can check for yourself. Download it here.

Update: It was brought to my attention that the plugin didn’t work as expected. The Update Services form was shown, but the data was never saved. Obviously I thought that I had tested it. But I worked on two different solutions and rather quickly… I guess I worked to quickly. :) Anyway, I found out that I needed a second filter, whitelist_options, to add the ping_sites form to the whitelist when saving the form data.

Now I only need a confirmation on that all the sites you add actually gets pinged to … Check out the source code here.

Update 2: @jonasbjork have reported that it seams to work. :)

Posted by David

WordPress 3.0

Just updated to WordPress 3.0. It is nice. Thank you WordPress team!

Posted by David

Notes PostWidgets

My newest plugin has just been submitted and accepted at WordPress.org. The idea of the plugin took form in talks between me and TDH who is the creator of the Notes Core WordPress theme and the writer of Smashing WordPress: Beyong the blog. The plugin is called Notes PostWidgets and this is the description from the readme file.

Notes PostWidgets is a plugin which adds a custom post type (“Post Widgets”) that you can use to create text widgets with. This way you can use the built in WYSIWYG (What You See Is What You Get) editor to set the mark up on your widgets. You can set a custom CSS class name for each widget for more specific mark up.

You can read more about Notes and the Notes Core WordPress theme over at NotesBlog.com. Download Notes PostWidgets at WordPress.org or checkout my project page where I will post update notes.

Posted by David