Get MySQL full database size

If you have searched on the internets how to get the full MySQL database size, you have probably read something like this:


For certain DB, I was getting:

ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '((`information_schema`.`TABLES`.`DATA_LENGTH` + `information_schema`.`TABLES`.`INDEX_LENGTH`) - `information_schema`.`TABLES`.`DATA_FREE`)'

So, here is your fix:


Fun with Android intents and Spotify

I was taking a look on how to make my life easier with Llama. I wanted to start Spotify when my phone connected to the Bluetooth adapter in my car, so instead of using the default “Launch Application” feature from Llama, I started looking around on how to improve it. I always start my starred playlist. So, I could directly show it by adding an Android Intent with the following parameters:


Or the equivalent, with ADB:

adb shell am start -a android.intent.action.VIEW spotify:user:ereslibre:starred

Taking a deeper look I could start to directly play something (note that not my starred playlist) using the feature:

adb shell am start -n "" -a -e query "artist:heroes del silencio"

I also managed to fake play/stop key presses, this one is trivial:

adb shell input keyevent 126
adb shell input keyevent 86

I’d be glad to hear from you if you manage to directly play your starred playlist, so I could even save a tap on my phone after getting into the car.

Dynamic slugs on Rails 3

UPDATE: I gemified this code, and you can now find the ‘inferred_slug’ gem (rubygems, github).


Slugs have typically been stored in databases. At least that is what I read about slugs. It turns out that I am starting an amazing Rails project, which is pretty complex, and I want to keep it simple, stupid. So, I am setting up some facts:

  • slugs are used for mainly two reasons:
    • secure accesses, repelling information fetching scripts that just increment an id.
    • prettify URI’s.
  • slugs are actually duplicated information:
    • duplicated information is never good. Even if you have amazing callbacks, like those that ActiveRecord provides.
      • you need to take care of keeping them updated. Forget a callback, and your slugs will be outdated. Inconsistent.
      • update the ‘no-brainer-logic’ that creates your slugs, and you need to ‘migrate’ your whole database, full of information. If you want to be consistent, of course. And I really expect you to be.

From my point of view, and when thought about this issue yesterday, it was a no-brainer that slugs need to be logic, not data. So, here is my take on the problem.

Please, note that for correctly running this example you need the stringex gem, that adds some neat features to Ruby strings (among other nice candy).

Prettify URI’s

First of all, and the easiest part. Let’s prettify all URI’s. Let’s make it global for keeping the point (obviously you could decide on which models you want this).

module Slug

  def slug
    if not respond_to? :name or name.empty?

  def to_param


Ok, this is a no brainer. If there is a name attribute on your model, it will be used to prettify your URI’s. It’s important to note that the returned string contains the id at the beginning, followed by a dash, and whatever you want after that, in this case, the name. This will be explained later.

This way you can also reimplement slug method on your model, if your model instead of name contains a title column, that you want to show on the slug.

Now, let’s write an initializer that loads this directly on all your ActiveRecord::Base instances:

class ActiveRecord::Base
  include Slug

That’s it ! Now, you might be wondering why it works at all. You did not change any code on your controllers that call, for example, Model.find, and they are still able to find the record, when the passed parameter is 14-john-murray. Well, test on an irb session what returns ’14-john-murray’.to_i before continuing.

Yes, it returns 14. This is the reason why our slugs are of the form id-whatever-you-want-here. “#{id}-whatever-you-want-here”.to_i , where id  is an integer, will return that integer. We can still use a regular ActiveRecord find method !

We can still follow the links on our website; but ! Not everything is so cool. /users/14-john-murray, for instance. Try to point directly to /users/14-john-doe. It loads. It just fetches the id (14) and there are no checks about the rest of the slug. So it’s time to fix that. We made URI’s pretty, but we aren’t checking that 14-john-murray is our record with ID 14 , whose name should be John Murray.

 Protect yourself !

The first brain inner war that comes here is where to place this logic, and how. Let’s state some requirements that were basic:

  • This point should not exist, really. This should be crystal clear, but just in case. Obey MVC. No hacks.
  • We need to keep find method virgin. We’d like to still use it.
  • We don’t like to copy and paste code. We really do love kitties.

The controller looks like a nice place at a first sight. However you depend on your developer to remember that he/she needs to validate the slug somehow. Doesn’t look so nice now. The model cannot know anything about the controller. However, the model is given the whole id by the controller. There we go.

Let’s modify our simple slug initializer then:

class ActiveRecord::Base
  include Slug

module YourApplication
  module SlugFinders
    def find_by_slug(*args)
      record = find(*args)
      if record and record.respond_to? :slug
        return nil unless record.slug == args.first

    def find_by_slug!(*args)
      find_by_slug(*args) or raise ActiveRecord::RecordNotFound

class ActiveRecord::Base
  extend YourApplication::SlugFinders

Okay, great. We added two methods that we can use to search. find_by_slug, and find_by_slug!, following the usual Rails convention.

The idea is really easy. Let’s focus on find_by_slug, since find_by_slug! contains the exact same logic from the point of view that we are interested in. First, let’s do a regular find call, that will return (or not) the record. Let’s suppose we got a record. If that record responds to the :slug message, we just check that its slug is the same as the one that the model was asked for.

Wrapping up

So, we can do now things like:

  • Client.find_by_slug ‘1’ => nil
  • Client.find_by_slug ‘1-john-doe’ => Client(…)
  • Client.find_by_slug ‘1-alice-smith’ => nil
  • Client.first.payments.find_by_slug ‘1’ => nil
  • Client.first.payments.find_by_slug ‘1-niceproduct’ => Payment(…)
  • Client.first.payments.find_by_slug ‘1-fakeproduct’ => nil

We got lots of things for free (yeah, as in free beer):

  • Avoid data replication. It sounds so wrong, and feels even worse…
  • Avoid database headaches.
  • Save space in our database. Sounds stupid, right ?
  • Our logic controls the whole slug system. Change your slug logic, and magically all of them change.
  • Little impact in our project source code.

I hope this post was useful to you. Please take into account that is just an example. If someone asks for it, I can create an empty rails project showing how it works.

Happy coding !

realtime-validations rails gem

There is a new gem in the Rails world: realtime-validations.

It provides automatic realtime validations on your forms based on the validations set on the model.

The idea is to ask on every ‘blur’ event on every field of the form to the server whether this field is correct or not, creating a new model or finding the row if it contains an id.

This way you don’t need to replicate logic in your client that is already defined and implemented in your model at the server.

You can read more about realtime-validations here. You can also find the project on github.

So you want to code for CyanogenMod ?

We are living weird days. got compromised, and with it, all git repositories went down. It’s down for good, down for maintenance, reinstall and to be audited. But, for some cleaning reasons in the day that everything was put offline I cleaned up my android project folder. “Ok ! No worries ! CyanogenMod should have all repos mirrored !”. Well… yes… no.

So instead of bitching around, just put hands to work, and do some modifications on the ‘repo’ helper script in order to fetch sources from wherever it can. It’s only a temporary fix until the situation gets normalized.

Now, let’s say we are building CM from scratch for Ace (HTC Desire HD). The instructions are very similar to what you can find on the official wiki.

The Install the Repository section needs a bit of tweaking:

curl > ~/bin/repo
chmod a+x repo
repo init -u git:// -b gingerbread

So now you only need to proceed normally and start hacking.

Right to Left Systemsettings

It has been a while since my last blog post, but I hope to blog more regularly from now on. I have been looking at my todo list at KDE, and I have some necessary things to do, and others that are just ideas and need to be developed.

For now, I have been hacking today on the Right to Left support on the categorized view. It was on my todo since the big refactor that I made long time ago. It is indeed very well structured in the inside, but was missing this important piece for Right to Left users.

So, I have fixed this bug on master and backported it to the 4.6 branch. I have also adapted in this case the category drawer of Systemsettings, which was kind of special because of the neat gradients. So, here is the mandatory screenshot:

Left to Right:

Right to Left:

Next stop: keyboard navigation.

Bluedevil v1.0 is out !

We, at UFO Coders are really glad to release version 1.0 of Bluedevil, the new KDE bluetooth stack. It has been kind of long way, but finally is all ours !

We have focused on stability for this v1.0 release. Some highlights:

  • Albert gave a hand in order to fix about data information on all helpers, thus, making the application more i18n-ish.
  • Pino fixed some i18n() calls.
  • Now when a device is paired using the wizard, it is automatically set to trusted.
  • We are happily running on the brand new instance now.

So from now on, our main target will be to improve user experience (and keep stabilizing on errors that may pop out) where we believe it can be done, so if you have great ideas, don’t hesitate to report your feature requests !; right now we have a set of improvements for the post v1.0 upcoming release:

  • The monolithic application has a slightly different face, that we consider is more usable. Usability experts needed !

I also have some plans for libbluedevil for the near future:

  • Fix includes, they are unnecessarily repetitive. For this I have to release a major version, since we are following the Qt/KDE way.
  • Add services, so we can really remove some repeated code in BlueDevil itself.

Now, I have taken some photographs in order to show some features:

Monolithic Application

The monolithic application allows you to access the known devices, and connect to the services they provide. For post v1.0 versions we have redesigned this menu in order to be easier to access and less cluttered.

Devices KCM

Our KCM’s have been thought to be really easy to use, concise and functional. Three KCM exist: Devices, Adapters and File transfer.

  • The Devices KCM allows you to perform operations on already known devices. This includes: trust, untrust, rename (you can give an alias for a certain device) or disconnect. It also allows you to add new devices that are still unknown to your system. On the future, we will add also the ability to connect or disconnect from certain services of devices. Also, some other extended information like the hardware address and such.

Adapters KCM

  • The Adapters KCM allows you to perform all possible operations over your adapters. Usually, you will have only one adapter, but you may have more. This KCM allows you to rename your adapter (that is how others bluetooth devices know and find you), (un)power it, or perform changes on the visibility of the device.

Transfer KCM

  • The file transfer KCM allows you to completely enable or disable incoming transfer operations, and provide a default folder where this incoming transfers will be saved.

Another important bit is the KIO, that directly allows you to discover devices that are next to you, and browse their contents. I have taken some snapshots:

Bluetooth KIO (listing devices)

Bluetooth KIO (listing services)

Bluetooth KIO (listing contents)

Since this is our first official release, we’d like to thank all those who packaged our v1.0-rc4, giving us valuable feedback from the users (in no special order): Kubuntu, OpenSuSE, Arch Linux AUR, Chakra, and probably some others that I am missing.

Obviously, we also want to thank all users that reported us all kind of valuable info like error reports or feature requests. We will fix them all (in case of bugs) and take them seriously into consideration (in case of feature requests).



Spokify – v0.9

After some quite time pretty busy at work I had the time to hack with some relax. Yesterday I wanted to give one of the final touches to Spokify before it gets to a v1.0 release. To sum up:

  • Now when the track ends it changes to the next track. Not before. This is a historical problem with the libspotify library which doesn’t provide the exact length of the track.
  • Some spotted bugs fixed, specially regarding clicking on the cover to highlight the current track and filtering combo.
  • Previous and Next on the system tray icon.
  • Removed slider handle.
  • Slider now can be clicked to seek on the current track.
  • Creating playlists implemented.
  • Renaming playlists implemented.
  • Deleting playlists implemented.
  • Repeat finally implemented. It was always an enabled thing, now you can choose.
  • Add songs to playlists by drag & drop.

Still to do for release v1.0:

  • Allow to star tracks and list them.
  • Show playlists owners on the playlists view (trivial one).
  • Implement shuffle. Probably trivial, but want to do it right from the start. Still to decide if previous and next should take unordered list into account.
  • Implement cool track switching. Some kind of new widget. Note we never had next and previous buttons on the GUI, this is because of this plan.
  • Allow to set playlists as collaborative (trivial one).

As usual, I have recorded a video in order to show old and new features:

So, if you are using Spokify and have feedback, please let me know. Arch Linux users have a package ready to be installed: `yaourt -S spokify-git’.

An amazing weekend…

I really needed this.

  • Social

On thursday, Sebas and me went to Medialab Prado to answer some questions Agustín asked us about how the KDE community works and how we develop, design and handle such a great software. The colloquium was streamed so we reached much more people than those that came in person. I personally don’t like the answers I gave in general, and that could be in part because I was quite nervous, don’t know why. Actually I did pretty bad, but there was Sebas to fix the mess I was creating in almost every answer.

Working with the solid team has been a really great experience: Sebas, Kevin, Lamarque, Dario, Will and Alex. Also joined the party Agustín, Albert and Javier. Thanks to this sprint I met Dario, Lamarque and Javier, and I had the opportunity to see again the rest of the people.

Also I just can say Will’s daughter Anna is sooo cute and so tiny 🙂

  • Technical

I basically took the UDev backend coding responsability, being helped by Kevin almost all the time. I took my time to find out how the solid internals work, since it has been my first time with this API, and so far it looks really good to me. I wasn’t really productive this weekend for some reason I just don’t know, but I have all that voices inside that I need to code crazily like I did some quite time ago 🙂

  • Political

The day the sprint began, Sebas and I had an agenda programmed by Agustín which opens new opportunities for the KDE community. I want to thank Agustín for the hard work he does in order to keep our presence everywhere. We basically first met with Fernando Herrero, who is the technological cooperation service boss at the Madrid council, and he told us that we can have the Madrid on Rails place for whenever we want* (obviously it depends if it was already taken or not :P) for doing knowledge sharing events and whatever we feel like, which is great. He also offered us a slot on the SIMO Network so we can show what we can offer to SMEs.

We later went to met with Miguel Jaque, who is the director of cenatic and he was very impressed when he was told our numbers in bug fixing, for example.

I just love how everything went. This community is just amazing… thanks, to everyone. Really.

libbluedevil 1.8 released

Hi all,

libbluedevil v1.8 has been tagged and released. You can find a tarball here.

This version includes couple bug fixes and some tweaking. The plan for v1.9 is basically to fix all known D-Bus problems and make it rock solid. Support for this major version 1.x is planned to be continued for a long time.

However, and when nobody sees me in my dark cave I am planning some refactor on it. First, starting by the headers name. They aren’t as good as they could be. Second, I think including services to the library would be such a great thing that it’d rock. So I expect those to happen for v2.0. No dates (sorry), but I can tell you: don’t expect it for 2011. Hopefully for that time it’ll be alive and rocking !

So, if you plan to use Bluetooth services I’d suggest you to have a look at libbluedevil, since it has a really straight-forward and simple API. That way, you will also help me when reporting new issues and we can have a better library, from which we all benefit.

Sad thing… I was pretty used to post always a picture of what I was working on, but this one is pretty hard…