Wednesday, 25 May 2016

Restoring applications after minimizing to Mac OS X dock

When you click the yellow pill button in the upper left corner of a window to minimize that window in Mac OS X or if you use ⌘ Cmd + M you might want to bring the application back. When cycling through running applications, including the minimised applications, using ⌘ Cmd + Tab you might expect to retrieve the application back.

This sequence on the other hand will bring wour application window.
1. Use ⌘ Cmd + Tab untill you find your application.
2. Before releasing ⌘ Cmd, press and hold ⌥ Alt

Other method is to hide application using ⌘ Cmd + H, then you can restore your window with ⌘ Cmd + Tab
Thursday, 12 May 2016

Using Python, MySQL and UTF-8

I have been spending way to long time figuring out how I can encode my data to utf8 when fetching records from MySQL database. All the time I was focusing on encoding the output, resulting in error like this one.
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe1 in position 1: 
ordinal not in range(128)
The solution I finally found is to set the character set when I prepare the MySQL connection
Ending up in my code like this.
!/usr/bin/env python
# -*- coding: utf-8 -*-
import MySQLdb as mdb

def getname(p):
    con = mdb.connect('hostname', 'username', ' password', 'databasname')
    sql = "SELECT cellname1 from tablename where cellname2='%s'"%(str(p))
    cur = con.cursor()
    row = cur.fetchone()
    if not row:
        return 'n/a'
        return str(row[0])
Now everything works like a charm.