Category: programming

  • Java tips&tricks

    A couple of quick/short Java tips: The Collections.unmodifiable* just wrap the original object in a facade class which throws UnsupportedOperationException when you invoke operations that would modify it (like add or remove), but the original collection still remains mutable (and the mutations are reflected in facade object). This might be obvious to some, but not…

  • Quirky Perl tricks

    Perl is like a sharp knife: you can do a lot of things with it easily (like carve wood), but you easily hurt yourself. So here are some quirky things which I discovered (credit goes to my friends who came to me with these issues and helped me to grow my knowledge by researching the…

  • Is Java slower than C? (and does it matter?)

    Via daniel’s blog (the creator of curl) I arrived to this page: why the Java implementation (JGit) doesn’t run nearly as fast as the C implementation. The short version of it is: even after many tunings JGit is twice as slow as the C implementation. One of the problems which got my attention, was the…

  • Weird Sybase JDBC driver issue (jConnect)

    I post this so that the search engines can pick up on it and maybe it can help somebody out. I had the following issue with the Sybase JDBC driver (jConnect): I was calling a stored procedure and it was throwing an error. However these errors weren’t propagated to the Java code in form of…

  • Hackish method to include custom content into CruiseControl

    Disclaimer: I’m a CruiseControl newbie, so there might well be a much better / simpler / cleaner method to achieve this. However this is the way I managed to get it working. Write your (Perl) script and make it output something like this: <testsuite tests="0" name="summary" failures="0"><system-out> foo bar </system-out></testsuite> Make your script run during…

  • Compiling software for OpenWrt (and creating packages)

    From my experience, compiling software is not especially hard, but most of the tutorials out there are somewhat dated (as this one will be in 6-7 months). But at least until then it can be useful, and hopefully I will find the time to update it later on. I’m using the trunk version of OpenWrt,…

  • Small programming tips

    A quickpost inspired by issues I encountered recently. How to concatenate (aggregate) strings with PostgreSQL? In MySQL you can write: SELECT concat(name) FROM test_table Because concat also works as an aggregate function (like MIN, MAX, SUM, COUNT, etc). To get the equivalent result in PostgreSQL, you can use the following query (based on ideas from…

  • Alternative regular expression syntax

    For a long time I was a believer in the “Perl way” of doing regular expressions and an avid reader of perlre. All other implementations I viewed as a “poor man’s copy” of the one true idea. However, after reading the Lua Patterns Tutorial, I found it quite enlightening. Even though it is called “patterns”…

  • Function references in Perl

    A friend asked me how to do the following: use strict; use warnings; use File::Copy ‘move’; my $op = $condition ? &move : &link; # … $op->($a, $b); So, I tried to get it working, but I kept getting the error: Undefined subroutine &main::link called at linkme.pl line 2. For move it worked fine. Finally,…

  • Repetitive testcases with jUnit

    Update: after listening to a recent episode of Java Posse, I found out about parameterized tests for JUnit which seems to be a better option than the method described below. Live and learn. Let’s say you have a lot of similar cases in a jUnit test. You might be tempted to write a loop to…