Category Archives: General

Facebook be gone

Productivity can sometimes be hard. Especially when you have facebook accessible on all your devices. I have killed their app from my iPhone ages ago, but still manage to use it in the browser. And if you started looking through the feed, it never ends. But this had to stop.
First, I tried iOS built-in website blocker, but you just cannot block one site, there is an entire black list and I grew tired of it. It was the time for more elegant solution (for civilized age).

So here’s my “Almost Instant Productivity Boost”™ for you iOS device: . Yes, it’s a custom iOS content blocker, which only kills facebook. Yes, you have to have Mac and XCode to install it. No, you cannot download it from App Store. Yes, because I don’t have money to pay for the license.

Oh yeah, just use /etc/hosts file to block facebook on your Mac (link to google).

Unfortunately, I was lazy, so Login with facebook will also be gone. Which is a pity, but I don’t care. If you care – just send me a PR.


Some time ago we got a new car. It’s Mercedes-Benz B-class again, but a bit newer. However, this new car has some bugs.

First thing that i’ve notice is that rear view mirror if switched to ‘night mode’ has different angle, so every time we go from ‘day’ to ‘night’ or back we need to adjust it.

Another thing is even better. Sometime in the morning it give us a message in red: ‘Reversing not possible. Consult workshop’. And reverse gear is indeed does not work. Moreover it only uses odd gears from now on: 1-3-5-7, and revs are usually very high as well. At first we were really upset and even got it to the workshop. Needless to say, they did not fix or even detected the problem. However it persists. Right this morning we had the message again. Luckily there is a workaround. Yes, you just need to reboot it. Twice. Turn off, take out the key, start again. Repeat. And the message is gone, plus gearbox is working with all gears now. Simple fix.

Heroku, golang and martini

Just a note to myself. When deploying go + martini project to Heroku, there was an error:

remote: -----> Running: godep go install -tags heroku ./...
remote: www.go:3:8: cannot find package "" in any of:
remote: /app/tmp/cache/go1.4.2/go/src/ (from $GOROOT)
remote: /tmp/build_ea6105408e12a560374800681cccb8e2/.heroku/g/src/gggggg/Godeps/_workspace/src/ (from $GOPATH)
remote: /tmp/build_ea6105408e12a560374800681cccb8e2/.heroku/g/src/
remote: godep: go exit status 1

To fix it I had to force Godeps/_workspace folder into git repository, since Heroku buildpack expects dependencies to be delivered with app code.

Mailcatcher to test your email subsystem

You have probably heard of Mailcatcher already. It’s a great piece of software that implements neat idea.
I am using Vagrant and Apache on Debian, so my development box is build using It allows mailcatcher installation btw, but we’ll do it manually and with a step forward:

  1. Get sqlite3 development libs: sudo apt-get install libsqlite3-dev;
  2. Got ruby? Install mailcatcher: sudo gem install mailcatcher;
  3. Now, let’s make it running after box restart:
    • Create /etc/init.d/mailcatcher script with this code:
      #! /bin/sh
      # Provides:          mailcatcher
      # Required-Start:    $all
      # Required-Stop:     $network
      # Default-Start:     2 3 4 5
      # Default-Stop:      0 1 6
      # Short-Description: Start daemon at boot time
      # Description:       Enable service provided by daemon.
      ### END INIT INFO
      start() {
      	echo -n "Starting MailCatcher"
      	if start-stop-daemon --stop --quiet --pidfile $PID_FILE --signal 0
      		echo " already running."
      	start-stop-daemon \
      		--start \
      		--pidfile $PID_FILE \
      		--make-pidfile \
      		--background \
      		--exec $PROG \
      		--user $USER \
      		--group $GROUP \
      		--chuid $USER \
      		-- \
      	echo "."
      	return $?
      stop() {
      	echo -n "Stopping MailCatcher"
      	start-stop-daemon \
      		--stop \
      		--oknodo \
      		--pidfile $PID_FILE
      	echo "."
      	return $?
      restart() {
      case "$1" in
      		echo "Usage: $0 {start|stop|restart}"
      		exit 1
    • Make the script executable: sudo chmod +x /etc/init.d/mailcatcher;
    • Create the user: sudo adduser mailcatecher;
    • Add the script for upstart: update-rc.d mailcatcher enable;

Ok, so mailcatcher will run at startup, but will not be visible at host machine. Now, you can do it just by forwarding guest’s 1080 port to host’s 1080 port using Vagrant config. But it didn’t work for me for no apparent reason. And i am not a big fan of typing in port numbers into browser address bar. So next steps will solve that:

  1. Create a new Apache “site”, let’s say “/etc/apache2/sites-available/35-mailcatcher.conf“;
  2. Let’s use Apache proxy module to let us access to mailcatcher (on port 80). Add this to the newly created “site” file:
    <VirtualHost *:80>
         ServerName mailcatcher.local
         ProxyPass /
         ProxyPassReverse /
  3. On your host machine update /etc/hosts file with this line (replace %GUEST_IP% with your Vagrant box IP address):
    %GUEST_IP% mailcatcher.local
  4. Enable mailcatcher site with a2ensite command, enable proxy module with a2enmod proxy_http command and restart apache;
  5. Point your browser to http://mailcatcher.local and your should see mailcatcher interface.
  6. If you see 503 error, it’s probably because mailcatcher did not start.

    Oh, yes, refer to the manual on how to add support to your language of choice. For PHP it’s simple:

    ; php.ini
    sendmail_path = /usr/bin/env catchmail -f [email protected]

The Stanley Parable

Oh i have written code today, alright. Whole day. Cracked the nut just two minutes before six. What a joy, when you do something that actually works, despite all odds and… inconveniences (i don’t want to rattle again about how “good” open source products sometimes are, there are too much complains in this blog already, and besides, i could just go and fix it instead of mumbling, it is free after all).

So instead, i would rather tell about the game. It’s called The Stanley Parable. And it is simply brilliant. The problem i face is that this is all i can tell you about it. Go play.

Recursive C #2

All day today i’ve been thinking how to implement reverse() function from yesterday post using no helper code. Still no result though. Except the realization, that this whole helper is very slow. Let’s make a test: reverse 103 character string 106 times, shall we?

time ./test2

real	0m26.846s
user	0m26.810s
sys	0m0.016s

Wow, that’s a lot. The reason for that is obviously the fact, that we call strlen() each time _rev() is called and strlen() has linear running time, so we are just adding that running time ever _rev() invocation without any gain because string length do not change during reverse() call. Not cool. We can add another constant parameter to carry initial string length:

static void _rev(char s[], int i, const int l) {
	int k = l - 1 - i;
	if (i > k) return;

	char c = s[i];
	s[i] = s[k];
	s[k] = c;

	_rev(s, ++i, l);

And then:

void reverse(char s[]) {
	_rev(s, 0, strlen(s));

Quite simple. Here’s how it performs:

time ./test1

real	0m2.830s
user	0m2.825s
sys	0m0.002s

Fastaaaa! Mind you, that’s recursive solution which has function call overhead (tail recursion, anyone?) and is just an exercise.

So yeah. Optimize-shmoptimize.

Just started the preprocessor chapters. That should be even funnier, because of all the bugs possibilities. Really looking forward to it.

That’s it for today.

Recursive C

Continuing with C. Last chapter i’ve finished is Recursion. There is an exercise which is to implement recursive function for reversing string in place. Here’s my solution:

void reverse(char s[]) {
	static int i;
	int k = strlen(s) - 1 - i;
	if (i > k) {
		i = 0;

	char c = s[i];
	s[i] = s[k];
	s[k] = c;


Which is a bit… cheating. And that’s due to the fact, that function is not supposed to keep any kind of state. Look at static int i; which i use to keep track of which position is currently exchanging. This is not very good. Is there a better way? If i would be using Scala, i could just create nested function. In C i have to use static function, which is essentially private.

Here is goes:

void reverse(char s[]) {
	_rev(s, 0);

static void _rev(char s[], int i) {
	int k = strlen(s) - 1 - i;

	if (i > k) return;

	char c = s[i];
	s[i] = s[k];
	s[k] = c;

	_rev(s, ++i);

Funny enough changing ++i in _rev()‘s last line, to i++ will lead to Segfault because recursion never ends. Why not stack overflow? Here is why.

That concludes recursion for now. Source file here: reverse.c.

That’s it for today.