Disable margin collapse in CSS with no visual impact

The problem

When working with CSS you sometimes have to work around a behaviour known as margin collapsing. Basically, the top/bottom margin of two neighboring block elements will be set to the biggest margin value in-between the two elements, if their top/bottom margins are adjacent and no text, clearance, padding nor border separate them.

»
Author's profile picture Nicu Surdu

How to set a variable in Django template

As you may have figured by now, Django does not implement such a feature. That is, because the logic of setting the variable must go in the view, not in the template. But there are some rare cases when you actually need this.

»
Author's profile picture Nicu Surdu

Capture the output of a Django command

The documentation is very slim when it talks about how to call a Django command from code. In order to do this, just use call_command. To solve the trick of capturing the output of this I had to dig a little into the Django source.

»
Author's profile picture Nicu Surdu

How does Shazam work ?

What is Shazam, you may ask ? Let’s say you’re in a bar, and they play a song that you like and you don’t know its name ? Shazam can help you find out what is the name of that song.

»
Author's profile picture Nicu Surdu

Make LineString resolution depend on zoom level in OpenLayers

So, you want to render a route on your OpenLayers map. Everything will be nice and sweet until you’ll have to render a huge route, in which case no matter what computer your clients have, most probably it will stall. To solve this you have two possibilities: you either reduce the number of lines you send from the server or you reduce the number of points rendered directly on the client’s browser.

»
Author's profile picture Nicu Surdu