SpringCross avklarat!

Vi var tre tappra B3IT:are som ställde upp i årets upplaga av SpringCross. 6km var distansen som gällde, och själv hade jag som mål att spring på under 36 minuter. Det lyckades jag med, den officiella tiden blev 35:23, vilket jag är väldigt nöjd med! För att vara första gången på denna tävling och första gången i området, tyckte jag det gick riktigt bra. Tyvärr fick jag en del mjölksyra i benen efter halva loppet, och fick ta det lugnare någon kilometer. Men det är bara till att träna mer till nästa år!

Kolla Google Maps för bansträckningen, och GPX-filen från min pulsklocka, en GlobalSat GH625M.


View Larger Map

Log File Roller For Microsoft Windows

A simple log file roller, that rolls/rotates a file from FILENAME.0, to FILENAME.1, onwards to FILENAME.9. If FILENAME.9 exists, it is deleted. Can be used to keep log files small and managable, and delete old ones. The code is not pretty, I could not get it work with loops. If anyone has a better way of doing this, please let me know! :-)

Usage:

rollLog LOGDIRECTORY LOGFILENAME

For instance, if you have a log at c:logat.log, you can run:

rollLog c:logs at.log

Afterwards, you have one file named c:logsat.log.0. The next time you run it (and there has been something written to at.log) you get two files, at.log.0 and at.log.1.

The rollLog.cmd file is here!

HOWTO Restart shoutcast if inbound stream is lost

This is a simple way to get Shoutcast restarted (tested in Ubuntu 8.04) if the inbound stream is lost. You need Lynx installed for this to work, there might be better ways of achieving the same result though. To install Lynx:


$ sudo apt-get install lynx

Put in file shoutcast_supervisor.sh in /usr/bin:

#!/bin/bash
ONLINE=$(lynx -dump localhost:8000 | grep "Stream is up" | wc -l)
if [ "$ONLINE" -eq "0" ]
then
logger -i Inbound connection not found. Restarting Shoutcast.
/etc/init.d/shoutcast restart
fi

Change ownership, group and execution:

$ sudo chown root /usr/bin/shoutcast_supervisor.sh
$ sudo chgrp root /usr/bin/shoutcast_supervisor.sh
$ sudo chmod +x /usr/bin/shoutcast_supervisor.sh

Add the script to cron.d your preferred way, I do it in /etc/cron.d in a file name shoutcast_supervisor:

0 * * * * root /usr/bin/shoutcast_supervisor.sh
15 * * * * root /usr/bin/shoutcast_supervisor.sh
30 * * * * root /usr/bin/shoutcast_supervisor.sh
45 * * * * root /usr/bin/shoutcast_supervisor.sh

Restart cron:

$ sudo /etc/init.d/cron restart

…and the script is run every 15 minutes and will restart the Shoutcast daemon if the inbound connection was lost. Change the interval if you need to check more often. Sometimes this solves connection problems. Check the syslog for any message that the daemon was restarted, like:

$ tail /var/log/syslog

HOWTO Edit your crontab with Emacs

Another ”wee” tip. I had a hard time doing this right…

Put emacs in the EDITOR shell variable:

$ EDITOR=emacs
$ export EDITOR

and add the following to your ~/.emacs:

(set 'temporary-file-directory "/tmp")

Now, edit the crontab file via:

$ crontab -e

Edit and save the file, and you should get a response from crontab:

crontab: installing new crontab

If you get an error message, something is wrong. You can check that your edits really changed your crontab using:

$ crontab -l

Simple Combobox using Autocompleter.Local from Script.aculo.us

The Autocompleter.Local in the Script.aculo.us Prototype-addon is quite nice. It can be used to get type-ahead into a field if you have a local JavaScript Array. I wanted to extend the functionality to have it behave as a Combobox, which is like a Select with a text input field. Here is how I did it, be advised it has some bugs, let me know if you have a better solution!

var Combobox={};
Combobox.Local=Class.create(Autocompleter.Local,{
initialize:function($super,element,update,array,options){
$super(element,update,array,options);
this.options.minChars=this.options.minChars||0;
Event.observe(this.element,'click',this.onClick.bindAsEventListener(this));
},
onClick:function($super,event){
if(Event.element(event).id){
if(this.active){
this.hasFocus=false;
this.active=false;
this.hide();
}else{
this.activate();
this.render();
}
return;
}
$super(event);
}
});

The CSS I use is a modified variant of the Autocompleter.Local wiki page:

.combo {
background-image:url(combo_select2.gif);
background-repeat:no-repeat;
background-position:right top;
margin-right:10px;
}

.combo:hover {
background-image:url(combo_select2.gif);
background-repeat:no-repeat;
background-position:right -18px;
}

div#autocomplete {
margin:0px;
padding:0px;
width:250px;
background:#fff;
border:1px solid #888;
position:absolute;
}

div#autocomplete ul {
margin:0px;
padding:0px;
list-style-type:none;
}

div#autocomplete ul li.selected {
background-color:#ffb;
}

div#autocomplete ul li {
margin:0;
padding:2px;
height:12px;
display:block;
list-style-type:none;
cursor:pointer;
}

Usage:

new Combobox.Local('textFieldID','outputDivID',array,options);

Example JavaScript:

var cities=new Array('Stockholm','Göteborg','Kiruna');
new Combobox.Local(
'cityField',
'autocomplete',
cities,
{
partialSearch:true,
fullSearch:true,
partialChars:0,
minChars:0
}
);

Example HTML:


The Windows XP style combobox image referenced in the CSS can be found here:

HOWTO Use Lotus Notes, Domino Designer and Domino Administrator 8.01 on Ubuntu 8.04 via Wine 1.0.0

I just followed Julian’s excellent guide and it worked! Even though the guide was for previous versions of both Notes, Ubuntu and Wine, I did not have to make any additional steps to get it working. All programs works, I haven’t found anything that is broken (yet), and it’s great having the Designer ”directly” in Ubuntu instead of firing up VirtualBox.

Thanks Julian, for your excellent guide!

MySQL Commands Cheat Sheet

Another memory-dump. The manual contains more information (that’s a surprise :-).

mysql> delete from TABLE where id=X
Removes the specified row
mysql> describe TABLE;
Shows the structure of the specified table
mysql> select * from TABLE;
Shows all rows in the specified table :-O
mysql> show procedure status;
Shows stored procedures
mysql> show table status;
Shows tables in current database
mysql> use MYDATABASE;
Changes the database to act on

Bash Variables Cheat Sheet

For a complete list, see Bash Reference Manual – Bash Environment Variables. This is just my own memory-dump. To get the value of a variable, you can use:

echo $OLDPWD

OLDPWD
previous current directory
PWD
current directory
LANG
the language used by programs, check with locale -a for available locales. Can be set in .bash_profile with export LANG=”en_US.utf8″
LANGUAGE
the language used by programs, check with locale- a for available locales. Can be set in .bash_profile with export LANGUAGE=”en_US.utf8″
RSYNC_RSH
the shell used for rsync, usually /usr/bin/ssh