Category Archives: General

mac OS tip – add shortcuts to (almost) any application

Just a note for myself. It is possible to add a global shortcut for any UI app in mac OS using System Preferences.

I am using Notes app extensively to manage my notes and TODO lists. Sometimes instead of checking the TODO item I need to mark it as unneeded, then I like to use a Strikethrough text. Notes does not have a shortcut defined for this text style and I kept jumping through the menus.

Finally figured out the way to assign a key binding. Here’s how to do it:

  1. Open System Preferences and go to Keyboard → Shortcuts;
  2. Go to App Shortcuts in the left list and click “+” below;
  3. In the Application dropdown select Notes.app (or other app you need);
  4. Type in or paste exact menu item name in Menu Title – this is just the item name, not the full path to it. In my example it’s “Strikethrough” (no quotes);
  5. Click in Keyboard Shortcut input and then press which shortcut you’d like to assign, I picket Cmd+Shift+S (⌘+⇧+S).
  6. Press Add and you are all set, the shortcut is immediately active and ready to use.

If something goes wrong, make sure the app and the menu title are correct.

Book review: SQL Performance Explained

Overall: 9/10

Good parts

In-depth explanation of database performance concepts and pitfalls for all current major relative database engines. Goes over indexes, how to use them properly and why they might not be used during query execution. This can be used as an introduction but also as a handbook for everyday work.

Missing

Wish the author would include answers for “Think about it” questions in the appendix, so readers could check themselves.

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: https://github.com/alexzabolotny/NoMoreFacebook . 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.

Car

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 "github.com/go-martini/martini" in any of:
remote: /app/tmp/cache/go1.4.2/go/src/github.com/go-martini/martini (from $GOROOT)
remote: /tmp/build_ea6105408e12a560374800681cccb8e2/.heroku/g/src/gggggg/Godeps/_workspace/src/github.com/go-martini/martini (from $GOPATH)
remote: /tmp/build_ea6105408e12a560374800681cccb8e2/.heroku/g/src/github.com/go-martini/martini
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 puphpet.com. 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
      
      ### BEGIN INIT INFO
      # 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
      
      PID_FILE=/var/run/mailcatcher.pid
      NAME=mailcatcher
      PROG=/usr/local/bin/mailcatcher
      USER=mailcatcher
      GROUP=mailcatcher
       
      start() {
      	echo -n "Starting MailCatcher"
      	if start-stop-daemon --stop --quiet --pidfile $PID_FILE --signal 0
      	then
      		echo " already running."
      		exit
      	fi
      	start-stop-daemon \
      		--start \
      		--pidfile $PID_FILE \
      		--make-pidfile \
      		--background \
      		--exec $PROG \
      		--user $USER \
      		--group $GROUP \
      		--chuid $USER \
      		-- \
      		--foreground
      	echo "."
      	return $?
      }
       
      stop() {
      	echo -n "Stopping MailCatcher"
      	start-stop-daemon \
      		--stop \
      		--oknodo \
      		--pidfile $PID_FILE
      	echo "."
      	return $?
      }
       
      restart() {
      	stop
      	start
      }
       
      case "$1" in
      	start)
      		start
      		;;
      	stop)
      		stop
      		;;
      	restart)
      		restart
      		;;
      	*)
      		echo "Usage: $0 {start|stop|restart}"
      		exit 1
      		;;
      esac
      
    • 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 / http://127.0.0.1:1080/
         ProxyPassReverse / http://127.0.0.1:1080/
    </VirtualHost>
    
  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.