ogg not playing on Kivy when packaged with pyinstaller


I’m working to package a Kivy based project for Windows7 by using pyinstaller and while following
the Kivy manual I noticed that all went well except for the ogg sound files I’m using.
The only thing one would notice when running the “exe” is that when playing the ogg you
would only hear a “click” iso the ogg sound file.
The solution  was to include by hand the the following DLL’s from site-packages/pygame:
libogg.dll, libvorbis.dll and libvorbisfile.dll to th eroot of the “exe” tree.

dpkg –set-selections results in “warning: package not in database….”


When you want to restore your packages that you’ve backup-ed with :

sudo dpkg --get_selections > selections.txt

And when you restore them with:

dpkg --set-selections < selections.txt

And the result is a whole bunch of warnings like  “warning: package blabla not in database….”

Then theres a easy fix:

$ sudo apt-get install dselect
$ sudo dselect 
   -> Update
   -> Install


Ubuntu 12.04 atheros wifi card not found


When you have Ubuntu 12.04 installed on a system with a Atheros wifi card indicated by ‘Device 0037’ when you run lspci then you have a problem that the driver shipped in 12.04 isn’t compatible with that card.

The solution is to compile the driver yourself which is pretty easy so don’t worry 😉

First make sure you install the necessary tools:

sudo apt-get install build-essentials

Download the driver(s) package:

Unpack it, cd into the directory and do:

sudo su
./scripts/driver-select restore
./scripts/driver-select ath9k
make clean
make install

You now have a proper working Atheros wifi card.

That wasn’t to hard 🙂



Unlock Nexus 7 and become root


As any mobile device without root access is pretty useless I decided to unlock and root my new Nexus 7 with 3G as my live isn’t complete without root access on all my devices 🙂

Update for android lollipop,


Warning: you can screw your device, and the rest of the standard bla bla

But lets be honest, a device without a root shell is basically screwed in the first place so lets go ‘unscrew’ your device 🙂

As the unlocking is somewhat drastic, it will basically reset the device to the factory state, it’s best to do it as soon as possible.
Everything you put onto the device will be removed.

On the upside, Nexus devices are very easy to unlock, nothing special about it as Google considers removing root just a way to protect stupid users from themselves so there’s no need for real hacking.

We will just use regular developers tools.

Unlocking bootloader

Here we go:

First you must have the adb tool which is part of the android-sdk.

Now get your “developer options” back under ‘settings’ on your device.
With android 4.2 the dev options are hidden but they are easy uncovered:
Go to Settings -> about tablet -> Now hit ‘build number’ 7 times. For real, no joke, lets say the guys at Google still have a sense of humor 🙂
You now have “developer options” back in your settings menu.

In settings -> developer options -> enable USB debugging.

Now go into the SDK -> platform-tools.

First check to see that the device is found:

~/android-sdk-linux/platform-tools$ ./adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached 
015d4**********    device

Unlock bootloader:

~/android-sdk-linux/platform-tools$ ./adb reboot bootloader

Use the power button on the nexus to say yes.

Now we can talk to it with ‘fastboot’. (Do this only once unless you want to reverse it)

~/android-sdk-linux/platform-tools$ sudo ./fastboot oem unlock
[sudo] password for stas: ...
(bootloader) erasing userdata...
(bootloader) erasing userdata done
(bootloader) erasing cache...
(bootloader) erasing cache done
(bootloader) unlocking...
(bootloader) Bootloader is unlocked now.
OKAY [ 24.176s]finished. 
total time: 24.176s

It’s now unlocked and stays unlocked, no update will lock it again.

When you device get unresponsive or whatever, hold down the power button for some time until the device switches off.
Then restart it by holding down the volume down button and powerbutton at the same time until you are back in the bootloader

Now we must wipe the data.

Use the volume down to select “recovery mode”
Use the power to select it.

You will see a android with a red exclamation mark.

While holding down Power, press Volume Up.

Use the volume keys to scroll to “wipe data/factory reset” and press Power to select it.

Installing clockwork recovery image

Download the correct image for the Nexus 7 to the adb directory:
(the touch variant didn’t work on my device)
Download to the adb directory the ‘root’ binary, SuperSu :

Now connect device again to your computer as a ‘camera’ because my Linux system doesn’t handle the default “MTP” protocol very well.

Copy the SuperSu program to your device:
I use the adb as the Nexus doesn’t expose itself as a usb device so the mormal access to the device filesystem is limited from a computer.

~/android-sdk-linux/platform-tools$ ./adb push /mnt/sdcard/Downloads/
761 KB/s (899752 bytes in 1.154s)

Shutdown the device and restart it into recovery mode (powerdown and volume down)

Flash the recovery image:

~/android-sdk-linux/platform-tools$ sudo ./fastboot flash recovery recovery-clockwork- 
sending 'recovery' (5990 KB)...OKAY 
[  0.722s]writing 'recovery'...OKAY 
[  0.635s]finished. total time: 1.357s

Reboot it into bootloader again:

~/android-sdk-linux/platform-tools$ sudo ./fastboot reboot-bootloader

Go into recovery:


Install zip from sdcard -> choose zip from sdcard -> 0/ -> Downloads -> UPDATE-SuperSU

Check the output for errors.

Choose Go back -> reboot system

Install a terminal app, Android Terminal Emulator from Jack Palevich is a good one.

Start the terminal and type at the prompt “su”

The program SuperSu should ask you if you want to grant superuser permission, say yes.

And you have a root shell 🙂

Yeahhh a black screen with a # as prompt, now your live is complete again 🙂


What to install when your root ?

Make sure you never ever download apps from outside the googleplay store, remember you can become root now and so can some apps.

First of all rommanager from It’s the same stuff  you flashed as a recovery. From this app you can easily reflash recovery images from your device itself.

Titanium backup. It’s been a real livesaver for me a number of times. I myself have purchased the pro version it’s much quicker and it’s a must have app on any rooted device.

Python xmlrpcserver with HTTPS support and basic authentication


For a project I’m working on at I needed a Python based multithreaded xmlrpcserver with HTTPS support, HTTP basic authentication and capable of running on any port. After looking into solutions which required some sort of server for the HTTPS and basic autentication parts I decided to go for a better solution to try to add the HTTPS support and basic authentication to the Python xmlrpsserver itself. That way we would have a simple and fast solution which could run from any box on any port. Looking around on the net I found various solutions for every requirement but nothing which combined it all into one solution. So after combining various bits and pieces I came up with a Python xmlrpcserver with HTTPS and basic authentication support.

As the code used came from various free-software projects and locations I decided to share the server with the world so that it might benefit others.

For the HTTPS you need OpenSSL certificates, use your existing PEM formatted one or just create one yourself.

$ openssl genrsa -out privkey.pem 2048
$ openssl req -new -key privkey.pem -out cert.csr
$ openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095

And here’s the server

from SocketServer import ThreadingMixIn, BaseServer
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler, SimpleXMLRPCDispatcher
import socket
from OpenSSL import SSL
from base64 import b64decode

from threading import Thread, Condition
from thread import start_new_thread

import traceback
import time

# static stuff
DEFAULTKEYFILE = 'privkey.pem'  # Replace with your PEM formatted key file
DEFAULTCERTFILE = 'cacert.pem'  # Replace with your PEM formatted certificate file

class Services:
    def give_me_time(self):
        return time.asctime()

class CustomThreadingMixIn:
    """Mix-in class to handle each request in a new thread."""
    # Decides how threads will act upon termination of the main process
    daemon_threads = True

    def process_request_thread(self, request, client_address):
        """Same as in BaseServer but as a thread.
        In addition, exception handling is done here.
            self.finish_request(request, client_address)
        except (socket.error, SSL.SysCallError), why:
            print 'socket.error finishing request from "%s"; Error: %s' % (client_address, str(why))
            self.handle_error(request, client_address)

    def process_request(self, request, client_address):
        """Start a new thread to process the request."""
        t = Thread(target=self.process_request_thread, args=(request, client_address))
        if self.daemon_threads:

class MyXMLRPCServer(CustomThreadingMixIn, SimpleXMLRPCServer):
    def __init__(self, ip, port, keyFile=DEFAULTKEYFILE, certFile=DEFAULTCERTFILE, logRequests=True):
        self.logRequests = logRequests
        class VerifyingRequestHandler(SimpleXMLRPCRequestHandler):

            def setup(myself):
                myself.connection = myself.request
                myself.rfile = socket._fileobject(myself.request, "rb", myself.rbufsize)
                myself.wfile = socket._fileobject(myself.request, "wb", myself.wbufsize)

            def address_string(myself):
                "getting 'FQDN' from host seems to stall on some ip addresses, so... just (quickly!) return raw host address"
                host, port = myself.client_address
                #return socket.getfqdn(host)
                return host

            def do_POST(myself):
                """Handles the HTTPS POST request.
                It was copied out from and modified to shutdown the socket cleanly.
                    # get arguments
                    data =["content-length"]))
                    # In previous versions of SimpleXMLRPCServer, _dispatch
                    # could be overridden in this class, instead of in
                    # SimpleXMLRPCDispatcher. To maintain backwards compatibility,
                    # check to see if a subclass implements _dispatch and dispatch
                    # using that method if present.
                    response = myself.server._marshaled_dispatch(data, getattr(myself, '_dispatch', None))
                except Exception, info: # This should only happen if the module is buggy
                    print "ERROR do_POST: ", info
                    print "Traceback follows:", traceback.print_exc()

                    # internal error, report as HTTP server error
                    # got a valid XML RPC response
                    myself.send_header("Content-type", "text/xml")
                    myself.send_header("Content-length", str(len(response)))

                    # shut down the connection
                    myself.connection.shutdown() # Modified here!

            def do_GET(myself):
                """Handles the HTTP GET request.

                Interpret all HTTP GET requests as requests for server
                # Check that the path is legal
                if not myself.is_rpc_path_valid():

                response = myself.server.generate_html_documentation()
                myself.send_header("Content-type", "text/html")
                myself.send_header("Content-length", str(len(response)))

                # shut down the connection
                myself.connection.shutdown() # Modified here!

            def report_404(myself):
                # Report a 404 error
                response = 'No such page'
                myself.send_header("Content-type", "text/plain")
                myself.send_header("Content-length", str(len(response)))
                # shut down the connection
                myself.connection.shutdown() # Modified here!

            def parse_request(myself):
                if SimpleXMLRPCRequestHandler.parse_request(myself):
                    basic, foo, encoded = myself.headers.get('Authorization').partition(' ')
                    username, foo, password = b64decode(encoded).partition(':')
                    #print username, foo, password
                    if username == 'admin':
                        return True
                        myself.send_error(401, 'Authentication failed')
                        return False
        SimpleXMLRPCDispatcher.__init__(self, False, None)
        BaseServer.__init__(self, (ip, port), VerifyingRequestHandler)

        # SSL socket stuff
        ctx = SSL.Context(SSL.SSLv23_METHOD)
        self.socket = SSL.Connection(ctx, socket.socket(self.address_family, self.socket_type))

        self.funcs = {}

        # requests count and condition, to allow for keyboard quit via CTL-C
        self.requests = 0
        self.rCondition = Condition()

    def startup(self):
        #run until quit signaled from keyboard
        print 'server starting; hit CTRL-C to quit...'
        while True:
                start_new_thread(self.handle_request, ()) # we do this async, because handle_request blocks!
                while not self.requests:
                if self.requests:
                    self.requests -= 1
            except KeyboardInterrupt:
                print "quit signaled, i'm done."

    def get_request(self):
        request, client_address = self.socket.accept()
        self.requests += 1
        return (request, client_address)

    def listMethods(self):
        """return list of method names (strings)"""
        methodNames = self.funcs.keys()
        return methodNames

    def methodHelp(self, methodName):
        """method help"""
        if methodName in self.funcs:
            return self.funcs[methodName].__doc__
            raise Exception('method "%s" is not supported' % methodName)

if __name__ == '__main__':
    import sys
    if len(sys.argv) == 3:
        host = sys.argv[1]
        port = int(sys.argv[2])
        host = 'localhost'
        port = 8111

    server = MyXMLRPCServer(host, port, logRequests=True)
    # Run the server's main loop
    sa = server.socket.getsockname()
    print "Serving HTTPS on", sa[0], "port", sa[1]


For a client use someting like this

from xmlrpclib import ServerProxy

user = 'stas'
pas = 'stas'
p = ServerProxy('https://%s:%s@localhost:8111' % (user, pas))
print p.give_me_time()

There are pizzas and there are Pizzas



Nothing beats an Italian made pizza oven, well perhaps a real Italian wood fueled oven.

But this is the next best thing 🙂



Linux wifi intel Centrino Advanced-N 6235 slow


There seems to be an issue with the new Intel Centrino Advanced-N 6235 wifi chip when running in N mode. This problem occurs in all current kernels, as of this writing  <= 3.7.

The problem lies in the iwlwifi driver and disabling the N mode support seems to be an reasonable solution for the time beeing.

First check if you get an improvement:

$ sudo modprobe iwlwifi 11n_disable=1

If it performs better make it permanent:

$ sudo su#  echo options iwlwifi 11n_disable=1 | sudo tee /etc/modprobe.d/51-disable-6235-11n.conf


Raspberrry-pi as mediacenter



Raspberry over clocked to 800 with xbmc. Media center for 30 euros 🙂

Kivy on android https support. Part2


I still was unable to connect to http(s) from an android device and after some test cases with simple xmlrpc server/clients I noticed I’ve got socket errors claiming that I have no permission to use sockets.
So the real fix was to build the package with “–permission INTERNET”.
Now I have proper http(s) support 🙂

Something todo for Christmas :-)



Go to Top