Sunday, August 5, 2007

SpringMeasure 1.0

I don't understand how I've ever been without Spring framework. It is so tasty. I will use it whenever I can. Do you think a step from EJB 2.1 to EJB 3.0 is a revolution? Then step from EJB 3.0 to Spring 2.0 is a revolution no less: flexible IoC, nasty testing out of box, standalone or web or whatever execution, annotations, if you prefer your app knows nothing about spring (no direct dependencies on spring classes) and so on. But that is not an issue of this post. As an example of spring ideas I am going to show you how spring can be easily extended for your needs. In my case I wanted to use measured values right in a bean property definition. I.e. instead of using a value 120013 calculated behind the scene (60*2*1000 + 13) I wanted a human suitable representation like a "2min 13ms". And to achive it I've created a small project.

Download the archive.
Uncompress it.
Do mvn install from command line inside the archive's folder.

Now you can use springmeasure as the dependency in your own project (artifactId: springmeasure, groupId: ru.toril.springmeasure, verision: 1.0).

In your application context xml add the following line:
<bean class="ru.toril.springmeasure.MeasureConfigurer" />

From now you can write following (as an example):

<bean class="some class you want"
p:value1="{${test.length}}m"
p:value2="{4GiB 200MiB}MiB"
p:value3="{400ms}s." />

The property value1 is configured with PropertyPlaceholderConfigurer in addition to MeasureConfigurer, whereas test.length property is set to "8km".

As you already noticed springmeasure is written to support symbols of Si. A format of value is as following:

{sequence of space-separated values with symbol suffix joined to value}outputSymbol

An output symbol may be followed by the dot marking that an output value is not to be rounded.
You may find out more about format looking at the following test lines:

// IT symbols (bits, bytes)
assertEquals ("2048", convert ("{2KiB}B"));
assertEquals ("16384", convert ("{2KiB}b"));
assertEquals ("11", convert ("{1B 3b}b"));
assertEquals ("10000000", convert ("{ 10MB }B"));
assertEquals ("500", convert ("{ 0.5kB }B"));
assertEquals ("2", convert (" { 2048B 100B 3b }KiB "));
assertEquals ("2.098", convert (" { 2048B 100B 3b }KiB. ").substring (0, 5));

// Time (minutes, seconds, hours, days)
assertEquals ("600", convert ("{10min}s"));
assertEquals ("615", convert ("{10min 15s}s"));
assertEquals ("615000", convert ("{10min 15s}ms"));
assertEquals ("615001000000003", convert ("{10min 15s 1ms 3ps}ps"));
assertEquals ("70", convert ("{1h 10min}min"));

// Length (meters)
assertEquals ("0.5", convert ("{5mm}cm."));
assertEquals ("2", convert ("{2000mm}m"));

// Any other Si value
assertEquals ("0.5", convert ("{5m*}c*."));
assertEquals ("2", convert ("{2000m*}*"));

Here is a real life usage examples:

<bean id="monitorTask" class="org.springframework.scheduling.timer.ScheduledTimerTask"
p:period="{30s}ms" ... />

<bean id="monitor"
class="ru.toril.....model.Monitor"
p:maxAllowedIdle="{2h}ms"
p:maxAllowedSize="{2MiB}B"
p:minFreeSize="{2GiB}B"
p:maxSleepTime="{1min}ms" ... />

Saturday, August 4, 2007

Wow

JBoss 4.2.1 uses 120M of memory running on Java 5, while only 91M on Java 6. Only what I can guess is that Java 6 leverages some new memory page allocation strategy or may be I just wrong and there is something completely different :).

Also it means I've replaced Sun Application Server 9 (based on glassfish) with jboss, becouse Sun AS has been eating twice as more memory than JBOSS 4.2.1 and I've read that Sun Portal requires 2 GB of memory to run and a lot of dependencies!

IDE

Eclipse 3.3 has won my heart. I just enjoy programming in it as I've never been enjoing in any other (jdeveloper, idea 7, eclipse 3.2).

Monday, June 4, 2007

Recent Upgrade of Debian (intel's video driver problem)

Yesterday I did apt-get dist-upgrade. ion3 as usually rejected to work properly for its API changes. I was not surprised and fixed this technically. But next, what I had noticed right after upgrade, was the large fonts in opposite to ones before upgrade. Quickly I discovered that DPI was incorrect due to a wrong display size. But it took me an enormous amout of time to fix. At first, I tried obvious DisplaySize declaration in a Monitor section of xorg.conf file, yet with no luck. Reading forums, I found one mentioning xrandr util that controls X's RandR extension that, in turn, responsible for DPI. I modified my ~/.xsession adding "xrandr --screen 0 --fbmm 300x225" as the first command. Most of the fonts became smaller, yet fonts of GTK remanined the same. And only today I found out why. I had been using GDM. GTK (GDM relied on it) loaded DPI values before an execution of ~/.xsession took place. So, I added xrandr command into /etc/gdm/Init/Default. It helped.

Next I discovered XV was not working now (no picture, just blue rectangle instead), becouse of bug in intel's driver. This bug exists in xserver-xorg-video-intel-2.0.0-1, and it has been definitely fixed in xserver-xorg-video-intel-2.0.0-3.

Saturday, May 26, 2007

LooxLight & GoodWavPower

Minor update of utilities for PDA Fujitsu Siemens C550/N560.

Here is the new LooxLight version (2007-05-26). You may try it if you are enough annoyed with this message:
Error while starting: Return status 2 of ReqQueryValueEx
for hnd indicates error
lasterror=0
lasterror=0


Here is the new GoodWavPower version (2007-05-26). Message 'GoodWavPower: error play sound' is simply disabled.

New versions and latest news about LooxLight will be published right here.
Check for GoodWavPower updates here.

Recovering of Encfs Password

Whew. I've found all forgotten passwords for encfs with a help of the perl script:


#!/usr/bin/perl

use strict;
use warnings;

# these words are used as password components
my @words = (
"example", " ", "word", "123", "666", "pwd", "part1"
);

my @l = ();

sub mindex {
my $x = shift;

for (my $i = 0; $i <= $#words; $i++) {
if ($words[$i] eq $x) {
return $i;
}
}

return -1;
};

sub inc {
my $p = shift;
my $v = $l[$p];

unless (defined $v) {
$l[$p] = $words[0];
} else {
my $i = mindex ($v);
if ($i == $#words) {
$l[$p] = $words[0];
inc ($p+1);
} else {
$l[$p] = $words[$i+1];
}
}
};

while (1) {
inc (0);
my @ll = reverse @l;
my $pwd = join '', @ll;

open F, ">/tmp/1233";
print F "pwd\n";
close F;

print "$pwd\n";
system "encfs -S /tmp/encfsdir /tmp/mountpoint < /tmp/1233";
}


You may use it if you still know a vague shape of password you have lost.

Friday, May 18, 2007

Combinations

It seems to be simple, but it took me two hours to write this function. And now I know the true nature of things!
combr :: [[a]] -> [[a]]
combr [l] = map (\x -> [x]) l
combr (l : tl) = concat $ map (\ll -> map (:ll) l) $ combr tl

print $ combr [[1,2], [3,4], [5,6,7]]

[[1,3,5],[2,3,5],[1,4,5],[2,4,5],[1,3,6],[2,3,6],[1,4,6],
[2,4,6],[1,3,7],[2,3,7],[1,4,7],[2,4,7]]