James Gardner


Booleans Add Up

Posted in Python by thejimmyg on the May 31st, 2007

This result suprised me today. If you add True to True in Python you get an integer 2 instead of a TypeError being raised. This is slightly unexpected but presumably there for backwards compatibility?

Python 2.4.4 (#2, Apr 5 2007, 20:11:18)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> True
True
>>> False
False
>>> True+False
1
>>> False+False
0
>>> True+True
2

Google Gears

Posted in Web by thejimmyg on the May 31st, 2007

Google today launched a new product called Google Gears which is an open source plugin available for Firefox, IE and others which enables pages to store data offline via a simple API. It uses an SQLite database for the storage and has a sync API.

It provides a half-way house between full desktop applications like Joyent Slingshot and XULRunner and traditional web applications.

SSHFS

Posted in Debian by thejimmyg on the May 29th, 2007

If you are using Xen to host a development server on your workstation one of the problems is that it can be tricky to edit the files in your usual desktop environment. If you have Debian Etch and a stock kernel you can use the SSH filesystem to mount the Xen server’s hard disk as a directory on your computer so that you can edit the files directly. This approach actually works really well.

sudo apt-get install sshfs

To mount the drive:

sudo modprobe fuse
cd ~/Desktop
sudo sshfs -o allow_other root@rms.dev:/ rms.dev

and to unmount:

cd ~/Desktop
sudo umount rms.dev

Rsync Backups and Hardlinking

Posted in Debian by thejimmyg on the May 29th, 2007

I’ve been looking for a good way to back up files on a remote server. Two solutions I’ve found are as follows:

Rsync and hardlinks: http://www.mikerubel.org/computers/rsync_snapshots/
Rsync and SSH: http://troy.jdmz.net/rsync/index.html

The first link describes an approach for creating incremental backups by using hardlinks to files on the same server (hardlinks don’t take up any extra space) and then rsyncing the copies to another server. I suppose you could do the same thing by creating a diff of the backed-up directory and storing it on Amazon S3.

The second link describes how to setup a cron job to rsync files securely to a remote server over SSH without using any passwords by setting up an SSH key.

Combining these two approaches should result in a very flexible backup solution.

reCAPTCHA

Posted in Web by thejimmyg on the May 28th, 2007

This is a nice idea that solves two problems at once. The first problem is that spammers regularly use computers to automate the process of posting spam messages to websites. The second problem is that old books need to be digitised from scanned copies of their words.

One way of preventing computers from being able to post to a site is to used a so-called CAPTCHA, which is simply an image of some text, suitably distorted or coloured to make it very difficult for a computer to work out what the letter are but still very obvious to a human.

reCAPTCHA simply displays two such words from scanned copies of text. It knows the letters which make up one word but not the other so when you enter the two words, if you get the one it knows correct it assumes you have entered the correct text for the one it doesn’t know. Computers used by spammers will not be able to guess either word so are stopped but human users will enter both words correctly and so help digitise the scanned words. Very neat! (via thoughtplay).

Vim Setup

Posted in Debian by thejimmyg on the May 19th, 2007

About a year ago I was first introduced to Vim by Olly Cope and others at the Institute of Child Health. I borroed the O’Reilly book and started learning it. Here is the setup I currently have in my ~/.vimrc file.

" Set colour scheme.
color wombat
” Set syntax hilighting
syntax on
” Replace tabs with spaces.
” With this option set, if you want to enter a real tab character use Ctrl-V key sequence.
set expandtab
” Set the number of space characters that will be inserted when the tab key is pressed.
set tabstop=4
” To replace the existing tab characters to spaces
retab
” Set the number of space characters inserted for indentation.
set shiftwidth=4
” Highlight all the search pattern matches.
” To disable the highlighting temporarily - set nohlsearch
set hlsearch
” Set the foreground and background colours
hi Search guifg=slategrey guibg=khaki
” Set line numbers
set number
” Set copy and pasting mode for terminals
set paste

The last command, set paste is particularly useful because it allows you to paste text directly into Vim running in a terminal and Vim correctly maintains the formatting.

You’ll notice I’ve set the color to use wombat. This is a special colour scheme which you have to download and install manually.

mkdir ~/.vim
mkdir ~/.vim/colors
wget http://www.vim.org/scripts/download_script.php?src_id=6657 -O ~/.vim/colors/wombat.vim

If you don’t want to use wombat, pablo is another scheme I quite like and it comes with Vim.

The version of Vim which comes with most Linux operating systems isn’t the full one so if you are looking to use Vim as your main editor you probably want to install the full version which includes gvim, the X windows version of Vim which integrates with Gnome:

sudo apt-get install vim-full

I honestly wouldn’t recommend Vim to people looking for an editor because although I now find it quick, the length of time I have spent not finding it very quick has meant that arguably it wasn’t worth the investment of time.

GNU Screen

Posted in Debian by thejimmyg on the May 19th, 2007

If you’ve had a situation where you are running a command on a remote server and need to close your terminal to go home or use another computer but don’t want to stop the command then GNU screen is for you. The website says:

Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells. Each virtual terminal provides the functions of the DEC VT100 terminal

In simple terms though it just a piece of software that separates what you are doing in a particular terminal from the terminal itself so that you close your terminal without affectting what is actually going on. It also has another use, it enables you to run multiple terminal sessions from the same actual terminal and switch between them at will.

To install it type:

sudo apt-get install screen

Here are some examples of its use.

Load up two terminals, we’ll call them A and B.
In terminal A run the screen command. You’ll see the following message:

Screen version 4.00.03 (FAU) 23-Oct-06

Copyright (c) 1993-2002 Juergen Weigert, Michael Schroeder
Copyright (c) 1987 Oliver Laumann

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program (see the file COPYING); if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

Send bugreports, fixes, enhancements, t-shirts, money, beer & pizza to
screen@uni-erlangen.de

                        [Press Space or Return to end.]

Press enter and you will see what looks like an ordinary prompt. Try running a command:

bose:/home/james# echo "This is screen window 0"
This is screen window 0

At this point we want to send a command to screen. screen commands are issued by pressing Ctrl+a and then the letter for the particular commad. To detatch from the screen session and go back to the terminal prompt press Ctrl+a then d. A message appears to tell you that you have detached from screen:

bose:/home/james# screen
[detached]

You can then reattach to screen using screen -r and you will see that the screen window is exactly as you left it:

bose:/home/james# echo "This is screen window 0"
This is screen window 0

Now we are reattached to screen we will create a new screen window. A screen window is effectively just another virtual terminal running within the screen program. You can create a new screen window by pressing Ctrl+a and then c for create. At this prompt you can enter this:

bose:/home/james# echo "This is screen window 1"
This is screen window 1

Now that we have two screen windows running we can toggle between them by pressing Ctrl+a and then Ctrl+a again. You can also get a list of all the screen windows by pressing Ctrl+a then . You’ll see this:

Num Name Flags
0 bash $
1 bash $

Notice that the default name for each window is the name of the shell you are running, in this case bash. You can rename the current screen window you are using by pressing Ctrl+a then A.

Now that we have a farily typical screen session we can have a go at attaching it to the other terminal. In the terminal you have been using type Ctrl+a and d and in terminal B type screen -r you will see the screen session you just detached from terminal A. Nifty eh?

To close a screen window you can type exit or to kill the screen window type Ctrl+a then k.

Other things you might like to try include Ctrl+a then S to split a screen in two and Ctrl+a and Tab to switch between panes.

There us some more information here: http://www.kuro5hin.org/story/2004/3/9/16838/14935

Borderless Windows Xfce 4

Posted in Debian by thejimmyg on the May 19th, 2007

Since I’ve been using my new desktop/server machine with dual montior support I’ve been desperately trying to set up a fullscreen VNC connection to Windows XP on one of the monitors and keep the other for a sensible Linux desktop. I very quickly managed to get a 1280×1024 VNC connection to WindowsXP but no matter how hard I tried I couldn’t get the VNC display to work full screen on just one of the monitors, either part of the Windows desktop was off screen because I couldn’t fit the window borders and the desktop onto the one screen or I had to resize the window and scrollbars appeared.

Here’s some other ideas I tried which failed:

  • Fiddling with the window sizes in Gnome in the hope of getting the whole visible area of the Window to overlap with the visible screen area.
  • Using the ratpoison window manager - I couldn’t get it to place the VNC window on the second monitor
  • Using xvncviewer in full screen mode - it just made a 1280×1024 screen in the middle of my two screens with the remaining portions blacked out
  • Enabling the Metacity toggle_fullscreen option in Gnome using gconf-tool2 - it just did nothing - apparantly a bug in the version I was using.

I’m pleased to say I have found a solution, I’ve switched to Xfce 4. You simply drag the VNC window to the monitor you want and hit Alt+F11 to full screen it. Works perfectly and is so simple. I now have a workspace for Linux/WindowsXP and one for a dual screen linux setup. Next I’m going to play with GNU screen which by all accounts sounds quite interesting.

I actually like Xfce generally, it feels quite speedy and has nice drop shadow and transparency effects built in which are fun to play with for 2 minutes before they become irritating and get disabled.

Update: Sadly this looks like it might be a temporary solution because I’m sure I read somewhere that 4.4 will be fully freedesktop.org compliant and therefore not allow fullscreen windows. This would be a diaster so I hope this is a mistake on my part.

Posted in Uncategorized by thejimmyg on the May 18th, 2007

Rest in peace Uncle Simon.

Dual Screen Radeon 7000 VE

Posted in Debian by thejimmyg on the May 5th, 2007

I purchased a Pentium 4 desktop from the Institute of Child Health yesterday (they were upgrading some of their machines) and have been busily setting it up today as my main server. One of the tricker things to get working is always the dual screen support but luckily it didn’t take too long this time.

The computer comes with a Radeon 7000 VE which works with the open source ati driver which Debian detects during the install. First a bit of background. There are three types of DVI connector:

  • DVI-D (digital only)
  • DVI-A (analog only)
  • DVI-I (digital & analog)

Both DVI-D and DVI-A can have single or dual interfaces. The dual interfaces allow two screens to be connected to the single DVI connector using an adaptor. You can tell which DVI interface your card supports by looking at the pins on the connector. The Radeon 7000 VE has a DVI-D dual interface so it can have two monitors plugged in. The wikipedia DVI article has more information and some pin diagrams.

I modified the /etc/X11/xorg.conf so that it used the radeon driver, had dbe loaded, and made use of a composite. Here’s the diff:

bose:/home/james# diff -u /etc/X11/xorg.conf.orig /etc/X11/xorg.conf
--- /etc/X11/xorg.conf.orig     2007-05-05 13:13:21.000000000 +0100
+++ /etc/X11/xorg.conf  2007-05-05 20:44:23.000000000 +0100
@@ -43,6 +43,8 @@
        Load    "glx"
        Load    "int10"
        Load    "vbe"
+       Load    "dbe"
+       Load    "type1"
 EndSection

 Section "InputDevice"
@@ -65,7 +67,17 @@

 Section "Device"
        Identifier      "ATI Technologies Inc Radeon RV100 QY [Radeon 7000/VE]"
-       Driver          "ati"
+       Driver          "radeon"
+       Option          "AGPMode" "8"
+       Option          "ColorTiling" "on"
+       Option          "AccelMethod" "XAA"
+       Option          "EnablePageFlip" "on"
+       Option          "XAANoOffScreenPixMaps"
+       Option          "RenderAccel" "true"
+       Option          "MergedFB" "true"
+       Option          "MonitorLayout" "LCD, LCD"
+       Option          "CRT2Position" "LeftOf"
+       Option          "MetaModes" "1280x1024-1280x1024"
        BusID           "PCI:1:0:0"
 EndSection

@@ -102,6 +114,7 @@
        SubSection "Display"
                Depth           24
                Modes           "1280x1024" "1024x768" "800x600" "640x480"
+               Virtual         2560 1024
        EndSubSection
 EndSection

@@ -115,3 +128,7 @@
 Section "DRI"
        Mode    0666
 EndSection
+
+Section "Extensions"
+       Option "Composite" "Enable"
+EndSection

and here is the complete file:

bose:/home/james# cat /etc/X11/xorg.conf
# /etc/X11/xorg.conf (xorg X Window System server configuration file)
#
# This file was generated by dexconf, the Debian X Configuration tool, using
# values from the debconf database.
#
# Edit this file with caution, and see the /etc/X11/xorg.conf manual page.
# (Type "man /etc/X11/xorg.conf" at the shell prompt.)
#
# This file is automatically updated on xserver-xorg package upgrades *only*
# if it has not been modified since the last upgrade of the xserver-xorg
# package.
#
# If you have edited this file but would like it to be automatically updated
# again, run the following command:
#   sudo dpkg-reconfigure -phigh xserver-xorg

Section "Files"
        FontPath        "/usr/share/fonts/X11/misc"
        FontPath        "/usr/X11R6/lib/X11/fonts/misc"
        FontPath        "/usr/share/fonts/X11/cyrillic"
        FontPath        "/usr/X11R6/lib/X11/fonts/cyrillic"
        FontPath        "/usr/share/fonts/X11/100dpi/:unscaled"
        FontPath        "/usr/X11R6/lib/X11/fonts/100dpi/:unscaled"
        FontPath        "/usr/share/fonts/X11/75dpi/:unscaled"
        FontPath        "/usr/X11R6/lib/X11/fonts/75dpi/:unscaled"
        FontPath        "/usr/share/fonts/X11/Type1"
        FontPath        "/usr/X11R6/lib/X11/fonts/Type1"
        FontPath        "/usr/share/fonts/X11/100dpi"
        FontPath        "/usr/X11R6/lib/X11/fonts/100dpi"
        FontPath        "/usr/share/fonts/X11/75dpi"
        FontPath        "/usr/X11R6/lib/X11/fonts/75dpi"
        # path to defoma fonts
        FontPath        "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType"
EndSection

Section "Module"
        Load    "i2c"
        Load    "bitmap"
        Load    "ddc"
        Load    "dri"
        Load    "extmod"
        Load    "freetype"
        Load    "glx"
        Load    "int10"
        Load    "vbe"
        Load    "dbe"
        Load    "type1"
EndSection

Section "InputDevice"
        Identifier      "Generic Keyboard"
        Driver          "kbd"
        Option          "CoreKeyboard"
        Option          "XkbRules"      "xorg"
        Option          "XkbModel"      "pc105"
        Option          "XkbLayout"     "gb"
EndSection

Section "InputDevice"
        Identifier      "Configured Mouse"
        Driver          "mouse"
        Option          "CorePointer"
        Option          "Device"                "/dev/input/mice"
        Option          "Protocol"              "ImPS/2"
        Option          "Emulate3Buttons"       "true"
EndSection

Section "Device"
        Identifier      "ATI Technologies Inc Radeon RV100 QY [Radeon 7000/VE]"
        Driver          "radeon"
        Option          "AGPMode" "8"
        Option          "ColorTiling" "on"
        Option          "AccelMethod" "XAA"
        Option          "EnablePageFlip" "on"
        Option          "XAANoOffScreenPixMaps"
        Option          "RenderAccel" "true"
        Option          "MergedFB" "true"
        Option          "MonitorLayout" "LCD, LCD"
        Option          "CRT2Position" "LeftOf"
        Option          "MetaModes" "1280x1024-1280x1024"
        BusID           "PCI:1:0:0"
EndSection

Section "Monitor"
        Identifier      "DELL 1702FP"
        Option          "DPMS"
EndSection

Section "Screen"
        Identifier      "Default Screen"
        Device          "ATI Technologies Inc Radeon RV100 QY [Radeon 7000/VE]"
        Monitor         "DELL 1702FP"
        DefaultDepth    24
        SubSection "Display"
                Depth           1
                Modes           "1024x768" "800x600" "640x480"
        EndSubSection
        SubSection "Display"
                Depth           4
                Modes           "1024x768" "800x600" "640x480"
        EndSubSection
        SubSection "Display"
                Depth           8
                Modes           "1024x768" "800x600" "640x480"
        EndSubSection
        SubSection "Display"
                Depth           15
                Modes           "1024x768" "800x600" "640x480"
        EndSubSection
        SubSection "Display"
                Depth           16
                Modes           "1280x1024" "1024x768" "800x600" "640x480"
        EndSubSection
        SubSection "Display"
                Depth           24
                Modes           "1280x1024" "1024x768" "800x600" "640x480"
                Virtual         2560 1024
        EndSubSection
EndSection

Section "ServerLayout"
        Identifier      "Default Layout"
        Screen          "Default Screen"
        InputDevice     "Generic Keyboard"
        InputDevice     "Configured Mouse"
EndSection

Section "DRI"
        Mode    0666
EndSection

Section "Extensions"
        Option "Composite" "Enable"
EndSection
Next Page »