Creating an Android Keystore on Unity

I’ve been working a lot with Unity recently. I’ve been pleasantly surprised by it’s UI. Every manipulation feels natural. Little did I know that this particular fondness of mine will come back to bite me!

Hours before releasing Gravity, my first Android game, I couldn’t for the life of me figure out how to create my Android Keystore.

-Read more-

Solving the dreaded Varnish 503 error

“Error 503 Service Unavailable” / “Guru Meditation” is probably the most common error people get with Varnish. This post will go through a few causes of (and solutions to) this Varnish 503 error.

Before we start

One of the most confusing (but nonetheless very cool) things about Varnish is that it does not store any logs on disk. All log entries go directly into memory. This allows for better performance and efficient disk usage.

So to view the logs, you’ll have to fire the following command:


Once the command is running, load up a page from your website on your browser and look for any errors. This literally means looking for the word “error”.

Pretty sweet, huh! Now let’s get on to our first solution.

Solution 1 – General check

Most of the times, Varnish 503 means Varnish cannot connect with your backend (Apache, Nginx, etc…). So you should start from there.

The first thing is to make sure your backend is correctly configured. That means making sure your Apache/Nginx/whatever is running properly before installing Varnish.

If you’ve installed Varnish on a properly running instance, then you might just check that installing Varnish hasn’t done anything funny to your Apache configurations. Here’s what you can do:

Open your Varnish configuration file. Mine was in /etc/varnish/user.vcl

backend default {
  .host = "";
  .port = "8888";
  .connect_timeout = 1s;

We can see that Varnish is trying to connect to port 8888 on the same machine. But is our backend responding correctly there?

Let’s try this (make sure you run this on your server, this port will probably be blocked to the outside world):


This will create an HTML file with the output in your current directory. Open the file and see if it matches your website’s homepage. If it does not, then you need to configure your server. This is beyond the scope of this post, I’ll advise you to check the Linode Library for resources.

Solution 2 – Increase timeouts

A frequent cause of Varnish 503 errors is timeouts between Varnish and your backend. This is quite easy to solve.

Open your Varnish configuration file (mine was in /etc/varnish/user.vcl) and add these lines:

backend default {
  .host = "";
  .port = "8888";
  .connect_timeout = 1s; # Wait a maximum of 1s for backend connection (Apache, Nginx, etc...)
  .first_byte_timeout = 5s; # Wait a maximum of 5s for the first byte to come from your backend
  .between_bytes_timeout = 2s; # Wait a maximum of 2s between each bytes sent

The settings are pretty straightforward. The most important settings here is the first_byte_timeout. So go ahead and play with those settings until you find the sweet spot for your server.

Solution 3 – Turn KeepAlive off

If you’ve increased the timeouts and you’re still getting Varnish 503 errors, then the problem might be elsewhere.

Do this test; increase your timeouts to a considerable amount, like 10 seconds. Then, start browsing your website until you get a 503 error. If the error comes up before those 10 seconds, then the error is definitely elsewhere. I’ve seen cases where the error was coming up right after the click, as if the page was cached locally.

The solution to this issue is quite simple. It occurs often on Apache servers and it’s all due to the KeepAlive directive.

Open your Apache configuration file. Mine was in /etc/apache2/apache2.conf

# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
KeepAlive Off

By turning the KeepAlive directive off, we are forcing Apache to drop idle connections. Turning KeepAlive on makes sense when your Apache instance serves files directly to the end users. Basically the end user will open one connection and receive multiple files from it.

But with Varnish and Apache on the same server, I’d advise you to turn KeepAlive Off.

Wrapping up

So there you go with my suggestions. Go ahead, try them and let me know if you have any other solutions!


LMAG – Proof of concept

Okay, so last time I set out to make my own game. And things have been going great! I managed to hack together a nice proof of concept of my upcoming game.


Sweet right? The idea of the game is to explore a castle through a series of doors, except that you have no indication of the destination of any door. As  you progress through the levels, the castles will get more complicated and new challenges will appear.

I already have a few crazy ideas in my head, and I’m going to be talking about them in future posts.

But for now, let’s concentrate on the actual coding…


A huge part of the game relies on doors, and I made sure that this part was easily manageable. Each door is a GameObject and it’s naming defines it’s behaviour.

Here is the list of doors on the level above:

  • DoorA0
  • DoorA1
  • DoorB0
  • DoorB1

So DoorA0, will teleport to DoorA1 and back to DoorA0. But here’s the trick, if I add DoorA2, the pattern transforms into DoorA0 > DoorA1 > DoorA2 > DoorA1 > DoorA0.

Doors, moar doors!

This one’s tricky; I had to find a way to detect the collision between the player and the doors. I naturally turned to Physics2D.OverlapCircle().

But! For the function to work, the door needed to be a collider. And if the door is a collider, well, then I can’t get in!

So, I came up with this trick (I love how gamedev is 1% code and 99% hacks). I created a circle collider with radius 0.1 and Y position -0.1. That way the collider is just bellow the feet of the player and I can boost the radius parameter of Physics2D.OverlapCircle() to detect the presence of the user.

Big bugs, small fixes!

From the moment I got my door mechanisms to work, I was plagued by a bug. When the player would use a door, he would teleport to and from multiple times.

Since the Up key is used to activate doors, I quickly guessed that the keyboard input was being fired through multiple frames. And I was right!

I tried solving the issue by adding a delay to the teleportation function, learned about Coroutines on the way, only to realize that the real culprit was this line:


Which I changed to:


Indeed, GetKey gets fired as long as you hold the key down. While I only needed to teleport the user once the Up key was released.


To conclude,  I have to say I’m quite impressed with Unity. They managed to put together an amazing piece of software. Of course it has some weird behaviours at times and it crashes once a while, but there’s something that lets you know that this was made by gamers for gamers!

* LMAG = Let’s Make A Game

Fix “Object #<Object> has no method ‘onCleanup’ fancybox”

If you’ve used Fancybox before, you’ll know that it’s a double edged sword. The plugin works wonders when moulded the right way, but miss one thing and everything starts going wrong. The issue here is that jQuery plugins, in general, do not give enough feedback.

So for a few weeks now, I’ve been getting the following error: Object #<Object> has no method ‘onCleanup’ fancybox. And since it was on a low priority task, I’ve been delaying its correction. I have also been delaying because the error says absolutely nothing to me. Why would Fancybox miss a function when all the code has been minified in one single file, right?

Well, that’s where I was wrong. The issue is not about Fancybox missing anything. The issue is actually in the CSS. A proper Google search sent me towards a guy who got the exact same bug because he did not include Fancybox’s CSS.

So I went back to my code and, indeed, my CSS file was corrupt! So yeah, if you get this error “Object #<Object> has no method ‘onCleanup’ fancybox”, be sure to check if your “jquery.fancybox-1.3.4.css” file is included correctly.


LMAG – Once upon a time…

Raise your hand if the last time you heard from your mother was when she sent you a request on Facebook, asking you for more Pear Candy Rescue Saga lives. Now raise your other hand if your mother had to call you sixteen times for you to come down for dinner.

That woman has changed her ways! But we don’t care, the only thing that we care about is that games are getting ridiculously popular and everyone and their mother is playing it. Hence, this post! Also, put both your hands down!

Since day one, the fascination of every programmer has been to craft their own games. Why? Three reasons for that:

  • It’s the ultimate way to get respect. Show your friends how you made a Youtube clone on Ruby on Rails in 2 days and no one bats an eye, show them your new game and everybody looses their minds!
  • It’s fascinating. Sure beats debugging CSS3 on IE7!
  • It’s the most satisfying piece of code. One variable can change the whole meaning of a game. So yeah, it feels pretty powerful!
Playing with my stick like I don't even care
Playing with my stick like I don’t even care [Source]

You’re not gonna make a game, are you ?

Why yes! That’s exactly my plan. I’ve even sorted out my tools and stuff:

  • A good game needs a good game engine. That’s where Unity comes in. What sold me to Unity was the ease at which everything is managed. The IDE is just a breeze to use, and everything feels intuitive.
  • It also needs some catchy graphics. And the very beautiful Kenney has our back covered!
  • Lastly, it needs a strong community to make these pieces of code come alive.

I hope you guys will be that community, and I’ll see you next time with a very early sneak peak.

* LMAG = Let’s Make A Game