Stripping (HTML) tags in XSLT

As there doesn’t seem to be any built-in function in XLST for stripping tags from strings (e.g., to remove all markup from a piece of HTML-formatted text), people came up with a recursive template-based solution, which has been posted several times on the web (e.g., here). However, I found this approach hard to use when the string to be cleaned from all tags already is stored in a variable or is created by using a xsl:value-of statement. Therefore, I transformed the existing template-based solution into a function-based one, which is a bit shorter and easier to use. Here it is:

<xsl:function name="util:strip-tags">
  <xsl:param name="text"/>
  <xsl:choose>
    <xsl:when test="contains($text, '&lt;')">
      <xsl:value-of select="concat(substring-before($text, '&lt;'),
        util:strip-tags(substring-after($text, '&gt;')))"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$text"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:function>

Note: Don’t forget to declare a namespace for this function (called util in the above code).

Posted in XML | Leave a comment

Where to Download the DB2 JDBC driver

When you want to access a DB2 database from Java, you usually need IBM’s JDBC driver for DB2. In the past, I (and some other people I know) always had trouble in finding out where to download the recent version of the driver. To solve this issue once and for all, I just took a deep dive into IBM’s website. There I found the following page, which seems to be ultimate resource to downloading DB2′s JDBC driver: https://www-304.ibm.com/support/docview.wss?uid=swg21363866.

Posted in DB2 | Leave a comment

Steve Jobs’ Macworld 2007 Keynote (iPhone Introduction) in High Quality

For a course about giving good presentations we are currently offering at work, I was looking for a high-quality version of Steve Jobs’ famous iPhone introduction at Macworld 2007. When searching on YouTube, I only got videos in awful resolutions. Even the “official” video stream offered by Apple isn’t too impressive (direct link to the stream). I spent some time on searching for a better version and finally came up with the following (if you want to download these files, you can use tools such as youtube-dl):

Part 1
Part 2
Part 3
Part 4
Part 5
Part 6
Part 7
Part 8
Part 9
Part 10
Part 11

Posted in Uncategorized | 2 Comments

VMware Workstation 7.1.2 and Fedora 14

UPDATE: VMware Workstation 7.1.3 works out of the box with Fedora 14.

As always, VMware has not been able to keep up with recent changes in Linux (kernel 2.6.35 and up). This becomes apparent, when trying to run VMware Workstation in the new Fedora 14. Compiling the VMware kernel module fails with errors like the following:

error: implicit declaration of function ‘iommu_unmap_range’
error: ‘struct sock’ has no member named ‘sk_sleep’

Combining the hints from here and here, I arrived at the following solution, which patches VMware’s kernel module:

cd /tmp
tar xvf /usr/lib/vmware/modules/source/vmmon.tar -C /tmp
perl -pi -e 's,_range,,' vmmon-only/linux/iommu.c
sudo tar cvf /usr/lib/vmware/modules/source/vmmon.tar vmmon-only

cd /tmp
tar xvf /usr/lib/vmware/modules/source/vsock.tar -C /tmp
perl -pi -e 's,sk->compat_sk_sleep,compat_sk_sleep(sk),' vsock-only/linux/af_vsock.c
perl -pi -e 's,listener->compat_sk_sleep,compat_sk_sleep(listener),' vsock-only/linux/af_vsock.c
sudo tar cvf /usr/lib/vmware/modules/source/vsock.tar vsock-only

sudo vmware-modconfig --console --install-all

Posted in VMware | 26 Comments

Running MATLAB scripts on a remote server

I often have to run some experiments with large data sets in MATLAB. Therefore, it comes handy to do this on a machine that is different from my notebook. The following bash script remotely runs a given MATLAB script called matlabbg and writes all console output to some logfile:

#!/bin/bash
nohup matlab -nodisplay -r "run $1" >$2 2>&1 &

To run the MATLAB script myscript.m in the background and write the output to myscript.log, simply do the following:

matlabbg myscript.m myscript.log

Posted in MATLAB | Leave a comment

DB2: How to Add an Identity Column to an Existing Table

Adding generated key columns to existing tables seems to be complicated in DB2. The following code adds a new generated primary key id to the table tablename. Granted, the code is ugly, but it works. I was not able to come up with a better solution in time.


ALTER TABLE tablename ADD COLUMN id INTEGER NOT NULL WITH DEFAULT 0
ALTER TABLE tablename ALTER COLUMN id GENERATED BY DEFAULT AS IDENTITY
REORG TABLE tablename
UPDATE tablename SET id = DEFAULT
ALTER TABLE tablename ALTER COLUMN id SET PRIMARY KEY

EDIT: I tested this code with DB2 9.7, but it should work on earlier versions of DB2.

Posted in DB2 | 3 Comments

Windows 7: Persistent Storage of Login Credentials for Samba Shares

I have a Windows 7 installation running in a VMware virtual machine. Within Windows, I mounted a network drive pointing to a Samba share within our local network, which is secured by username/password. However, although I told Windows several times to remember my login credentials (username/password) when it asked for them, Windows stored them only for the current session. This can be seen using Windows’ credential manager (Control Panel\User Accounts and Family Safety\Credential Manager). Therefore, the data was lost after each reboot and I had to enter them again.

There is a simple (but strange) solution to this problem: Instead of entering just your username when asked for, enter SERVERNAME\USERNAME. Adding the server name as “remote domain” makes Windows think that you are located within a “trustworthy” enterprise environment. Then, your login credentials are stored persistently, thus surviving reboots. Thanks to Microsoft for this intuitive mechanism.

Posted in Uncategorized | 1 Comment

How to look up SQL error codes quickly in DB2

Quite regularly DB2 complains about my SQL statements and usually returns a cryptic error message including an even more cryptic SQL error code. What I normally do in those situations is looking up the error code in the DB2 Information Center, which takes some time. I just found out that there is an easier way to get at least a short explanation of what an error code means. For example, to look up the error code -161, you can use the following SQL query:

VALUES SQLERRM(-161)

Result:

1
------------------------------------------------------------------------------------------------------
SQL0161N  The resulting row of the insert or update operation does not conform to the view definition.

Nice.

Posted in DB2 | Leave a comment

What SQL statements are currently running on my DB2 database server?

To see some detailed info about which users are currently connected to your DB2 database server (including the SQL statements they are running), you can use the following query (tested with DB2 9.7, fixpack 3a):

    WITH a AS (SELECT a.application_handle, a.system_auth_id, a.application_name, a.client_wrkstnname, a.workload_name, a.workload_occurrence_state, b.activity_id, b.uow_id, b.local_start_time, b.activity_state, b.activity_type, b.total_cpu_time, b.rows_read, b.rows_returned, b.query_cost_estimate, b.direct_reads, b.direct_writes
                 FROM TABLE(wlm_get_service_class_workload_occurrences_v97(NULL, NULL, NULL)) a
                      LEFT JOIN TABLE(wlm_get_workload_occurrence_activities_v97(NULL, NULL)) b ON a.application_handle = b.application_handle),
         b AS (SELECT t.*
                 FROM TABLE(mon_get_activity_details(FOR EACH ROW OF (SELECT application_handle, uow_id, activity_id, NULL FROM a WHERE activity_id > 0))) t),
         c AS (SELECT x."activity_id" activity_id, x."uow_id" uow_id, x."stmt_text" stmt_text
                 FROM b,
                      XMLTABLE(XMLNAMESPACES(DEFAULT 'http://www.ibm.com/xmlns/prod/db2/mon'), '$m/db2_activity_details' PASSING XMLPARSE(DOCUMENT b.details) AS "m" COLUMNS
                                                                                                             "activity_id" INTEGER PATH 'activity_id',
                                                                                                             "uow_id" INTEGER PATH 'uow_id',
                                                                                                             "stmt_text" VARCHAR(1024) PATH 'stmt_text') x)
  SELECT a.*, TRANSLATE(c.stmt_text, ' ', CHR(10)) stmt_text
    FROM a
         LEFT JOIN c ON a.activity_id = c.activity_id AND a.uow_id = c.uow_id
   WHERE stmt_text IS NULL OR SUBSTR(stmt_text, 1, 40) <> 'WITH a AS (SELECT a.application_handle, '
ORDER BY application_handle, a.activity_id

Posted in DB2 | Leave a comment

How to move a table to a different tablespace in DB2

Recently I had to move a table of some DB2 database to a different tablespace (building an index required a larger page size). At first, I suspected changing tablespaces to be one of those complicated operations that essentially require you to re-create the whole table. However, I was surprised to see that there is a simple admin procedure in DB2 for doing what I wanted (see ADMIN_MOVE_TABLE). For example, to move the table myschema.mytable to data tablespace mydatatablespace, index tablespace myindextablespace, and LOB tablespace mylobtablespace, just run the following SQL statement:

CALL SYSPROC.ADMIN_MOVE_TABLE('myschema', 'mytable', 'mydatatablespace', 'myindextablespace', 'mylobtblespace', NULL, NULL, NULL, NULL, NULL, 'MOVE')

Posted in DB2 | 1 Comment