Mr. Casals

Probably the worst blog name ever

My First Octopress Plugin: Spotify Play Button

I’m a big fan of Spotify. I use it everyday, I pay my monthly fee to get rid of those annoying ads (I don’t know what ads do people get in other countries, but Spanish ones are really annoying… really). I was really happy when they launched their Metadata API, but today’s announcement is even better.

Embed Spotify everywhere… even Octopress!

Spotify’s new feature Play Button lets you embed a single track, an album or a playlist to any web page, giving you the possibility to put a soundtrack anywhere. So I decided to make an Octopress plugin for this. You can find its source on GitHub.

The plugin is pretty simple. You have to use the spotify liquid tag and, as param, one of the following examples.

In the next release it will let you specify the height and the width of the widget. I hope it won’t take very long :)

A single track

Example input:

1
spotify spotify:track:4vVE8YDntxjT0gld4bdd4x

Example output:

An album

Example input:

1
spotify spotify:album:2B9q4KPjOEYu885Keo9dfX

Example output:

A playlist

Example input:

1
spotify spotify:user:mrc2407:playlist:1O9JUUKiMqA8LXahz61fCH

Example output:

Some independent tracks

Example input:

1
spotify spotify:trackset:PREFEREDTITLE:5Z7ygHQo02SUrFmcgpwsKW,1x6ACsKV4UdWS2FMuPFUiT,4bi73jCM02fMpkI11Lqmfe

Example output:

An Approach to DataMapper, an Alternative to ActiveRecord

Note: I published this post for the first time at the Codegram blog, so this is just a repost :)

A few days ago we started a new project at Codegram. The project (which is still in development) is a good challenge for us and a real motivator: we all were tired of using always the same technologies, so we decided to use some tools we hadn’t had opportunity to use. One of them is DataMapper.

So what is DataMapper and why using it?

DataMapper is an Object Relational Mapper written in Ruby. The goal is to create an ORM which is fast, thread-safe and feature rich.

Datamapper is an object-relational mapper library written in Ruby and commonly used with Merb. It was developed to address perceived shortcomings in Ruby on Rails’ ActiveRecord library.

So, as the Wikipedia article says, DataMapper is an alternative to ActiveRecord. So why using it instead of the default ActiveRecord?

  • No need to write structural migrations
  • Scoped relations
  • Lazy loading on certain attribute types
  • Strategic eager loading
  • Default support for composite and natural keys

As you can see, DataMapper has some really interesting features. This post will be a little introduction to this ORM, let’s see some of them.

Back Online!

It’s been really long since the last time I wrote a post. A lot of things have happened since: I started the second semester at university, I got angry with the educational model they’re using there and I’m trying to change it. I started organizing the Barcelona Ruby Conference 2012 (BaRuCo) (which looks amazing, I must say) with the people at Codegram. I improved my VIm knowledge. I learned about design patterns and became kind of obsessed with them. I got an Android smartphone. And I found myself with the need of a place where to talk about all those things.

But sometimes it’s better to get rid of everything to start again instead of trying to keep something alive. That’s what I did with the blog: I had one, but I didn’t use it. Now I find myself with the need of a place to save my thoughts and things I do… But I couldn’t use the older blog. It was too unupdated and I screwed the repo at some point, so I just deleted it and created a new one.

I don’t need a change, I just need to start again. That’s why I’m still using Octopress. Besides, Octopress has implemented some nice features since the last time I took a look at it, such as separating plugins into their own system or linked posts, which are still in beta (but I’d love to see them merged in master). Oh, and I just love writing posts with Markdown and VIm :)

The only drawback I find using Octopress is the lack of themes. I just can’t stand another blog with this layout. Too mainstream, I’d say. So I’ll try to create my own layout for this blog, which will be a funny challenge because I’ll have to design something useful from zero to hero and take a look at Octopress templating system (about which I could not find any docs… shame on you!).

I’m also thinking about taking a look at Octopress’ plugins system, which looks quite nice and easy to work with. I’ve already got a plugin in mind related to Spotify and it will take me to create a gem to work with its API, so three things in one :)

PS: this reminds me that I have to do a cleanup to me GitHub account… So much stupid repos there.