Sound volume issues when using kivy on Debian with gnome and pulse audio fixed

When using kivy on a Debian system running pulse audio (gnome) you would encounter issues with the sound volume due to the fact that kivy would set the volume to 100% each time it uses the soundcard.
The problem is in pulse audio, what’s new πŸ™ as it’s the from the same author who brings us systemd.
You can remove pulse audio as much of gnome depends on it.
You can however disable pulse and use good old alsa.

Disable pulse in /etc/pulse/client.conf uncomment the line “”autospawn = yes”” and set it to “”autospawn = no””
Install gnome alsa mixer, sudo apt-get install gnome-alsamixer
Restart alsa, sudo alsa force-reload
Or use alsamixer (console) to control the volumes.

Tried to use key shortcuts in gnome but that doesn’t work correctly.
Just use trusted xbindkeysrc always works πŸ™‚

install xbindkeys, sudo apt-get install xbindkeys
Use this .xbindkeysrc file and your done (after logout and login)

#Alsa Volume Down
""amixer set Master 3- unmute""

#Alsa Volume Up
 ""amixer set Master 3%+ unmute""

#Alsa mute/unmute toggel
 ""amixer sset Master toggle""

Flash TWRP on Samsung Tab2 10.1 using linux

Flashing TWRP on Samsung Tab2 10.1 using linux can brick your device
and I’m not responsible for any issues you might face.

As Samsung doesn’t have a “”fastboot”” mode but only “”download”” mode
you need Heimdall/Odin to flash TWRP onto the device.
As many members of my family have samsung tab2 tablet which are not getting
any updates from Samsung anymore they are getting slower and slower with
any app that’s updated.
As the tablets are in pefect working order and the problem is software related
it’s much better and cheaper to just replace the samsung OS with LineageOS to
gave them a second live πŸ™‚

Put device into download mode (odin mode)
Power button and volume up (is the right side of the button)
Then push volume down (left side) and make sure the device says “”Downloading…””

Now connect device by USB to your linux machine.

On your Linux machine:
sudo apt-get install heimdall
sudo heimdall detect
sudo heimdall print-pit --no-reboot

(Device might reboot without –no-reboot)
Go into download mode again

In the output of the ‘print-pit’ look for
“”Partition Name: RECOVERY””

Use that as your partition name, sometimes it could be in small caps, then
use small caps.

sudo heimdall flash --RECOVERY twrp-3.1.0-0-p5110.img --no-reboot

Disconnect USB cable

Now reboot into recovery by using keep pressed the buttons power + volume down (left side)
your device will reboot after 10 seconds and as soon as you see the samsung name on the screen
release the power button.

You are now in TWRP recovery and “”swipe to allow modifications”” to sideload a custom rom like LineageOS.

it list commit messages to create a changelog file

When you want to construct a changelog file from git commit messages you can use git log.
The way to construct such a list of commit messages is to use the git log command like this:
git log --since ""DEC 1 2016"" --until ""FEB 3 2017"" --pretty=format:""%s"" > git.log.txt

This will only display the text of the commit message.
Other useful format options are :
git log --since ""DEC 1 2016"" --until ""FEB 2 2017"" --pretty=format:""%an %ad >> %s""
To get the author name and date.

More info can be found here:

Manually resize a SD card for your Raspberry Pi (version2)

Warning, use these instructions on your own risk.


When I tried to resize the 16GB SD card in the raspberry pi version 2 I got a corrupted file system and all other kinds
of nastiness.

So I decided to try to resize the thing manually.

First “”dd”” the image to the SD card.

Leave the card in the reader/writer and issue the following comands, replace the device for you own device
and use the units for your card.


$ sudo parted /dev/sdd
 GNU Parted 2.3
 Using /dev/sdd
 Welcome to GNU Parted! Type 'help' to view a list of commands.

 (parted) print
 Model: Generic- SD/MMC (scsi)
 Disk /dev/sdd: 16,1GB
 Sector size (logical/physical): 512B/512B
 Partition Table: msdos
Number Start End Size Type File system Flags
 1 4194kB 62,9MB 58,7MB primary fat16 lba
 2 62,9MB 3277MB 3214MB primary ext4

(parted) unit chs
 (parted) print
 Model: Generic- SD/MMC (scsi)
 Disk /dev/sdd: 1955,244,16
 Sector size (logical/physical): 512B/512B
 BIOS cylinder,head,sector geometry: 1955,255,63. Each cylinder is 8225kB.
 Partition Table: msdos
Number Start End Type File system Flags
 1 0,130,2 7,165,29 primary fat16 lba
 2 7,165,30 398,97,18 primary ext4

(parted) rm 2
 (parted) mkpart primary 7,165,30 1955,244,16
 (parted) quit

 Information: You may need to update /etc/fstab.

$ sudo e2fsck -f /dev/sdd2
 e2fsck 1.42.9 (4-Feb-2014)
 Pass 1: Checking inodes, blocks, and sizes
 Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
 /dev/sdd2: 86233/196224 files (0.1% non-contiguous), 630146/784640 blocks

 $ sudo resize2fs /dev/sdd2
 resize2fs 1.42.9 (4-Feb-2014)
 Resizing the filesystem on /dev/sdd2 to 3912448 (4k) blocks.
 The filesystem on /dev/sdd2 is now 3912448 blocks long.

$ sudo parted /dev/sdd
 GNU Parted 2.3
 Using /dev/sdd
 Welcome to GNU Parted! Type 'help' to view a list of commands.
 (parted) print
 Model: Generic- SD/MMC (scsi)
 Disk /dev/sdd: 16,1GB
 Sector size (logical/physical): 512B/512B
 Partition Table: msdos
Number Start End Size Type File system Flags
 1 4194kB 62,9MB 58,7MB primary fat16 lba
 2 62,9MB 16,1GB 16,0GB primary ext4
(parted) quit


And of course, don’t choose ‘resize’ when the rspi first boots πŸ™‚

Rotate video 90 degrees clockwise

I’ve have a video shot with a phone and for some reason the maker thought it would be a good idea to keep the phone upright while filming.
So now I’m forced to view the video with my head turned 90 degrees.
It’s uncomfortable so lets turn this video 90 degrees clockwise.

avconv -i inputvideo.mp4 -c:a copy -q 1 -r 23.967 -vf ""transpose=1"" outputvideo.mp4

Syntax highlighting for Kivy kv language in pycharm

Add syntax highlighting to your pycharm
You can get the file and instructions here: KV4Jetbrains

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

(original posted: 2013)

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



Unlock Nexus 7 and become root

(original posted: 2013)

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 πŸ™‚

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 πŸ™‚

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.
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()

Install Ubuntu Linux on a samsung series 5 ultrabook with SSD

(original posted: 2012)

To install Ubuntu Linux on your samsung series 5 ultrabook with SSD you should change some stuff in your BIOS as well as change some things in your Ubuntu Linux install.
I used Ubuntu 12.10 as that’s the most current version at this moment.

You must first disable ‘secure boot’ as it’s a Microsoft thing we don’t need it and would make things a lot more complicated.
Start the laptop and keep pressing the F2 button.
Your now in the BIOS setup.

‘Advanced’ -> ‘Fast Biosmode’ > Disabled
‘Security’ -> ‘Secure boot configuration’ > Customized signatures
‘Boot’ -> Move USB HDD to the top
-> ‘Secure Boot’ > Disabled
-> ‘OS mode selection’ > CSM OS
‘Exit’ > Save and exit

That’s it, no more secure boot crap.

Connect your usb-stick.
Boot the laptop.

When installing Ubuntu remove all the partitions on sda (HDD) and sdb (SSD).
Make one new partition on sdb (SSD) with mount point ‘/’ (root)
Make on sda (HD) the following (extended) partitons:
(Size is a personal issue but you get the idea)
sda5 swap 6GB
sda6 /var 20GB
sda7 /home remaining space

Install Ubuntu.

When the install is finished no want to set some mount options in to keep the write actions to the SSD to a minimum.
Open you /etc/fstab file and make sure you have the following mount options for your SSD:
So your fstab line for SSD would look something like this:
(This is actually one line in fstab)
UUID=c1526b35-193f-4573-9817-b0fa06100b93 / ext4 noatime,nodiratime,discard,errors=remount-ro 0 1
(Of course your UUID would be different.)

You should also move the /tmp directory to a ramdisk so that the directory would no longer be on SSD but lives in RAM.
Again it’s something you do in fstab:
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0

You could also set a different scheduler for the SSD to get the most out of it.
Edit /etc/rc.local and add the following line ABOVE the line ‘exit 0’.
echo deadline >/sys/block/sda/queue/scheduler

Your done, reboot and enjoy your 3 seconds boot time :-)”

Go to Top