I am a Zurich based software engineer with focus on user experience and security. I'm also a music enthusiast.
To learn more about me, click here.

Use FOSRestBundle only for limited routes

There are many tutorials on how to use FOSRestBundle to provide a RESTful API with Symfony2.

However I found very little information on how to integrate an API into an existing application (E.g. everything below domain.com/api is the API, but all other routes should be ignored by the RestBundle).

Initially I used the following configuration (especially the last two lines).

    param_fetcher_listener: true
        default_format: json
        view_response_listener: 'force'
            json: true
    allowed_methods_listener: true
        json: true

            - { path: '^/api', priorities: ['json'], fallback_format: json, }
            - { path: '^/', priorities: [ '*/*' ], prefer_extension: true }

But this meant that still every request went through the RestBundle, even if it wasn’t an API page. For me this also broke svg images in dev environment.

The solution is simpe: Replace the last line with - { path: '^/', stop: true } to stop the format listener (also see the documentation).

Having a bad (sysadmin) day?

Being a sysadmin can be frustrating. Sometimes you would like to (or actually do) smash a keyboard or even your computer. And you swear. A lot.

Having one of these days again? Try this:

# alias fucking=sudo
# reboot
reboot: Operation not permitted
# fucking reboot

So now you can at least tell your computer to fucking do what you want him to.

If you are from Canada, however, try this:

# alias please=sudo

Syonix is online!

I am happy to announce that my company’s website is online: We are looking forward to your visit: www.syonix.ch
Syonix Web

Lens Aperture

A macro lens gives you an awesome view of the aperture of a lens:


Sigma Aperture on Vimeo.

Generate different shades of a color

I’m working on a web based chat application where I needed different colors for the speech bubbles. These are generated completely using CSS and consist of 5 different colors for text, gradient and border.

The problem that I faced is that they should be available in various colors and because each color required ~30 lines of code (only for the color definitions) I didn’t want to manually create each color.

Unfortunately, the RGB color model which is normally used in CSS color definitions is not very helpful. Take the gradient of this blue speech bubble: It goes from rgb(87, 196, 255) to rgb(168, 225, 255). There does not seem to be any logical relation between these two values.

This is where the HSL color model is a lot more useful. Instead of using Red, Green and Blue to describe Colors, the HSL color model uses Hue, Saturation and Lightness. The HSL Color Picker makes this clear:

The same two colors mentioned before have now the values hsl(201, 100%, 67%) and hsl(201, 100%, 83%). So while Hue and Saturation stay the same, only the lightness changes.

When I figured this out, I guessed that I’m not the first to find out and that I would probably find many great solutions to use this in PHP.

I was wrong.

Maybe I didn’t search long enough but I didn’t find any PHP script that did exactly what I wanted and was comprehensible (I didn’t want to use a code snippet that magically does what I want, without knowing, how it does.).

So I started to improve and extend what I found and ended up with a pretty nice set of PHP functions.

The Workflow looks like this:
Hex color code → RGB → HSL → Change Lightness → RGB → Hex color code

So we take an RGB hex color code, convert it to HSL, set the lightness to a desired level, convert it back to RGB and then generate a HEX color code from that.

You can download the ready-to-use PHP file with these functions (including an example how to use it) on GitHub:

Download RGB-HSL Converter

Continue reading