»
S
I
D
E
B
A
R
«
Timesheet Prompt
Jul 31st, 2009 by Andrew McCombe

At work we keep track of work and time by using a web-based timesheet system. This requires employees to update their online timesheet on a daily basis.

Some of the Linux users use a text file to update the timesheet (via a python script written by a colleague) but there still remains the problem of remembering to update the text file when completing a job.

I have written a small bash script that uses Zenity to prompt me for information and then write it to my log file.

Here is the script:

#!/bin/sh
export DISPLAY=:0.0
THETIME=`date +%H:%M`
THEDATE=`date +%Y-%m-%d`
LOG='~/bin/logs/'`date +%Y`'/'`date +%b`'/'`date +%d`'.txt'
LOGFILE=`echo $LOG | tr "[:upper:]" "[:lower:]"`
 
TEXT=`zenity --entry  --title="Timesheet Update" --text="$THETIME: What are you working on?" --entry-text ""`
 
# check if logfile exists and if not, create it
 
if [ ! -f $LOGFILE ]; then
	touch $LOGFILE;
	echo "$THEDATE:" >> $LOGFILE;
fi
 
case $? in
 
                 0)
			echo "$THETIME - $TEXT" >> $LOGFILE;;
                 1)
                        echo "Nothing Added.";;
                -1)
                        echo "Nothing Added.";;
        esac

I set up a cron to run this script every 30 minutes during working hours.

At the end of the day I open the timesheet file, format it and send it to the python script to update my log. Simple.

Share mouse and keyboard across computers
Jul 30th, 2009 by Andrew McCombe

As a website developer I have a need to use multiple operating systems at the same time.  I have a laptop that dual boots Windows Vista and Ubuntu 9.04 and I use this to test websites in Internet Explorer and Safari on Vista.

To save me from having to switch between the Linux Desktop and my Vista laptop everytime I wanted to reload the Vista browser I use a unix utility called x2vnc.  Simply install a VNC server on Vista (I used TightVNC) and start it running.  Then run the x2vnc utility on the Linux Desktop:

sudo aptitude install x2vnc
x2vnc andrew-laptop:5901 &

I sometimes have the need to control another Linux machine from the desktop too.  This is where the x2x utility comes in.  First log in to the remote machine and install the x2x utility:

sudo aptitude install x2x

From my local machine, with the screen of the remote computer to the right of the local one:

ssh user@remote -X "x2x -east -to :0" &

This should allow you to move the mouse off the right of your screen and onto the desktop of the remote machine.

Cool or what?!

MySQL Stored Procedure tutorial
Jul 30th, 2009 by Andrew McCombe

How to create and use a stored procedure in MySQL:

mysql > CREATE TABLE team (
id INT(3) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 
team_name VARCHAR(20) NOT NULL, 
position TINYINT(3) UNSIGNED NOT NULL) 
ENGINE=INNODB;
 
INSERT INTO team (team_name, position) 
VALUES ('McLaren',1),('Ferrari',2), ('Brawn',3), ('Toyota',4), 
('Red Bull', 5), ('Torro Rosso', 6), ('Williams', 7), ('Force India',8),
('BMW', 9), ('Renault', 10);
 
DELIMITER |
CREATE PROCEDURE position_team(teamid INT, newposition INT)
BEGIN
UPDATE team SET position=(position+1) WHERE position=newposition;
UPDATE team SET position=newposition WHERE id=teamid;
SELECT position, team_name FROM team ORDER BY position ASC;
END
|
DELIMITER ;

To call this use the ‘call’ keyword and pass the parameters:

CALL position_team(2, 1);
+----------+-------------+
| position | team        |
+----------+-------------+
|        1 | Ferrari     |
|        2 | McLaren     |
|        3 | Brawn       |
|        4 | Toyota      |
|        5 | Red Bull    |
|        6 | Torro Rosso |
|        7 | Williams    |
|        8 | Force India |
|        9 | BMW         |
|       10 | Renault     |
+----------+-------------+
A day in the life of Spinnaker Tower, Portsmouth
Jul 17th, 2009 by Andrew McCombe

Spinnaker Tower

Please allow time for this to load. Size is 18mb.

»  Substance: WordPress   »  Style: Ahren Ahimsa