Friday 28 June 2013

QR Code

Just because I could...

Couple of simple commandline utilities for this, qrencode and qrcode

Thursday 27 June 2013

Python Command history

I was using the python command interpreter interactively to test out some snippets of python and rather than either typing it out again, copy/paste and removing the prompt markers at the beginning of the line or loosing it entirely, I wondered if there was a way to save the command history like in bash.

Turns out there is an easy way to do this and it is referenced in the python documentation (http://docs.python.org/3/tutorial/interactive.html)

Place the startup script below in a file in your home directory such as .pystartup
and export the environment variable PYTHONSTARTUP pointing to this file

import atexit
import os
import readline
import rlcompleter

historyPath = os.path.expanduser("~/.pyhistory")

def save_history(historyPath=historyPath):
    import readline
    readline.write_history_file(historyPath)

if os.path.exists(historyPath):
    readline.read_history_file(historyPath)

atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, historyPath
 
 

Wednesday 26 June 2013

Custom Perl code

It has been a little while since I looked at any custom Perl code, so just a quick reminder on how to get custom Perl modules to work when they are outside of the distributions standard paths.

Perl modules are loaded from the included library path "@INC", to check what paths this points to use

perl -le 'print foreach @INC'

This set of library paths can then be extended by using the environment variable PERL5LIB e.g.

PERL5LIB='<custom library path>'; export PERL5LIB

While looking at some code I noticed that in insert mode in vim my cursor keys were producing unwanted input, to solve this add the following to your .vimrc file

set nocompatible

Monday 24 June 2013

Early Birthday Present

For the last few days I have been playing with my early birthday present (thanks to my wife), a Raspberry Pi.
Bought the kit from Maplin so I did not have to buy extra pieces (with the exception of an HDMI to DVI adapter) and could just plug it in and power it up.
The aim is to use it to do some programming with it.

I know it is billed as a credit card sized computer, however I had the impression (not sure why as I have seen them before) it was a little bigger. It is tiny, see comparison photo.

RaspberryPi
Raspberry Pi next to ruler

















I have been messing round with using the pygame library that is built on top of SDL. Thinking of re-working some examples given to some of my university students using this library, should be fairly easy to convert from java.

Seemed to be a problem the other day with uploading photos to the blog so delay in posting this entry.

Sunday 23 June 2013

Gnome3 login screen background

Using the default background for the login screen has never really bothered me, however I thought it would be useful to know how to customise it.

Changing the desktop background is easy in the graphical environment using gnome-control-center.

However the background for the login screen is set for the user that runs the login screen, which is gdm. Therefore changes need to be made for the gdm user. I have found mentions of modifying xml files directly but it looks like the easiest way is to launch the gnome-control-center as the gdm user.
The steps are

su -
xhost +si:localuser:gdm #to allow gdm user access to X server session
sudo -u gdm dbus-launch gnome-control-center

The desktop background picture can now be changed to either one of the defaults or a new custom picture if desired. Once picture has been selected and gnome-control-center has been closed the change will take effect.

The only thing left is to remove access for gdm user to X server session
xhost -si:localuser:gdm

To change the desktop background from the commandline you can use the gsettings command and point it at you picture file as follows
gsettings set org.gnome.desktop.background picture-uri "file://<filename>"

Friday 21 June 2013

Refreshing memory on some basics

While going back across some Linux basics (always worth doing periodically), I was reminded of the command xfs_freeze. This command can also work on other journalled filesystems such as ext3, ext4, btrfs etc.

Also messing around with getopts bash builtin and getopt command, sample test script using getopts below

#!/bin/bash

if [ $# -eq 0 ] # Script invoked with no command-line args
then
echo "Usage: `basename $0` [-a] [-b] [-c] [-d <arg>]"
exit 99

fi

#first : suppresses error reporting from getopts
while getopts ":abcd:" option
do
case $option in
a ) echo "option a OPTIND=${OPTIND}";;
b | c ) echo "option $Option OPTIND=${OPTIND}";;
d ) echo "option d with argument \"$OPTARG\" OPTIND=${OPTIND}";;
* ) echo "Default error with options given";; # Default.
esac
done

exit $?


Note to self there must be a better way of displaying sample code in this blog.

Laptop OS Upgrade

Previously I have not been using my laptop frequently so no surprise that the OS needed upgrading.
Bumped the version of the distribution to something closer to current, will check it out and then bump in again to latest stable version.
The longest amount of time during the upgrade process was backing up (just to be safe) all the random files I had acquired. Overall took about 2 hours

Noted an interesting package installed called schroedinger which contains libraries for Dirac codec, one to check out some time. 

Thursday 20 June 2013

Dipping toe into the water

Testing various blogging platforms, possibly with a view to posting some blogs at some point in the future.

Just for fun nothing serious, just to keep track of the technologies I have been playing with and to keep useful notes in one central place.

Basic layout for now, will test out more the features as time goes on.