/labs

This is a blog by the staff at the web agency Earth People in Stockholm Sweden. Check out our work and get in contact with us here.

our www – experiment 001

2012-02-01 18:45:54

the new earthpeople.se is an experiment driven website, where we try out ideas in the background, where the actual content stays the same over time. we just love fiddling around with www, and we thought it would be a good idea to showcase this somehow.

the base of the website is a codeigniter install, with all content living inside one reusable model. using routes we can decide when to go live with a new experiments, by routing to a new controller.

in the first experiment we’ve set up a webcam, which will move around from day to day. our music machine (my old macbook pro) has been rigged with a couple of scripts to enable twitter users to decide our playlist. the playlists are logged in mysql and displayed on the website.

some fun findings when creating these scripts were:
- you can control the local spotify client by calling “open <spotify uri>” from commandline (at least in osx).
-  it’s easy to make your mac talk, from php. call “say <text to be spoken>” from within a system() call (we use this to make the mac read us whatever is playing next and who’s chosen it)
- spotify’s metadata api returns the duration of a song, which makes it easy to create a fake play queue from within php. the script playing songs is actually just an endless loop that sleep()’s the duration of the current song.

download the scripts here. bare in mind that these are just fun hacks and should maybe not be used in a production environment. oh wait…

/ peder fjällström

Christmas gift to the Internet: Hundstallet WordPress plugin

2011-12-16 17:04:22

I recently fell in love with _all_ the homeless dogs on the Hundstallet website.
I’m sure everyone would. And seeing as dogs has been mans best friend for many years, i thought we’d better give something back.

When installed, this WordPress plugin will override your theme’s 404 page and instead display a random homeless dog + links back to Hundstallet and to your homepage.
Try it here! Download and contribute here! UPDATE! We have now released this plugin at the WordPress plugin directory, we recommend you to download it from there in the future, still, the git repository will be kept updated as well.

Since Hundstallet is a Swedish organisation, all copy is in Swedish.

(Hundstallet does not know about this plugin. If you are a representative for Hundstallet and like us to take this plugin down, please let us know.)

/ peder fjällström

Moving WordPress 2.6 posts to a new 3.x installation

2011-07-29 22:05:45

You have an old 2.6 version of WordPress with 2 000+ posts and 100 000+ in total comments. Today you have installed a brand new WordPress 3.x blog and want to import all data from the old blog but it is just too much to export with the built in export function in WP 2.6. In 2.6 there is no filter option as in 3.x so we had to edit the core export.php to split up the export in parts.

The export.php you will find in wp-admin/includes/export.php

Include approved comments only

First we’re going to edit this file so that only approved comment will be exported, no need to keep the spam, right? This might lower the amount of comments to 30-40 000 instead of the 100 000 +. So, around on line 233 you will find

$comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d", $post->ID) );

Copy that line and comment it out. Paste the line above the old and after %d you add

AND comment_approved = '1'

so the finished code will look like

$comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM  $wpdb->comments WHERE comment_post_ID = %d AND comment_approved =  '1'", $post->ID) );
#$comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d", $post->ID) );

Save the changes and the first part is done.

Split the export into chunks

To split the export we use the LIMIT option in the database request and edit this file after every chunk we export. Let’s dig into the code again.

Around line 24 will you find

$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");

Copy that line and comment it out. Paste the line above the old and after ASC you add

LIMIT 0, 500

so the finished code will look like

$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC LIMIT 0, 500");
#$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");

The first value (0) tells where to start and the second (500) how many results to get. With this values the export will take the first 500 blog posts. The 500 value might have to be lower or can be higher, it all depends on how much load your web server can handle. Save your changes and go and run an export. If you get a popup about saving a file, everything works. If not, try to set a lower amount value.

The export option can be find in Design -> Export in WP 2.6

After the first export, we have to change the LIMIT values from 0, 500 to 501, 500 to get the next 500 posts. Repeat this and up the values after every export you do. Don’t forget go name your files with something like part1, part2 and so on.

Make the import

To import your posts and comments you first login to your new 3.x WP. In the Tools section in the menu you have the option “Import”. Go there and choose “WordPress” from the list.

If this is the first time you use this you will get a popup about installing the import plugin, go ahead and do so. After installing it, network activate it and go back to the tools -> import -> wordpress page.

Now you can select a file to import. Click browse and choose the first part of your exported files. Continue with clicking “Upload file and import”.

On the next page you have some options. You can choose to import the posts with the default admin user, create a new user och choose an existing. Also, check the “download and import attachment” to get pictures and other files that in your posts.

Repeat this steps with all your exported xml files from the old blog. Remember to import them in the same order as you exported them!

/ Mattias & Hjalmar

/ Mattias Hedman

Line-out scrobbler – when DJ’ing

2011-07-09 17:21:26

When DJ’ing at Debaser Slussen yesterday, we decided to hook up the Line out scrobbler to the DJ mixer. I knew that Echonest wouldn’t be able to resolve all weird stuff we play, but was hoping for at least 70% success rate. Unfortunately we had a resolve rate of about 20%, which make our little hack project quite a disappointment. We also had 3 incorrect resolves under the 7 hour long DJ set.

According to Echonest, the catalogue is only about 150 000 songs, and until this grows substantially, this project will be put on hold.

Here’s a clip of us in action last night:

Here’s the last.fm feed we scrobbled to:
http://www.last.fm/user/fredagsbiten

 

/ peder fjällström

Line-out scrobbler

2011-06-30 13:36:08

for years i’ve been trying to hijack music recognition services like shahzam to be able to recognize music. i’ve finally got this working thanks to the fine guys at echonest, who kindly provide a proper api for this. my proof of concept is running on a spare macbook.

here’s how it works on the mac atm:
1. the os x automator runs in a 90 second loop, recording audio with quicktime and then running a cli php script.
2. the php script first converts the recorded .mov file to .mp3 with ffmpeg/lame
3. the php script then runs the echonest binary for music fingerprinting, which generates a json string
4. part of the json string is sent via curl to the echonest service and (hopefully) resolved
5. echonest returns artist, title and a unique id. this id is saved i a recent-log so that the php script can skip a run if it runs 2 times during the same song
6. artist and title are curled back to our lamp-server, where we save all plays in a database (mongodb atm)
7. artist and title can then be sent to any service you wish to interact with

making this projekt was pretty straight forward, except for a minor obstacle which took me a few hours to figure out. it turns out that the echonest binary calls ffmpeg internally, and for some reason automator couldn’t find ffmpeg in it’s $PATH. when i realized this the fix was done in a second, i just needed to make a symlink from the $PATH automator used to where i had ffmpeg locally.

next step: will try this a few days and see how well it performs. if it’s good enough i’ll buy a tiny linux box and give it a pair of rca jacks.

links:
the earth people account on last.fm which we scrobble vinyl to atm
the awesome echonest service

/ peder fjällström

kanjagcykla.nu

2011-06-23 14:35:19

Vi som bara cyklar av estetiska skäl är rätt kräsna när det gäller väder. När man saknar skärmar vill man inte att det ska regna. Kanjagcykla.nu är en mobil webbapp som berättar för dig, utifrån var du befinner dig, om du kan cykla eller inte.

I bakgrunden

  • Koppling till yr.no:s API
  • mongoDB med en massa orter i Sverige, med latitud och longitud
  • Ett bibliotek för att hitta position utifrån IP-adress

I förgrunden

  • HTML5 geolocation API, för att hitta din position ännu bättre
  • jQuery
/ Hjalmar Hägglund

NOW On Roskilde

2011-06-06 10:00:30

Now On Roskilde is a mobile application which users easily can add to their homescreen.
It shows what’s on right now, together with related artists playing in the near future.

Since nothing is playing right now (+ the correct feed hasn’t been published yet), the app is pretty worthless at the moment. There is a way to get a preview though, by adding a querystring to the url. These urls below will fetch the Roskilde data feed from 2010.

# thu, july 1st 2010, 19:43
http://nowonroskilde.com/?timestamp=1278013434

# fri, july 2st 2010, 19:43
http://nowonroskilde.com/?timestamp=1278017704

nowonroskilde.com by Earth People is a quick hack put together for the Roskilde Labs competition. Also, feel free to use the php class we put together for this.

/ peder fjällström

Sami language detection – fugly hack!

2011-05-13 22:54:17

so you want to know if a text string is in sami? sami is way too indie for google translate, so i made a really ugly hack to check if a sentence seems to be sami or not. it’s php, you can download and use any way you want. i have no idea what kind of licencing risten.no (the datasource for this hack) uses, so be careful.

use it like this:

include('detect.class.php');
$smadetect = new langdetect;
echo $smadetect->detect_sma_sentence('i can haz musigke at cool club');
echo $smadetect->detect_sma_sentence('i can haz music at cool club');

download the php class here. enjoy!

/ peder fjällström

hashimage.com

2011-02-25 22:40:41

some days ago, my wife attended some kind of social media event, called ssmx. during the event my twitter feed was packed with twitpics, yfrog and instagrams, and i decided to make a quick hack. here it is:

http://hashimage.com

the idea is simple – you just feed it a hashtag and it will scour the twitter api for images, extract them and present them to you. granted, some design would be awesome. if any fellow co-workers read this – feel free to take a stab at it (site is hosted on our usual box).

yey for hacks. out.

/ peder fjällström

html5 validation with(!) facebook opengraph

2010-09-17 22:27:22

html5 is that new, cool(?) technology which you should(?) be using when making new sites. but, being the thorough developer you are – it just eats you up from the inside when your brand new html5 website won’t validate because your client decided to add a facebook like button.

the facebook open graph protocol/namespace/api/whatever which was released in spring 2010 will only validate with an xhtml doctype. if you want to work in a html5 doctype and use opengraph, you need to apply a little bit of server logic. have a look at this, i won’t bother explaining the source code, i think you’ll get it.

<?php
function is_facebook(){
if(!(stristr($_SERVER["HTTP_USER_AGENT"],’facebook’) === FALSE))
return true;
}
}
?><!DOCTYPE html>
<html dir=”ltr” lang=”en-US”<?php if(is_facebook()){echo ‘ xmlns:fb=”http://www.facebook.com/2008/fbml” xmlns:og=”http://opengraphprotocol.org/schema/”‘;}?>>
<head>
<title><?php bloginfo(‘name’); ?></title>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />

<?php if(is_facebook()){?>
<meta property=”og:title” content=”<?php echo $title;?>”/>
<meta property=”og:description” content=”<?php echo $description;?>”/>
<meta property=”og:type” content=”article”/>
<meta property=”og:image” content=”<?=$path_to_page_thumbnail?>”/>
<meta property=”og:url” content=”http://<?php echo $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];?>”/>
<meta property=”og:site_name” content=”<?=$the_name_of_the_site?>”/>
<meta property=”fb:appid” content=”<?=$your_fb_app_id?>”/>
<?php }?>

one thing to have in mind is that page level caching is a no go if you apply this tactic. if your cache is clever, you could possibly make an exception for the facebook user agent, delivering fresh content to facebook on all requests.

oh well, it’s just a thought. let me know if i missed something.

/ peder fjällström