How to stop hanging print jobs in Windows 8.1

From time to time, some print jobs may be hanging for no apparent reason. This may some times be resolved by restarting or deleting the print job in the print job list. This however is not always possible, but another fix may be handy:

Right click on the start button and select “Command prompt (Admin) “.

In the command promt, restart the print spooler, by writing

net stop spooler

and then:

 net stop spooler



Read the ADXL345 accelerometer with Raspberry Pi, using SPI bus

I recently had to read the Analog Devices ADXL345 accelerometer, using SPI. So I used the Raspberry Pi. I only needed to verify the functionality in Python, so the code do have some rough edges, when it comes to the calculation of the gravity, but the code that reads the device is correct.

Note: You need to have the python-dev package installed, along with the SpiDev. You can get the former, using apt-get, but you have to install SpiDev manually.

Another note, and this is important; You shouldn’t set the spi.mode = 3 field before calling the open() function. I have no idea what so ever why, but the SPI on the Raspberry Pi, will absolutely not work for me, if I do that.

The code is provided, here below:

# -*- coding: utf-8 -*-
# Example on how to read the ADXL345 accelerometer.
# Kim H. Rasmussen, 2014
import time
import spidev

# Setup SPI
spi = spidev.SpiDev()
#spi.mode = 3    <-- Important: Do not do this! Or SPI won't work as intended, or even at all.,0)
spi.mode = 3

# Read the Device ID (should be xE5)
id = spi.xfer2([128,0])
print 'Device ID (Should be 0xE5):\n'+str(hex(id[1])) + '\n'

# Read the offsets
xoffset = spi.xfer2([30 | 128,0])
yoffset = spi.xfer2([31 | 128,0])
zoffset = spi.xfer2([32 | 128,0])
print 'Offsets: '
print xoffset[1]
print yoffset[1]
print str(zoffset[1]) + "\n\nRead the ADXL345 every half second:"

# Initialize the ADXL345
def initadxl345():
    # Enter power saving state
    spi.xfer2([45, 0])

    # Set data rate to 100 Hz
    spi.xfer2([44, 10])

    # Enable full range (10 bits resolution) and +/- 16g 4 LSB
    spi.xfer2([49, 16])

    # Enable measurement
    spi.xfer2([45, 8])

# Read the ADXL x-y-z axia
def readadxl345():
    rx = spi.xfer2([242,0,0,0,0,0,0])

    out = [rx[1] | (rx[2] << 8),rx[3] | (rx[4] << 8),rx[5] | (rx[6] << 8)]
    # Format x-axis
    if (out[0] & (1<<16 - 1 )):
        out[0] = out[0] - (1<<16)
    out[0] = out[0] * 0.004 * 9.82
    # Format y-axis
    if (out[1] & (1<<16 - 1 )):
        out[1] = out[1] - (1<<16)
    out[1] = out[1] * 0.004 * 9.82
    # Format z-axis
    if (out[2] & (1<<16 - 1 )):
        out[2] = out[2] - (1<<16)
    out[2] = out[2] * 0.004 * 9.82

    return out

# Initialize the ADXL345 accelerometer

# Read the ADXL345 every half second
timeout = 0.5
    axia = readadxl345()
    # Print the reading
    print axia[0]
    print axia[1]
    print str(axia[2]) + '\n'

    elapsed = time.clock()
    current = 0
    while(current < timeout):
        current = time.clock() - elapsed

Get Gnome back in Ubuntu 14.04 LTS

You often either love or hate the Unity desktop environment.

Fortunately, it is possible to bring back the “good old” Gnome look and feel in Ubuntu.

Simply open a terminal and install the Gnome Session Flashback, by typing:
“sudo apt-get install gnome-session-flashback”.

After the installation has ended, log out and choose “Gnome (Compiz)” for a Window manager.

Enable Windows Switching in Ubuntu 14.04 LTS within Gnome-Fallback-Session

Strangely,  Ubuntu 14.04 LTS (and previous versions, down to 10.04), loses it’s alt-tab feature for switching between windows. A feature which you definetely want back, as you use it constantly.

Fortunately it’s very easy to get the feature back:
Launch a terminal and install the CompizConfig Settings Manager, by typing:
“sudo apt-get install compizconfig-settings-manager && sudo apt-get install compiz-plugins”

Start the CompizConfig Settings Manager, by typing: “ccsm”.

In the left pane, navigate to “Window Management”. Remove the checkbox (if checked) for the Application Switcher, and check the box for “Static Application Switcher”.

You should now be able to <alt+tab> your way through your windows again.

Finding robust features in deformable objects.

Tricky business coming up.

For now, I’m diving into SIFT and SURF, which aren’t exactly designed to find features in deformable objects, but it’s a place to begin, if you want to learn about finding features.

SIFT (Left) | SURF (Right)


Are exactly the same here. This is also to be expected, since SURF is a derivative of SIFT.

Python Socket

Details to come.
Here’s a short description in the meanwhile:

This is a class I wrote for a host, which should handle some requests, given by clients.
The part to notice here is the way select() is used. I found that socket.recv() was a blocking call and since any method of trying to make it non-blocking failed with some error, I had to use select(). Select reads from selectable inputs (ie. socket or user inputs), and returns a list of sockets with data read. You may then use socket.recv() on these sockets, because there is data avaiable and this won’t block the program while waiting for data.

class ClientHandler():
    # Initializes a client handler
    # Takes the host socket as argument
    def __init__(self, socket):
        self.hostsoc = socket
        self.sockets = [self.hostsoc]       
        self.clients = []                 

    # Automatically removes dead clients
    def serveclients(self):

        # Select available sockets
        rready, wready, err =, [], [], 0)
        for s in rready:

            # If there was a new connection
            if s == self.hostsoc:                                                                                                                                                                                                           
                # Accept the new socket
                c, addr = s.accept()
                # Create new clients of the new socket
                client = Client(c, addr) 

                # Append the new socket to the client handlers list of sockets                

            # If data was available on existing clients                                                                                                                      
                data = s.recv(1024)

                if data:
                    # Get the sender (client)
                    for c in self.clients:
                        if s == c.socket():
                            sender = c

                    # Append the data to the clients queue

                    # Handle any complete requests there may be

                    # Add data to client data queue
                    #print "Received %s" % ( data )

                    # Mark the corresponding client as inactive ...
                    for c in self.clients:
                        if s == c.socket():

                    # ... and remove the socket descriptor from the list of avilable sockets                                                                      

                    # Close the socket
        # Return            
        return True


Timing in Python: Regarding time.clock()

I recently had to use a timer in a Python-program, and happened to run into a problem with the time.clock() function, which is supposed to be the most accurate [more accurate than time.time()]. The problem was, I found not the accuracy, but rather that clock() seemed to function poorly, when some blocing code, ie. socket.recv() and socket.send() was involved.

The problem:

import time
 tstart = time.clock()
 elapsed = time.clock() - tstart

The solution:

from datetime import datetimetstart =
 elapsed = - start

Worked just perfectly.

– This and that in computer -and electronics engineering