četrtek, 27. oktober 2011

Xmarks

Usually I'm using two web broswers: Firefox and Chrome. I always tried having one bookmarks set. I never found a way to share them between those web browsers. I've tried exporting bookmarks from one browser and importing into another, but that didn't feel right. Luckly, yesterday I found Xmarks. Now my bookmarks are in the cloud :)) and I can share them easyly between Firefox and Chrome, since Xmarks has plugins for both.

torek, 14. junij 2011

KDE Konsole

I've been a happy KDE user since the eary days of it.
I've also used Konsole as my primary terminal application, but in recent Kubuntu releases it became slow.
Yesterday I switched to good old xterm with screen:
xterm -bg black -fg grey -fn -*-console-*-*-*-*-*-*-*-*-*-*-*-* -geometry 166x45


and in xterm I start screen with 10 sessions.
Now everything is fast again. :)

sobota, 16. april 2011

Is my application running?

A neat way to check if a instance of an application is already running is to use FileChannel and it's ability to lock it.
An example:
File lockFile = new File("APP_NAME.lock");
FileChannel fileChannel = new RandomAccessFile(lockFile, "rw").getChannel();
FileLock fileLock = fileChannel.lock();


lock() will block, but you could use tryLock() to check it the fileChannel is already locked.
I've been using it in our application on Linux and Windows.

ponedeljek, 14. februar 2011

Mercurial server installation for Windows

Installation of hgweb interface:
- install Apache HTTPD 2.2 to c:/Apps/Apache
- install Python 2.6 to c:/Python26
- install Mercurial to C:/Apps/HG
- install EasyInstall
This will find your Python installation and install it there.
- put c:/Python26 and c:/Python26/Scripts in you PATH
- install Flup Python module
easy_install flup-1.0.3.dev_20110111-py2.6.egg
- unzip C:/Apps/HG/library.zip C:/Apps/HG/dev
- copy c:/Apps/HG/templates directory to c:/Apps/HG/dev/templates

I have my Mercurial repositories in d:/HG/repos.

hgweb.fcgi in d:/HG looks like:

#!C:/Python26/python.exe -u
#
# An example FastCGI script for use with flup, edit as necessary

# Path to repo or hgweb config to serve (see 'hg help hgweb')
config = "d:/HG/hgweb.config"

# Uncomment and adjust if Mercurial is not installed system-wide:
import sys
sys.path.insert(0, "C:/Apps/HG/dev")

# Uncomment to send python tracebacks to the browser if an error occurs:
import cgitb; cgitb.enable()

import os
os.environ["HGENCODING"] = "UTF-8"

from mercurial import demandimport; demandimport.enable()
from mercurial.hgweb import hgweb
from flup.server.fcgi import WSGIServer
application = hgweb(config)
WSGIServer(application).run()

- configuration file for hgweb (d:/HG/hgweb.config) looks like:

[paths]
# One repository
#FOO = d:/HG/repos/FOO
# All repositories in d:/HG/repos
/ = d:/HG/repos/**

[web]
style = gitweb

- each repository under d:/HG/ has hgrc (in UTF-8) like this:

[web]
description = Repository description
style = gitweb
allow_push = *
push_ssl = false
verbose = false
allowbz2 = yes
allowgz = yes
allowzip = yes

[ui]
username = Owner of repo <repo.owner@example.com>
debug = false


NOTE: debug and verbose have to be false

- edit c:/Apps/Apache/conf/httpd.conf and add:

LoadModule cgi_module modules/mod_cgi.so
LoadModule env_module modules/mod_env.so

SetEnv FCGI_FORCE_CGI Y
ScriptAliasMatch ^/hg(.*) d:/HG/hgweb.fcgi$1
<Directory d:/HG>
Options ExecCGI FollowSymLinks
AllowOverride None
AddHandler cgi-script .cgi
Allow from all
AllowOverride All
</Directory>

- if you want to limit access to repositories add this to c:/Apps/Apache/conf/httpd.conf

<Location /hg>
AuthType Basic
AuthName "Mercurial repositories"
AuthUserFile D:/HG/hgusers
Require valid-user
</Location>

- then add valid users to D:/HG/hgusers like this:

htpasswd -c D:/HG/hgusers frodo # creates file D:/HG/hgusers and adds user frodo
htpasswd D:/HG/hgusers sam # only add usersam to exising D:/HG/hgusers file

DB2 SQL440 or SQL901 on DELETE

If you get SQL440 or SQL901 when you try to delete from a table, you might encountered this problem. The solution is to recreate all foreign keys that point to this table (MY_TABLE is the SQL script below).
The SQL to generate that SQL script for you is this (statement delimiter is #):

SELECT 'ALTER TABLE EMGSYS.' || TABNAME || ' DROP CONSTRAINT ' || CONSTNAME || '#' || CHR(13) || CHR(10) ||
'ALTER TABLE EMGSYS.' || TABNAME || ' ADD CONSTRAINT ' || CONSTNAME || ' FOREIGN KEY (' || TRIM(FK_COLNAMES) || ') REFERENCES EMGSYS.' || REFTABNAME || '(' || TRIM(PK_COL
NAMES) || ') ON DELETE ' ||
(CASE WHEN DELETERULE = 'R' THEN 'RESTRICT' WHEN DELETERULE = 'C' THEN 'CASCADE' END) || ' ON UPDATE ' || (CASE WHEN UPDATERULE = 'R' THEN 'RESTRICT' WHEN UPDATERULE = 'A
' THEN 'NO ACTION' END) || '#'
FROM SYSCAT.REFERENCES WHERE REFTABNAME = 'MY_TABLE' ORDER BY TABNAME WITH UR

There are still some constands missing in DELETERULE and UPDATERULE. The various values can be seen here.

ponedeljek, 7. februar 2011

Mercurial

At our company we used (well, still using) CVS as our versioning system. We've finally moved one of our main projects to Mercurial. I've been given a task to expose the repository over HTTP and securing access to it. In the following days I will post how I did that on Windows. Oh, well, I know. I'd rather use Linux, but what can you do....

sobota, 1. januar 2011

New Year

I wish to you all a better 2011