Thursday, November 26, 2009

Upgrade of Firefox

After apt-get dist-upgrade I got this "Could not initialize the browser's security component. The most likely cause is problems with files in your browser's profile directory. Please check that this directory has no read/write restrictions and your hard disk is not full or close to full. It is recommended that you exit the browser and fix the problem. If you continue to use this browser session, you might see incorrect browser behavior when accessing security features."

I tried many possible solutions discovered in internet, but the only thing helped was removing of secmod.db file from my profile directory of firefox. I have no idea what this file is for, but it works. If you are having the same problem, backup your ~/.mozilla directory first before trying this or other solution which involves removing of files.

Friday, October 2, 2009

Auto-mount with halevt

halevt is good piece of software but by default it mounts disks in a way very inconvenient for me - that is mount points are like '/media/disk' '/media/disk-1/ '/media/disk-2' and so on. In order to help myself find disks more easily I've reconfigured halevt and created a script. Now I have /media/Cruzer-d4ba-1 and /media/Cruzer-a5e1-1 mountpoints for my two Sandisk USB sticks. And there are SD_Reader-a6a1-1, SD_Reader-a6a1-2, SD_Reader-a6a1-3 (three partitions) for the SD card I've inserted into a reader. A mountpoint name is composed by concatenating storage model name, short version of storage serial id and partition number. This is done by the following script (~/bin/halevt-mount-helper):
#!/bin/sh

STORAGE=`hal-get-property --udi "$1" --key block.storage_device`
PARTITION=`hal-get-property --udi "$1" --key volume.partition.number`
UUID=`hal-get-property --udi "$STORAGE" --key storage.serial | md5sum | head -c 4`
MODEL=`hal-get-property --udi "$STORAGE" --key storage.model | sed 's/ /_/g' | sed 's/^USB_//g'`

MPOINT="$MODEL-$UUID-$PARTITION"

halevt-mount -u "$1" -p "$MPOINT" -o sync -m 007
The script is used by configuring halevt with the following line instead of the default "halevt:insertion" line in halevt configuration file (/etc/halevt/halevt.xml or ~/.halevt/halevt.xml):
   <halevt:insertion exec="halevt-mount-helper $hal.udi$">

More security with ZSH

Don't save commands in history while a secure device is mounted. The mounted device must have .secure file in order to disable history file while the device mounted.

zshaddhistory() {
DIRS=`cat /proc/mounts | rgrep -P '(fuse|ext3|ext2|ext4|fat)' | cut -f2 -d' '`
FLAG=`for dir in ${=DIRS} ; do test -f "$dir/.secure" && echo secure; done`
echo $FLAG | grep secure 2>/dev/null >/dev/null && return -1 || return 0
}

Saturday, August 22, 2009

Constructor annotation in Scala 2.8.0

It was really hard for me to find any information concerning annotations on default constractor. Finally I discovered that scala accepts the following syntax:
class MyClass @Annotation() (val arg : Int) {
}

It is important that an annotation is followed by (), otherwise parameters of MyClass are parsed as parameters of annotation...

Tuesday, August 18, 2009

Richfaces & JSF 1.2

The problem with Richfaces 3.3.1 and Sun JSF RI is that an exception thrown in action listener is suppressed by Richfaces. I will show why this happens. The following stacktrace shows an order of invocations that takes place when an action listener is called:

((1)) at blah.blah.blah.ActionListenerTest.test(ActionListenerTest.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:170)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
((2)) at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:99)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:771)
at javax.faces.component.UICommand.broadcast(UICommand.java:372)
at javax.faces.component.UIData.broadcast(UIData.java:938)
((3)) at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)

I've marked interesting places with ((1)), ((2)) and ((3)). The first interesting method is ((1)) - that is where we throw an unchecked exception. The exception will be catched somewhere between ((1)) and ((2)) and wrapped into the ELException class. Then this exception will be caught in ((2)) as it can be seen here (sources are taken from Sun JSF RI 1.2.12):

public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
if (actionEvent == null) {
throw new NullPointerException();
}

try {
FacesContext context = FacesContext.getCurrentInstance();
ELContext elContext = context.getELContext();
methodExpression.invoke(elContext, new Object[] {actionEvent});
} catch (ELException ee) {
Throwable eeCause = ee.getCause();
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.log(Level.SEVERE,
"severe.event.exception_invoking_processaction"
new Object[]{
eeCause == null ? ee.getClass().getName() : eeCause.getClass().getName(),
methodExpression.getExpressionString(),
actionEvent.getComponent().getId()
});
StringWriter writer = new StringWriter(1024);
if (eeCause == null) {
ee.printStackTrace(new PrintWriter(writer));
} else {
eeCause.printStackTrace(new PrintWriter(writer));
}
LOGGER.severe(writer.toString());
}

throw eeCause == null ? new AbortProcessingException(ee.getMessage(), ee) : new AbortProcessingException(ee.getMessage(), eeCause);
}
}
When the processActio methods catches exception it logs it and wraps exception cause into the AbortProcessingException. Here we come to place ((3)) which catches AbortProcessingException. The following is the source code from RichFaces 3.3.1.GA:

public void processEvents(FacesContext context,
EventsQueue phaseEventsQueue, boolean havePhaseEvents) {
FacesEvent event;
while (havePhaseEvents) {
try {
event = (FacesEvent) phaseEventsQueue.remove();
UIComponent source = event.getComponent();
try {
source.broadcast(event);
} catch (AbortProcessingException e) {
if (_log.isErrorEnabled()) {
UIComponent component = event.getComponent();
String id = null != component ? component
.getClientId(context) : "";
_log.error(
"Error processing faces event for the component "
+ id, e);
}
}
} catch (NoSuchElementException e) {
havePhaseEvents = false;
}
}
}
As you can see processEvents catches AbortProcessingException, logs it and does nothing! That is it!

I've tried a lot of solutions to solve this, I've tried to solve it with servlets/filters/phase-listeners/action-listeners and so on with no luck! Then I've solved it with last resort - AspectJ. The following aspect does the job perfectly:

@Aspect
public class RichfacesErrorIntercepterAspect {
@Around("call(* javax.faces.component.UIComponent.broadcast(..)) && within (org.ajax4jsf.component.AjaxViewRoot)")

public void callToBroadcast (final ProceedingJoinPoint thisJoinPoint) throws Throwable
{
try {
thisJoinPoint.proceed ();
} catch (final AbortProcessingException e) {
throw new RuntimeException ("Exception in action listener: " + e.getMessage (), e.getCause ());
}
}
}
To weave Richfaces's jar I've used the maven (I use it to build the project anyway):

<plugin>
<groupId>org.codehaus.mojo</groupId>

<artifactId>aspectj-maven-plugin</artifactId>

<configuration>
<complianceLevel>1.5</complianceLevel>
<weaveDependencies>
<weaveDependency>
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-impl</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>

<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>

Sunday, August 2, 2009

Richfaces or Trinidad with Facelets

I upgraded existing project from Java 1.4 to Java 1.5, JSF 1.1 to JSF 1.2, myfaces to sun ri... and decided to leverage a framework providing AJAX for JSF. The first I tried was richfaces. But it worked unstable and I spent 2 days trying to find a reason for it. Then I tried to use trinidad. It was the same. The framework worked but very unstable. For example. I opened a jsf page, if I clicked on a ajaxfied button just immediately after page appeared, then button worked OK. But if I clicked on the button after a while, then the button didn't work, the relevant page part was not updated! It looked like a magick in work. Then I noticed a very strange message which I noticed long time ago but didn't pay any attention to it. The message was "INFO: Facelet[/page/blah.xhtml] was modified @ 14:23:24 AM, flushing component applied...". A quick investigation revealed a root of my problem! It turned out that time in a virtual machine I used as a place for application server was 3 hours less then current time! And so file creation time of files in WAR-file was greater than time in the virtual machine. It looked like facelets framework had some strange algorithm based on current time to reload modified files (and flush components tree). Having set facelets.REFRESH_PERIOD context parameter in web.xml I solved the problem. Both richfaces and trinidad worked fine after that.

Monday, July 6, 2009

Simple DSL in Scala

Recently I started to use Scala for my hobby-project.I had heard that Scala made it possible to write a code in a way that it looked like a DSL embedded inthe Scala language itself. So I decided to try this feature myself. I needed some concise and convenient API to schedule messages for actors. The following is what I ended up with:

final class TimeSpec[T] (number : Long, action : Long => T) {
def nanoseconds = action (number)
def microseconds = action (number * 1000L)
def miliseconds = action (number * 1000L * 1000L)
def seconds = action (number * 1000L * 1000L * 1000L)
def minutes = action (number * 1000L * 1000L * 1000L * 60L)
def hours = action (number * 1000L * 1000L * 1000L * 60L * 60L)
def days = action (number * 1000L * 1000L * 1000L * 60L * 60L * 24L)
}

final class Trigger (actor : MyActor, payload : Any) {
def in (number : Long) = new TimeSpec[Unit] (number, scheduleIn)
def every (number : Long) = new TimeSpec[Unit] (number, scheduleEvery)

private def scheduleIn (nanos : Long) = Scheduler.inNano (actor, payload, nanos)
private def scheduleEvery (nanos : Long) = Scheduler.everyNano (actor, payload, nanos)
}

final class ActorSchedule (actor : MyActor) {
def payload (payload : Any) = new Trigger (actor, payload)
}

trait MyActor ..... {
protected val schedule = new ActorSchedule (this)
....
}


This code made it possible to schedule messages in a natural way, like:

object TestActor extends MyActor {
schedule payload `Hi in 10 nanoseconds

schedule payload `HowAreYou every 5 seconds

schedule payload `Bye in 5 days

def act () = {
case `Hi => println ("Hello!")
case `HowAreYou => println ("I am fine")
case `Bye => println ("Bye-bye")
}
}

The idea is that schedule is an object of class ActorSchedule. This class has method payload which takes a payload object as its argument. So "schedule payload `Hi" is actually an invocation "schedule.payload(`Hi)". This invocation will create an object of class Trigger. Trigger class has two public methods - in(Long) and every(Long). Because we cannot do anything until a time unit is given, we create an object of TimeSpec class passing to it a method (scheduleIn or scheduleEvery) that is to be run with number of nanoseconds when one of TimeSpec's methods is called. I think this API is concise enough with only small efforts taken to implement it.

Sunday, March 22, 2009

CeBootLin - Linux autoloader for WinCE on Loox 5XX (560/550)

Here is the "bootloader" for wince to boot linux automatically on startup of PDA. It is not real bootloader because it has nothing to do with boot sectors, it is just a wince program which is able to boot linux as soon as possible. I have implemented it in this way because I didn't want to brick my PDA meddling with boot sectors or something. Also I wanted to have a way to skip loading of linux and let wince load itself. So here we are. It works. The code is based on haret (thanks guys!) but I cut off the parts I not used. Because the laoder uses hardware registers (GPIO/CPLD for leds and keybaord) of Fujitsu Siemens Loox N560/C550, it will not work for other PDAs. When CeBootLin is installed and PDA is turned on, wince begins boot process loading applications defined under the HKEY_LOCAL_MACHINE\init registery key. This way it loads CeBootLin. CeBootLin waits for 1 second, blinking with keyboard led. During the keyboard blinking, user can press any button to stop CeBootLin from loading Linux. If no button has been pressed during keyboard blinking, CeBootLin will search for \CeBootLin\default.txt and use this haret script to load Linux.

So, in essence, you should complete the following steps in order to install CeBootLin:
1. Download CeBootLin.
2. Unpack the downloaded archive into the PDA root. The CeBootLin.exe must be reachable with the path \CeBootLin\CeBootLin.exe.
3. Place default.txt under the \CeBootLin directory. The default txt might looks like this (if the Andorid is what you are going to load with CeBootLin):

set MTYPE 1454
set KERNEL "\CeBootLin\zImage"
set CMDLINE "root=179:3 mem=62M rootdelay=3 boot_delay=0 init=/init console=tty0 fbcon=rotate:0 androidboot.console=tty0 android.checkjni=1"
set RAMADDR 0xA0200000
bootlinux

4. Place zImage under the directory \CeBootLin\.

5. Modify HKEY_LOCAL_MACHINE\init adding Launch82 ="CeBootLin.exe" and Depend82 = 14 00.


6. Modify HKEY_LOCAL_MACHINE\Loader\SystemPath adding a new directory \CeBootLin\ to the multi-string list.

7. Wait for 5 minutes (WinCE needs time to persist changes to registry).
8. Feel free to reboot your PDA

To test that CeBootLin is able to boot linux at all, run CeBootLin.exe manually.

It looks little bit complicated but later, setup program might be created to ship automatically bootable Andorid on Loox550. But before, Andorid must be polished.

Here is the source code of CeBootLinux. CeBootLinux is licensed with GNU GPL.

Sunday, March 15, 2009

Pictures of Linux and Android on Fujitsu-Siemens Loox N560


Today the desteny of WM5 is only to be replaced with Linux


Haret.. all you need is to press Run


Android on Loox N560


Installation of debian on Loox N560


Installation of debian on Loox N560

Memory tester for Loox N560/C550

Recently I've created a way to test memory for defects on Fujitsu-Siemens Loox N560/C550. Only one who upgraded (or wants to upgrade) PDA's memory from 64M to 128M needs this utility. Using this "util" it is possible to test memory immediately right after memory has been upgraded, without re-flushing WM5/WM6.

So do the following to test your PDA's memory:
1. Download either LooxMem128-v0.zip (to test 128Mb of memory) or LooxMem64-v0.zip (to test 64Mb of memory).
2. Unpack the downloaded archive onto SD.
3. Insert SD into your Loox and reboot it.
4. Don't let PDA fall asleep, start haret.exe which is in the directory where unpacked the archive to.
5. When haret.exe is started press Run.
6. Read the caution when Linux is booted.
7. Make up your mind and then either press RESET (insert a stylus into a hole on the bottom side of the PDA, if you don't want to test memory) or press enter..
WARNING: Poor memory chips might be damaged during the test (that is why you want to test your PDA's memory, isn't it?). None will be responsible for your actions except yourself!!

Note: You have to press any button during the testing process once per 5 or so minutes.
(In a case you need to port the utility on the other platform (not Loox C550/N560) the only thing you have to do is to replace zImage and modify default.txt to let the linux for your platform boot on the target device).)

Saturday, March 14, 2009

Linux Kernel for Fujitsu-Siemens Loox N560/C550 with support for CPLD and builtin leds

I've implemented support for CPLD and leds. htc-gpio driver is used with a custom list of CPLD registers/resources for Fujitsu-Siemens Loox 5XX (N560/C550). Now CPLD interface is available for all other drivers (existing and planned) of the linux/android kernel.

It is interesting how CPLD is implemented in the linux kernel. Actually CPLD is a chip that supports very simple custom logic (and that is the reason why it is much faster than CPU). CPLD chip has a set of input pins and output pins. All these pins are mapped to a region of memory address space. The most important work with CPLD is that modifying values of pins to control devices. This is done setting a value to 0 or 1. In fact, programming of GPIO (general purpose input/output of CPU) is done in the same way: a programmer writes code that sets a GPIO pin to either 0 or 1. Linux kernel already has support for GPIO which provides a set of functions for platform drivers. In addition, GPIO driver provides a way to map any virtual GPIO pin to some custom code that is responsible for handling of setters and getters for the mapped pins. And indeed, that is how htc-egpio driver does the job. The driver leverages gpiolib mapping CPLD registers to GPIO pins. Thanks to this approach, no addition functions are required to work with CPLD. It is enough to use gpio_set_value/.. methods.
After the CPLD driver had been implemented, it was possible to implement a driver for the leds of Loox N560/C550. The leds driver, I implemented, exports a set of functions that other drivers (wifi, gps, bluetooth, pm, ...) are supposed to use to control the leds. Also, the leds driver makes it possible to control the leds from userspace (shell scripts, java program, ...) using files under sysfs filesystem.

The following is the list of files exported by the leds driver and the possible content values for the each file:
/sys/devices/platform/loox5xx-leds.1/keyboard: on, off, any
- backlight for keyboard

/sys/devices/platform/loox5xx-leds.1/left_green: on, off, any
- green led on the left side. WM5 indicates WiFi activity with this led

/sys/devices/platform/loox5xx-leds.1/left_blue: on, off, any
- blue led on the left side. WM5 indicates Bluetooth activity with this led

/sys/devices/platform/loox5xx-leds.1/left_orange: on, off, any
- orange led on the left side. WM5 indicates GPS activity with this led on Loox N560

/sys/devices/platform/loox5xx-leds.1/right_green: on, off, any
- green led on the right side. WM5 allows programs to control this led using winapi.

/sys/devices/platform/loox5xx-leds.1/right_orange: on, off, blink, any
- orange led on the left side. WM5 indicates charging activity with this led

Where:
on - the led is on regardless of the kernel activity,
off - the led is off regardless of the kernel activity,
blink - the led is blinking regardless of the kernel activity,
any - the led is controlled by the kernel.

For instance, if the content of the right_orange file is set to 'on', then the orange led (on right side of PDA) will be on no matter what you do: plug or unplug your device to/from a cradle. The driver will hold on the state of the led until, you write 'any' into the file right_orange. With 'any' value in file, the first 'power' event will change state of the led. The interface of the driver makes it possible to implement any notification (low battery, new mail..) effects you can imagine involving all leds of the device. The following script demonstrates how to blink with the keyboard backlight led:

while true;
do echo on > /sys/devices/platform/loox5xx-leds.1/keyboard;
sleep 0.1;
echo off > /sys/devices/platform/loox5xx-leds.1/keyboard;
sleep 0.1;
# Condition for break...
done
echo any > /sys/devices/platform/loox5xx-leds.1/keyboard;

The current patch for the android cupcake kernel is located here.

Tuesday, March 10, 2009

Cross-Packaging On Debian

Debian/Emdebian already has tons of packages. But sometimes you have a need to package or repackage a piece of software yourself. The following may be helpful if a platform you build for is not the platform you build on.

Use the following command to build a package from a repository of apt:
emsource --arch armel -b memtester

If you need to install a package for target on your host:

dpkg-cross -a armel -i zlib1g-dev_1.2.3.3.dfsg-13em1_armel.deb
The command dpkg -l | grep zlib1g will show you:

ii zlib1g-dev-armel-cross 1:1.2.3.3.dfsg-13em1

(dpkg-cross automatically converts package names and moves content under the /usr/arm-linux-gnueabi (for armel target))

You need to configure ~/.apt-cross/emsource to use emsource without privileges of root. The content of the file may look like:

workingdir: /home/akshaal/.apt-cross-working-dir

In a case you need to build a package from sources that have already been downloaded, use the following command:

dpkg-buildpackage -aarmel

Sunday, March 8, 2009

Install emdebian on ARM device

Here is how I've successfully installed emdebian on my Fujitsu-Siemens Loox N560. I assume there is an already installed emdebian-tools package and cross-compilers. Next thing is to run the following commands:
cd /tmp;
mkdir grip/
sudo debootstrap --arch=arm --foreign lenny grip/ http://www.emdebian.org/grip/
cd grip/
sudo tar -czf /tmp/emdebian-grip-arm-debootstrap.tgz .

Then SD card is to be partitioned with fdisk. For example it could be:

cfdisk /dev/sdX
mkfs.ext3 /dev/sdXy

where sdX - is a device for an SD card. And sdXy is a partition that is supposed to be used for linux on the SD card. Then mount the linux partition and untar the emdebian-grip-arm-debootstrap.tgz:

mount /dev/sdXy /mnt
cd /mnt
tar zxpvf /tmp/emdebian-grip-arm-debootstrap.tgz
ln -s bin/sh init
cd /tmp
umount /mnt

Now we can boot linux from the partition. When linux has booted and a command line appeared, run the following commands step by step:
cd /debootstrap
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
run ./debootstrap --second-stage
dpkg --configure -a
rm /init
cd /
ln -s sbin/init init

Now it is time to reboot linux again. This time a login prompt should work. Use root login and no password. Then configure basic settings:

echo 'nameserver 1.1.1.1' > /etc/resolv.conf
echo '127.0.0.1 localhost' > /etc/hosts
echo '172.16.0.2 myhost 172.16.0.2' >> /etc/hosts
echo 'myhost' > /etc/hostname

use actual nameserver IP instead of 1.1.1.1. Reboot PDA one more time. Then configure network:

ifconfig usb0 172.16.0.1 netmask 255.255.255.0
route add default gw 172.16.0.1
Make sure network is up and running. Then upgrade your installation:

echo 'deb http://www.emdebian.org/grip/ sid main' > /etc/apt/sources.list
apt-get update
apt-get dist-upgrade
apt-get install ...whateveryoulike...

And configure network properly.
cat > /etc/network/interfaces
auto lo
iface lo inet loopback
allow-hotplug usb0
iface usb0 inet static
address 172.16.0.2
netmask 255.255.255.0
network 127.16.0.0
broadcast 172.16.0.255
gateway 172.16.0.1
dns-nameservers 1.1.1.1
dns-search your.domain

Linux Kernel for Fujitsu-Siemens Loox N560/C550 with usbnet working

After 3 days of struggle I am finally able to build a linux kernel for my PDA Fujitsu-Siemens Loox N560. The kernel has been downloaded from http://www.asm32.ru and patched (pxa27x_udc.c) to support for usbnet (host-to-PDA networking through a usb coard). Also I've made a diff file with differences between the current cupcake kernel and the kernel (by date 02-mar-2009) from asm32.ru site. That will be useful later when I need to apply support for Loox to a new upstream cupcake kernel. Here is the patch which also includes support for usbnet on Loox C550/N560. The patch already contains a kernel configuration file (.config), but usbnet support is not enabled there. Here is the other .config file which is differ from that included in the patch by supporting usbnet, having power management switched off and configuration for larger fonts in console.

It is possible to build the kernel with any toolchain for arm of your choice. I've tried crosstool-ng, emdebian and the one that is included in the android repo. I have decided to leverage emdebian toolchain for I use debian on my PC. The following is the command to build the kernel using emdebian toolchain:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
Of course you have to have emdebian toolchain installed. You can install emdebian something like it is shown below:

apt-get install emdebian-tool
emsetup --arch arm
Then add:

deb http://www.emdebian.org/debian/ unstable main

into your /etc/apt/sources.list and run:
apt-get install linux-kernel-headers-arm-cross gcc-4.2-arm-linux-gnu

When the kernel is built and ready you can copy it on an SD card and run it with haret with the following default.txt:

set MTYPE 1454
set KERNEL zImage
set CMDLINE "root=179:2 mem=60M rootdelay=3 boot_delay=0 init=/init console=tty0 fbcon=rotate:0 androidboot.console=tty0 android.checkjni=1"
set RAMADDR 0xA0200000
bootlinux
That is important! When you've placed zImage on an SD card, you will insert the card in your PDA. And then you must reboot your PDA! And only after you have rebooted your PDA with the SD card inside, you should ask haret to boot linux. That is very important because a linux kernel will not be loaded correctly (or it will but with only 10% chances) if one of the following conditions is true:
1. PDA has fallen asleep or suspended.
2. You have just inserted an SD card in your PDA and not rebooted it yet.
It looks like it is a bug in wince...

P.S. There you can download cupcake kernel http://source.android.com/download

P.P.S. When you build kernel with usbnet, don't set CONFIG_USB_ETH_RNDIS to 'y'! Or your PC kernel (2.6.x) will not find your PDA... neither cdc_ether nor cdc_subset will claim your PDA.

Friday, March 6, 2009

Async Related Posts Widget

I have finally implemented a feature I wanted to have on my blog. It is Related Posts Widget, but not just Yet Another Related Posts Widget. It differs form all other widgets that show related posts. It has features that no other widget has (yet at least):
1. It sorts related posts not only by date, but by relevance!
2. It is small. It is fast. It is asynchronous!. It is just AJAX :).
3. It is easy to install. It is very crucial point for me because I maintain a bunch of blogs and I don't want to waste my time doing coplicated setups for each blog over and over again.

So, lets install the widget in a blog. The installation process constists of two simple modifications to the blog HTML Template. Go to Settings -> Layout -> HTML Template. But Before you start doing any modification, make a backup of your template (Download full template)! Now you are ready. The option Expend Widget Templates should be checked. Then follow the steps below:
1. Find string <data:post.body/> in your template code. Right after(!) this string, insert the snipped below:
<div caption='Related posts:' id='akRelatedPosts' max='8'/>
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<script language='javascript' type='text/javascript'>
(function(_1,_2){var _3={};var _4=_2.length;var _5=function(_6){var _7=&quot;([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?&quot;;var d=_6.match(new RegExp(_7));var _9=0;var _a=new Date(d[1],0,1);if(d[3]){_a.setMonth(d[3]-1)}if(d[5]){_a.setDate(d[5])}if(d[7]){_a.setHours(d[7])}if(d[8]){_a.setMinutes(d[8])}if(d[10]){_a.setSeconds(d[10])}if(d[12]){_a.setMilliseconds(Number(&quot;0.&quot;+d[12])*1000)}if(d[14]){_9=(Number(d[16])*60)+Number(d[17]);_9*=((d[15]==&quot;-&quot;)?1:-1)}_9-=_a.getTimezoneOffset();time=(Number(_a)+(_9*60*1000));return Number(time)};var _b=function(){var _c=[];for(var i in _3){_c.push(_3[i])}if(_c.length&lt;1){return}var _e=document.getElementById(&quot;akRelatedPosts&quot;);if(!_e){return}var _f=_e.getAttribute(&quot;max&quot;)||5;_c=_c.sort(function(a,b){var _12=b.weight-a.weight;if(_12!=0){return _12}return b.date-a.date});var s=&quot;&lt;ul&gt;&quot;;for(var i in _c){if(_f--&lt;1){break}var _14=_c[i];s+=&quot;&lt;li&gt;&lt;a href=&#39;&quot;+_14.href+&quot;&#39;&gt;&quot;+_14.title+&quot;&lt;/a&gt;&lt;/li&gt;&quot;}s+=&quot;&lt;/ul&gt;&quot;;var _15=_e.getAttribute(&quot;caption&quot;);s=&quot;&lt;span class=&#39;caption&#39;&gt;&quot;+_15+&quot;&lt;/span&gt;&quot;+s;_e.innerHTML=s};var _16=function(_17){for(var i in _17.feed.entry){var _19=_17.feed.entry[i];var _1a=_19.id[&quot;$t&quot;];var _1b=_3[_1a];if(_1b){_1b.weight++}else{var _1c;for(var _1d in _19.link){if(_19.link[_1d].rel==&quot;alternate&quot;){_1c=_19.link[_1d].href;break}}if(_1c==_1){continue}_1b={weight:1,title:_19.title[&quot;$t&quot;],date:_5(_19.published[&quot;$t&quot;]),href:_1c};_3[_1a]=_1b}}if(--_4==0){_b()}};var _1e=function(_1f){var _20;try{_20=new XMLHttpRequest()}catch(excp1){try{_20=new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;)}catch(excp2){try{_20=new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;)}catch(excp3){_20=false}}}var _21=function(){if(_20.readyState==4){if(_20.status==200){_16(eval(&quot;(&quot;+_20.responseText+&quot;)&quot;))}}};_20.open(&quot;GET&quot;,_1f,true);_20.onreadystatechange=_21;_20.send(null)};for(var _22 in _2){_1e(_2[_22])}} <!-- = = = = = endoffunc = = = = = = -->
)(&quot;<data:blog.url/>&quot;,[
<b:loop values='data:post.labels' var='label'>
&quot;/feeds/posts/default/-/<data:label.name/>?alt=json&amp;max-results=5&quot;<b:if cond='data:label.isLast != &quot;true&quot;'>,</b:if>
</b:loop>
]);
</script>
</b:if>
You should end up with something like this (click on the picture to open a full-size version):
Pay attention to caption='...' and max='8' You may consider to edit these values. A value for caption defines text to be shown above a list of related posts. And max defines a number of displayed relevant posts.
2. This step is optional. Everything should start working without it, but the widget will not be nice-looking. That is why you may want to complete it. So find the string ]]></b:skin>. And insert the following css snippet before(!) the string:
#akRelatedPosts {
padding-top: 20px;
}

#akRelatedPosts .caption {
font-weight: bold;
}

#akRelatedPosts ul {
margin: 0;
}
If you think you have knowledge of css, you can tweak the styles below as you like. Finally you should see a picture like the following (click on picture to see full-size version):
That is all. You can save your template and check your posts.

Thursday, March 5, 2009

Cross-site request

It is handy to test javascript snippets without uploading them on a production server. But it is hard to test AJAX request like that. The reason for it is that firefox doesn't allow a cross-site request for a sake of user's security.
uncaught exception: Access to restricted URI denied (NS_ERROR_DOM_BAD_URI)
But if you know what you are doing you can temporarley switch this behavior off. Open about:config page and set signed.applets.codebase_principal_support to true. Also your script must have the following line executed before any cross-site request:
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
And don't forget to set signed.applets.codebase_principal_support to false value back and remove the line above from script when you have done with testing!!

Saturday, February 28, 2009

Remove Solid Border

If you want to crop a picture stripping it from a border of some solid color, in linux you can use convert command which is a part of ImageMagick package:

convert original.jpg -trim modified.jpg

In a case you have a set of pictures, use find command to execute convert:
find *.jpg -exec convert {} -trim out/{} \;

Where out is a directory for converted images.

Monday, February 23, 2009

Extract Config from zImage

It was hard for me to find this simple thing in internet, so I gonna make life for someone a little bit easier.

If you want to extract config file from existing linux image, zImage or bzImage, do the following:
  • Download archive file with linux sources.
  • Unpack linux kernel sources
  • Go into root directory of the kernel sources
  • Run chmod 755 ./scripts/extract-ikconfig
  • Run ./scripts/extract-ikconfig /tmp/zImage > /tmp/config
Where /tmp/zImage is a file you want to extract a config from. And /tmp/config it is a filename for the extracted config.

Sunday, February 22, 2009

Top Delusions About Google Sites

As far as I can see from forums, the most common delusion about Google Sites are:
1. Google Sites doesn't support custom domains. This is not true. Google Sites supports custom domains. You can map any part of google site to any domain.
2. Google Sites gives you absolute freedom to populate your site with legal content. This is not true. For example you are not allowed to use adsense units on your Google Site.

Saturday, February 21, 2009

Google Blogger & AdSense

Blogspot had build-in way to insert AdSense ads in blog. But for some reasons it was not enough for me. For instance, I wanted to leverage channels feature of Google AdSense, but it was impossible with build-in AdSense widget. On the other hand, Google Blogger made it possible to edit a blog template, even insert arbitrary Javascript code. So I decided to go this way to insert my custom adsense code. It seemed to be simple to do, but I wasted 3 hours of my time trying to make it work. For these 3 hours I had been trying to understand why a code generated by AdSense and inserted into HTML Template of my blog didn't work. Instead of any advertisement I saw empty space where an advertisement should be. And even empty space was of wrong size (not the size I chose for the unit). An investigation revealed some details. With a help of firebug I discovered that browser sent a request to http://googleads.g.doubleclick.net and got response 400 Bad Request. Why request was baaaaad, adsense server didn't bother to tell. I compared behavior of an adsense unit that was working and behavior of the non-working unit. I noticed that the non-working unit didn't provide a client id and other info to the AdSense server in request, there values were undefined. The reason for the response 400 was clear now. I suspected that problem could be in javascript code generated by AdSense. The code looked like this:
<script type="text/javascript"><!--
[... something like var blah=blah-blah-blah; ...]
//-->
</script>

Although there was nothing wrong with this code, I considered to remove <!-- and //--> chunks. The chunks I removed were there just to support old browsers or browsers without javascript turned on. And it helped! Everything went fine. But AdSense prohibited any modifications to generated code. And then I suspected a problem with HTML Template itself, not with AdSense code. I rewrote code to make it look like this:
<script type="text/javascript">&lt;!--
[... something like var blah=blah-blah-blah; ...]
//--&gt;
</script>

And that worked as well!

There is a possible reason for this. It looks like BlogSpot engine parses template to some internal structure. And then, from this internal structure (DOM tree) it generates HTML code. And the problem is that it doesn't preserve new line characters inside a comments <!-- -->. A browser cuts off this comment before javascript engine begins it work.

Wednesday, February 18, 2009

LooxLight 2007-11-19

I don't know why I didn't write anything about the new version one year ago. But here I am going fix this mistake.

LooxLight is a tool for PDA Fujitsu Siemens C550/N560 (click here to find more information).

In version 2007-11-19 I added a new feature. It was ability to block (turn it off) the device's screen. Before I implemented this feature, I had used wossname program to turn PDA's screen off. But this wossname program had been buggy. So I had decided to implement the same feature in my LooxLight app but make it less buggy. And I implemented it. It allowed me to turn off the screen and block keyboard (including suspend button, that was what no other program could do!). It appeared that with screen turned off, the PDA consumed up to 50mA less battery power. This helped to prolong time I could enjoy music/audiobooks.

Here is the cab file with LooxLight 2007-11-19. Remember that it is for Fujitsu-Siemens Loox C550/N560 and maybe for 720, but I can't give you any guarantee.

How to use. After you have installed LooxLight 2007-11-19, run LooxLight Control and check "Permit blocking" option. Then setup up "Unblock by" keys. Remember, when your PDA is blocked, you will have to press these buttons one after another in order to unblock the PDA. By default these buttons are button 2 and button 4. Then, go to Settings/Button assign "LooxLight Block" to a button that will be used to block PDA. That is it, the configuration is over. Enjoy new feature.

New versions and latest news about LooxLight will be published right here.
Another project helps reduce power consumption on Fujitsu-Siemens Loox N560/C550.

Tuesday, February 17, 2009

text & jdbc & sybase

If you see the following error: "A wrong datastream has been sent to the server. The server was expecting token 236 but got the token 33. This is an internal error."

Then it means that you haven't sepcified the correct jdbc type for a column. If you use iBatis, the proper insert statement should look something like:

<insert>
INSERT INTO users (login_name, description)
VALUES (#loginName#, #description:LONGVARCHAR#)
</insert>