Johan Känngård » Programming http://johankanngard.net Useful tips for developers Thu, 19 May 2011 18:40:56 +0000 en hourly 1 http://wordpress.org/?v=3.0.1 Log File Roller For Microsoft Windows http://johankanngard.net/2008/12/11/log-file-roller-for-microsoft-windows/ http://johankanngard.net/2008/12/11/log-file-roller-for-microsoft-windows/#comments Thu, 11 Dec 2008 13:50:43 +0000 Johan Känngård http://johankanngard.net/?p=330 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:\log\at.log, you can run:

rollLog c:\logs at.log

Afterwards, you have one file named c:\logs\at.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!

]]>
http://johankanngard.net/2008/12/11/log-file-roller-for-microsoft-windows/feed/ 1
Simple Combobox using Autocompleter.Local from Script.aculo.us http://johankanngard.net/2008/10/08/simple-combobox-using-autocompleterlocal-from-scriptaculous/ http://johankanngard.net/2008/10/08/simple-combobox-using-autocompleterlocal-from-scriptaculous/#comments Wed, 08 Oct 2008 13:19:20 +0000 Johan Känngård http://johankanngard.net/?p=302 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:

]]>
http://johankanngard.net/2008/10/08/simple-combobox-using-autocompleterlocal-from-scriptaculous/feed/ 2
lotus.com/ldd no more :-( http://johankanngard.net/2008/09/04/lotuscomldd-no-more/ http://johankanngard.net/2008/09/04/lotuscomldd-no-more/#comments Thu, 04 Sep 2008 10:50:23 +0000 Johan Känngård http://johankanngard.net/?p=298 IBM has removed the old redirect for the Lotus Developer Domain, I only get to Lotus Software using that old URL. Now is time to remember this: http://www.ibm.com/developerworks/lotus

]]>
http://johankanngard.net/2008/09/04/lotuscomldd-no-more/feed/ 8
HOWTO Use Lotus Notes, Domino Designer and Domino Administrator 8.01 on Ubuntu 8.04 via Wine 1.0.0 http://johankanngard.net/2008/09/01/howto-use-lotus-notes-domino-designer-and-domino-administrator-801-on-ubuntu-804-via-wine-100/ http://johankanngard.net/2008/09/01/howto-use-lotus-notes-domino-designer-and-domino-administrator-801-on-ubuntu-804-via-wine-100/#comments Mon, 01 Sep 2008 20:09:28 +0000 Johan Känngård http://johankanngard.net/?p=294 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!

]]>
http://johankanngard.net/2008/09/01/howto-use-lotus-notes-domino-designer-and-domino-administrator-801-on-ubuntu-804-via-wine-100/feed/ 2
MySQL Commands Cheat Sheet http://johankanngard.net/2008/07/31/mysql-commands-cheat-sheet/ http://johankanngard.net/2008/07/31/mysql-commands-cheat-sheet/#comments Thu, 31 Jul 2008 12:03:48 +0000 Johan Känngård http://johankanngard.net/?p=255 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; [...]]]> 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
]]>
http://johankanngard.net/2008/07/31/mysql-commands-cheat-sheet/feed/ 0
HOWTO: Install Lotus Domino 7.0.2 on Ubuntu 8.0.4 http://johankanngard.net/2008/07/16/howto-install-lotus-domino-702-on-ubuntu-804/ http://johankanngard.net/2008/07/16/howto-install-lotus-domino-702-on-ubuntu-804/#comments Wed, 16 Jul 2008 09:05:23 +0000 Johan Känngård http://johankanngard.net/?p=196 This minimalistic guide shows how to install Domino 7.0.2 on Ubuntu 8.0.4 server or workstation. I did this on Ubuntu 7, but did not write everything down, which meant learning/searching for the information once more. Please let me know if you have better ways of doing this!

Create a domino user and group


$ sudo useradd -m domino
$ sudo groupadd domino
$ sudo passwd domino

Add required libraries

Domino uses some libraries that is not installed by the standard Ubuntu installation.


$ sudo apt-get install libstdc++5
$ sudo apt-get install libxmu6
$ sudo apt-get install libxp6
$ sudo apt-get install libxp-java
$ sudo apt-get install libxtst6

Install

Unpack the installation file (my is named S7.0.2.tar) and run the linux/domino/install script as root. Use default settings (except user, enter domino), use “Manual setup”.


$ tar -xvf S7.0.2.tar
$ cd S7.0.2/linux/domino
$ sudo install

Change ownerships on files

Since you installed as root, the files is owned by root. I guess if install was run as the domino user, this step would not be required.


$ sudo chown -R domino /local/notesdata
$ sudo chgrp -R domino /local/notesdata
$ sudo chown -R domino /opt/ibm
$ sudo chgrp -R domino /opt/ibm

Firewall

Stop your local firewall or open 1352 in the local firewall. If you are using shorewall, you can do your own Notes macro. Change the port from 80 to 1352 in the macro.Notes file.


$ sudo cp /usr/share/shorewall/macro.HTTP /usr/share/shorewall/macro.Notes
$ sudo gedit /usr/share/shorewall/macro.Notes

Add the following (depending on setup…) to /etc/shorewall/rules:


Notes/ACCEPT net $FW

Conflicting services

Stop any mail, web, ldap services, so that Domino does not conflict on ports. Remember to disable those you don’t need or disable the Domino services that you don’t need.

$ sudo /etc/init.d/postfix stop
$ sudo /etc/init.d/courier-imap stop
$ sudo /etc/init.d/courier-imap-ssl stop

Relink sh

The server script uses /bin/sh, relink sh to bash that normally links to /bin/dash.


$ sudo rm /bin/sh
$ sudo ln -s /bin/bash /bin/sh

nsd.sh

I got many “Command not found” errors when starting the server first time. After some research, I found that the script requires gawk in sd.sh:

$ sudo apt-get install gawk

Start the server setup listener


$ su notes
$ DISPLAY=:0.0
$ export DISPLAY
$ cd /local/notesdata
$ /opt/ibm/lotus/bin/server -listen

If you want to add a server with existing IDs, put the certifier ID, the server ID and the admin ID in the notesdata directory on the server. Run the Remote Server Setup utility on a client. Usually in Start\Lotus Applications\Remote Server Setup. Configure as a normal setup.

Server startup script

To be able to start Domino on startup, restart it and shutdown when system restarts, you can download domino init.d-script and put in /etc/init.d. Restart the server to see if it works.


$ cd /etc/init.d
$ sudo wget http://johankanngard.net/wp-content/uploads/2008/07/domino
$ sudo chmod +x domino
$ sudo chown domino domino
$ sudo chgrp domino domino
$ sudo update-rc.d domino defaults
$ sudo shutdown -r now

Test

Use a Notes client and test that the server is up and running. To see if the server is running on the server, you use telnet.


$ ps a | grep server
4505 pts/0 Ss+ 0:00 su - domino -c /opt/ibm/lotus/bin/server

You can also try connecting to the server locally with telnet using:


$ telnet localhost 1352
Trying 127.0.0.1...
Connected to localhost.
Escape character is \\\\\\\\\\\\\\\'^]\\\\\\\\\\\\\\\'.

Some links of interest


Updated the startup script since the stop argument wasn’t working.

]]>
http://johankanngard.net/2008/07/16/howto-install-lotus-domino-702-on-ubuntu-804/feed/ 8
Full and incremental dump of a Subversion repository from a Windows BAT file http://johankanngard.net/2008/05/23/full-dump-of-a-subversion-repository-from-a-windows-bat-file/ http://johankanngard.net/2008/05/23/full-dump-of-a-subversion-repository-from-a-windows-bat-file/#comments Fri, 23 May 2008 13:47:43 +0000 Johan Känngård http://johankanngard.net/2008/05/23/full-dump-of-a-subversion-repository-from-a-windows-bat-file/ The first is something you should do weekly on your Subversion repository – a full dump. Put the following in a BAT or CMD file on a Windows box, and run it scheduled.


@echo off
REM Creates a full dump of the repository, should be run weekly

for /f \"tokens=1-4 delims=- \" %%a in (\'date /T\') do set year=%%a
for /f \"tokens=1-4 delims=- \" %%a in (\'date /T\') do set month=%%b
for /f \"tokens=1-4 delims=- \" %%a in (\'date /T\') do set day=%%c
for /f \"tokens=1-2 delims=: \" %%a in (\'time /T\') do set hour=%%a
for /f \"tokens=1-2 delims=: \" %%a in (\'time /T\') do set minute=%%b
set TODAY=%year%%month%%day%
set NOW=%hour%%minute%

for /F \"tokens=1 \" %%i IN (\'svnlook youngest c:\\repository\') do call set YOUNGEST=%%i
echo %YOUNGEST% > c:\\backup\\repository\\latestRev.dat
svnadmin dump c:\\repository > c:\\backup\\repository\\svndump_full_rev%YOUNGEST%.%TODAY%%NOW%

The above example makes a dump to c:\backup\repository of your repository at c:\repository named with the most recent revision and todays date and time.
The example below creates incremental dumps using the latestRev.dat file to store the latest revision that was dumped.

@echo off
REM Creates a partial dump with all revisions since last full dump, should be run daily

for /f \"tokens=1-4 delims=- \" %%a in (\'date /T\') do set year=%%a
for /f \"tokens=1-4 delims=- \" %%a in (\'date /T\') do set month=%%b
for /f \"tokens=1-4 delims=- \" %%a in (\'date /T\') do set day=%%c
for /f \"tokens=1-2 delims=: \" %%a in (\'time /T\') do set hour=%%a
for /f \"tokens=1-2 delims=: \" %%a in (\'time /T\') do set minute=%%b
set TODAY=%year%%month%%day%
set NOW=%hour%%minute%

for /F \"tokens=1 \" %%i in (\'svnlook youngest c:\\repository\') do call set YOUNGEST=%%i
set PREVIOUS=0
if not exist c:\\backup\\repository\\latestRev.dat goto nolatestrev

for /F \"tokens=1 \" %%i in (c:\\backup\\repository\\latestRev.dat) do call set PREVIOUS=%%i

:nolatestrev:
if %YOUNGEST% == %PREVIOUS% goto noupdate

echo %YOUNGEST% > c:\\backup\\repository\\latestRev.dat

svnadmin dump -r %PREVIOUS%:%YOUNGEST% c:\\repository > c:\\backup\\repository\\svndump_incremental_rev%PREVIOUS%to%YOUNGEST%.%TODAY%%NOW%
goto finally

:noupdate
echo No dump needed
:finally

I’m no Windows batch file pro, but I got this working anyway with some help from Google.

]]>
http://johankanngard.net/2008/05/23/full-dump-of-a-subversion-repository-from-a-windows-bat-file/feed/ 6
Post “Java versions in Lotus Domino and Notes” updated http://johankanngard.net/2007/12/04/post-java-versions-in-lotus-domino-and-notes-updated/ http://johankanngard.net/2007/12/04/post-java-versions-in-lotus-domino-and-notes-updated/#comments Tue, 04 Dec 2007 12:43:55 +0000 Johan Känngård http://johankanngard.net/2007/12/04/post-java-versions-in-lotus-domino-and-notes-updated/ I’ve added 8.0 to the list.

]]>
http://johankanngard.net/2007/12/04/post-java-versions-in-lotus-domino-and-notes-updated/feed/ 0
Add your own indexOf in the JavaScript Array object http://johankanngard.net/2007/10/31/add-your-own-indexof-in-the-javascript-array-object/ http://johankanngard.net/2007/10/31/add-your-own-indexof-in-the-javascript-array-object/#comments Wed, 31 Oct 2007 13:16:45 +0000 Johan Känngård http://johankanngard.net/2007/10/31/add-your-own-indexof-in-the-javascript-array-object/ Internet Explorer does not have an indexOf method in the Array object. Here is how you can add your own:

if(!Array.indexOf){
Array.prototype.indexOf=function(o){
for(var i=0;i if(this[i]==o) return i;
return -1;
}
}

Use it like this:

var a=new Array(\'aaa\',\'bbb\',\'ccc\');
alert(a.indexOf(\'bbb\')); // Shows 1 as it is the index of \'bbb\' in the a Array.
alert(a.indexOf(\'b\')); // Shows -1 since \'b\' is not a member of the a Array.

]]>
http://johankanngard.net/2007/10/31/add-your-own-indexof-in-the-javascript-array-object/feed/ 0
MySQL 5 Stored Procedures Cheat Sheet http://johankanngard.net/2007/07/05/mysql-5-stored-procedures-cheat-sheet/ http://johankanngard.net/2007/07/05/mysql-5-stored-procedures-cheat-sheet/#comments Thu, 05 Jul 2007 10:37:57 +0000 Johan Känngård http://johankanngard.net/2007/07/05/mysql-5-stored-procedures-cheat-sheet/ SHOW PROCEDURE STATUS; Example output (with cropped dates and times for readable table): Db Name Type Definer Modified Created Security_type Comment mydb store_user PROCEDURE root 2007-0.. 2007-0.. DEFINER mydb store_cart PROCEDURE root 2007-0.. 2007-0.. [...]]]> I will add more when I stumble upon commands I can’t remember the syntax of.

To list all stored procedures:


mysql> SHOW PROCEDURE STATUS;

Example output (with cropped dates and times for readable table):

Db Name Type Definer Modified Created Security_type Comment
mydb store_user PROCEDURE root 2007-0.. 2007-0.. DEFINER
mydb store_cart PROCEDURE root 2007-0.. 2007-0.. DEFINER
mydb store_settings PROCEDURE root 2007-0.. 2007-0.. DEFINER


To create a new procedure


mysql> DELIMITER $$
mysql> CREATE PROCEDURE adduser(IN username VARCHAR(32), IN emailaddress VARCHAR(32))
BEGIN
INSERT INTO users VALUES (username, emailaddress);
END
$$

To show a stored procedure


mysql> SHOW CREATE PROCEDURE `userdb`.`adduser`\\\\G

Example output:

*************************** 1. row ***************************
Procedure: adduser
sql_mode:
Create Procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE `adduser`(IN username varchar(32), IN emailaddress(32))
BEGIN
INSERT INTO users VALUES (username, emailaddress);
END
1 row in set (0.00 sec)

To call a stored procedure from Java


Connection con = DriverManager.getConnection(url, user, password);
CallableStatement statement = con.prepareCall(\\\"{call userdb.adduser(?, ?)}\\\");
int i = 0;
statement.setString(i++, \\\"myuser\\\");
statement.setString(i++, \\\"[email protected]\\\");
statement.execute();

For this to work you must give the user SELECT privilege to the proc table in the MySQL database, where the stored procedures are stored. Do it like this:

GRANT SELECT ON `mysql`.`proc` TO \\\'mysqluser\\\'@\\\'myhost\\\';

For a list of more commands, see my MySQL Commands Cheat Sheet.

]]>
http://johankanngard.net/2007/07/05/mysql-5-stored-procedures-cheat-sheet/feed/ 0