20
Jun 11

New York, day 4

New York City, the Empire State Building salutes you.

This post is the fourth part of a series named “New York”, in which I talk about my trip to New York city in the first week of May 2011. These posts will be loaded with pictures, I took 1050 that week!

View all posts about New York 2011

or read all about day 3!

Continue reading →


20
Jun 11

Friendly hack of Last.fm and ifttt.com

Last.fm button, made by fotopocket.nl

Update july 25th, 2011: ifttt.com implented the Last.fm channel and triggers.

I’ve already suggested to the guys over at ifttt.com to add the Last.fm API to their channel for us to interect with (and they’re working on it!). However, untill they actually make this, here’s a quick tip (or lifehack) on how to achieve somewhat of a Last.fm channel.

One of the default If This Then That channels is RSS. On your last.fm page you can see your recent tracks but also loved tracks and similar options, these come with a RSS feed; thus you could interact with it.

Your “Favorite Tracks” URL would be something like this: http://ws.audioscrobbler.com/2.0/user/theonewithout/lovedtracks.rss
Where you would want to switch my username (theonewithout) with yours.

Now you can add an action for it. I’m obsessed with twitter, so my action is set to “Post a tweet”.

The ‘command’ looks like this:

I just added "{{EntryTitle}}" to my Last.fm favourites! {{EntryUrl}}

So in the end, our task looks like this:

From (Last.fm) RSS to Twitter

And our tweet like this:

The end result: A tweet

Hope this blogpost can you help you figure out cool stuff!

P.s. All available Last.fm feeds can be found here: http://www.last.fm/api/feeds


24
May 11

New York, day 3

Miss Liberty and Mr New York

This post is the third part of a series named “New York”, in which I talk about my trip to New York city in the first week of May 2011. These posts will be loaded with pictures, I took 1050 that week!

View all posts about New York 2011

or read all about day 2!

Continue reading →


19
May 11

Push new value into array with PHP

At work today, my colleague needed to add, or rather ‘insert’, a value into an existing array AND on a specific index. This because we fed it into a JS table sorter thing, once we pulled it through json_encode().

We couldn’t find any existing Array function at php.net, so I decided to make my own version.

At first I wanted it to work with associative arrays too, but it got complicated fast and at the time we didn’t even need it; feature creep. So for now it only works with numeric array keys.

What it does..
First it checks whether the index you supplied ($index) is available in the array ($array), if so, dissects the array in half, starting from the point you supplied ($index) (there’s no default function for this either, so I used array_slice). You now have a ‘first’ and a ‘last’ array. Then you add your value ($value) to the first array, merge both arrays back together, and you’re done!

1
2
3
4
5
6
7
8
9
function array_push_insert($array, $index, $value) {
	if (array_key_exists($index, $array)) {
		$firstArray = array_slice($array, 0, ($index + 1));
		$lastArray = array_slice($array, ($index + 1));
		array_push($firstArray, $value);
		$array = array_merge($firstArray, $lastArray);
	}
	return $array;
}

Example
We call the function and supply it with our original array, the index after which we want our new value to be inserted and the value itself. So in the next example, we want to add the letter “D” after the “B”, and this value’s key is 1. So we send in the array ($array), the key (1) and our new value (“D”).

1
2
3
4
5
6
7
$array = array(
	"A", // 0
	"B", // 1
	"C" // 2
);
 
$finalArray = array_push_insert($array, 1, "D");

So when we print_r() the $finalArray, it looks like this:

Array ( 
[0] => A 
[1] => B 
[2] => D 
[3] => C 
)