/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.

Pantaluren.se (in swedish)

Vi lanserade just ett eget projekt. Earth People är delaktiga i detta, inte bara som byggare utan även som partners. Tjänsten är inte färdig eller perfekt, men vi gillar att släppa saker tidigt och iterera ofta, så ha det i åtanke. Hittar du nån bugg, säg hemskt gärna till.

Tjänsten heter Pantaluren, och är i sin enkelhet ett ställe att sälja din gamla iPhone på. Så småningom kommer vi ta emot fler slags enheter, men för nu endast iPhone.

Eftersom vi är som vi är byggdes tjänsten runt ett egetdesignat REST-API. Detta API går det bra att ansluta till vid behov, om du behöver en tjänst som värderar smarta mobiler. Hör bara av dig isåfall!

Om vi ska få in lite tekniskt fokus här på labsbloggen kan jag nämna att tjänsten är byggd på CodeIgniter/MySQL/Memcached och renderas som HTML5 av Handlebars.js och Require.js.

WordPress loops: with_posts() is my way of dealing with them

One of the most boring, cumbersome and dangerous things with WordPress is getting and working with posts in custom loops.

A common situation is like this:

That’s a bit cumbersome I think. Do I really need to do that while-thingie, that the_post()-method-thingie and that wp_reset_postdata()-thingie each time? It feels a bit… repetitive. And dangerous, since if I forget to reset the postdata I can screw up other loops and functions and plugins and my site (that often is a client site..) is starting to fall apart, loop by loop.

with_posts(): a fancy solution with a callback

So, I give you my solution to this problem: the with_posts()-function. Let’s do the same thing again, using my approach:

Using with_posts() I went from 6 lines to 3 lines.

Maybe it’s just 3 lines less you think, but hey it’s 3 lines less every time you want to loop something! That, plus you won’t forget that reset_postdata or setup_postdata thing again.

The magic is in the callback function: inside it you will automagically get the current post as the current post and it’s called once for each post in the matching query. You can use all the common stuff like the_title, the_permalink, edit_post_link, the_content, and so on.

Oh! And you can pass other stuff into the with_post-function too (ids, slugs, query strings…), to get any mix of posts. This example uses a regular wp_query as the base, to get some posts from a custom post type:

The function is posted in a Gist on Github for your viewing and forking pleasure, and I’ve also created a Gist with all kinds of  examples, so check it out and you’ll probably hopefully get the hang of it.

What can i say – I love this little function, and I hope you do.

Now, feedback me!

How we created an API to our coffee machine and how we abused the 418 I’m a teapot

We needed(?) a REST API to our coffee machine. So I put a Twine next to it, and made it call back over HTTP to a webhook on one of our servers. This webhook logs all the temperature changes, and now anyone can query the dataset via our REST API. It just returns if the coffee is hot or cold in beautiful JSON.

http://earthpeople.se/api/coffee

Then, just for the hell of it, I set up an API to our teapot too.

http://earthpeople.se/api/tea

(It actually only returns that it is a teapot, according to the HTCPCC. Which is probably abusing the meaning of the status code, since it’s in the 400 Bad Request-range…)

Our #musichackday hack – Stealing Feeling!

UPDATE: We actually won an iPad Mini courtesy of Echonest for the hack! Very encouraging!

Me, Fredrik and Adrian attended the Music Hackday in Stockholm, and made a little something.

In short:
1. Steal the feeling from someone who’s got more of it than you.
2. Apply it to your music.

It’s based around a 16 step javascript sequencer which a user can program using a drumkit generated in web audio. Then, apply the swing from Aretha Franklin or Squarepusher on your song.

As a bonus, the drumkit plays in the left channel, and a trig signal is sent in right channel, so you can hook up your CV/Gate synthesizers.

We call it Stealing Feeling.

Technologies used: Echonest API (for stealing the feeling), Javascript (for the sequencer), Web Audio HTML 5 API(for creating the drum sounds).

 

 

PHP Run – a package for Sublime Text 2

I switched from the my old friend TextMate a couple of days ago. And missed CMD+SHIFT+R. In TextMate, this command would run the current PHP file and output the result. Great when you just want to see if your hotfix compiles, or if you want to beautify a json feed really quickly <?php print_r(json_decode(file_get_contents($feed)));

Not rocket science in any way, just a few lines of Python. But works for me and possibly you too. Soon you’ll hopefully be able to install it via the Sublime Text 2 Package Manager, but meanwhile you can grab it from GitHub.

The very first field extension for Simple Fields comes from Earth People

The recently released version 1 of Simple Fields added a nice feature called “field extensions“: using a simple API, developers can add their own custom field types to the plugin. Nice indeed.

For one of our WordPress projects we needed to be able to attach a location to each post, so we though that “hey, let’s make that a field in simple fields!”. Said and done, the plugin is here and it’s called “Simple Fields Map extension” and so far it’s been a joy to use.

If you need to add one or several locations to a post in WordPress then give this plugin a try. It’s really really nice and useful.

WordPress Plugin Simple Fields now maintained by Earth People

Yes, the great – prepare for SEO Keyword madness! – WordPress custom fields plugin Simple Fields is now actively developed by us here at EarthPeople.

This is thanks to the fact that the plugin creator Pär since a while back spends his days at our office, typing away on his Macbook Air or browsing the WordPress Codex trying to remember if the function was called “get_title()” or “get_the_title()”. And … yes, sometimes he also updates the plugin from here.

So, be happy, do cool WordPress stuff, and read more about Simple Fields on it’s own domain simple-fields.com.

Instagram bingo

This is a game that’s perfect for a company event, like our own Helsinki kick off. You get a list with stuff that you’re supposed to capture with your smartphone camera, tag properly and upload to instagram. Some of them are bound to a place, some not. Hard task – more points. In the field you get to see the other teams’ progress, as well as your own, listed and on a map. You also get comments from the web app directly in your instagram feed, telling you if you got points or if the image is no good for some reason, wrong location for instance.

In the backend we have a database with teams, challenges and scores, and a web app connected to the instagram api. The app checks the participants’ feeds for tags included in the game, and compares the challenge geo data to the image location, considering a specified allowed offset in meters.

Our challenges would be something like “Eating a Panda liquorice ice cream in Esplanadin Puisto”. The team would then have to find out what and where Esplanadin Puisto is, try to get there, find a place that sells the particular Panda ice cream, and take the photo. Plus snap a picture of a mullet on the way.

A time frame factor could also be added to the game – “A woman walking into the Arabia Store between 12 and 12.15″

We can make this fun thing happen at your event too. While your staff get loads of fun and team building, your company gets lots of positive social media exposure. Everybody’s happy, for real.

http://perkele.earthpeople.se