21 November 2010

How to restore Linux loader after installing Windows without Live-CD

Often having both Linux and Windows installed on the same PC I face trouble when after reinstalling Windows my Linux loader (GRUB\LILO\whatever) got erased with nasty one from M$. Before I always had to look up some live-CD distro to boot and restore GRUB. Today I was too lazy to do that - I had no suitable CD (or maybe it's time to throw away my CD drive) and after a quick look through the web I've found GRUB4DOS. So what magic does it provide? Here is the trick - GRUB4DOS allows you to install it from withing your running Windows instance, it boots up a GRUB-like stuff where you can select another partition to boot from. Basically you then boot to your broken GRUB record, then boot up your Linux distro and then having complete environment you just restore your broken GRUB MBR record. Easy, ha! To install the GRUB4DOS we don't even need to perform any dangerous manipulations with MBR. You just download grub4dos or grubinst package from http://sourceforge.net/projects/grub4dos/files/, copy grbldr from the package to your system drive root (e.g. C:\grbldr) and add following line to boot.ini:
Now you just need to reboot the PC, boot your Linux distro and reinstall GRUB On my ArchLinux I did the following:
$ sudo grub-install --root-directory=/ \(hd0\)
This installed GRUB to the MBR of my first hard drive and put staging files under /boot/grub directory.

17 September 2010

Partial fix for tomcat hot redeploy

Adding the following to CATALINA_OPTS makes tomcat survive across much more redeploy iterations then by default :)
-Xmx1024m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m

29 June 2010

Setting a single locale for GWT application

One library used to output messages in German when locale was not set explicitly (<extend-property name="locale" values="en"/>). After we add an English locale to GWT module compilation began to take twice more time than in was before and the count of compilation permutations grew twice time too. It appeared that we cannot just user . Compilation was just failing with that. After googling a bit I've found a strange example which was promised to work. And it did worked! :) So, here it is:
<extend-property name='locale' values='en'/>
<set-property-fallback name='locale' value='en'/>
<set-property name='locale' value='en'/>
Though it looks like a hack (and in fact it really is), but it do work! Now our project has single English locale and compiles in 6 permutations.

08 May 2010

Using D-Bus to shutdown the machine

I don't know why I don't like using /sbin/shutdown to switch off the computer :) But that is the fact! I am not using Gnome\KDE\XFCE\whatever_else_complete_DE. I'm running Archlinux with Openbox and several tools. So I wanted to allow non-privileged user to be able to shutdown the computer by a single click. Firstly I had to find out, what should I send over D-Bus (and whom to) to make my PC shutdown. Crawling the web I found an utility which allowed me to find what I needed in a few minutes. It's called DBus-Inspector. So having a message and destination it just remained to send it using dbus-send:
$ dbus-send --system --print-reply --dest=org.freedesktop.Hal \
          /org/freedesktop/Hal/devices/computer \
If you will try to execute it, you may receive and error saying that you don't have permissions to send messages to org.freedesktop.Hal.devices.computer interface. If you did, you should open hal.conf from system config directory of D-Bus (mine is /etc/dbus-1/system.d/hal.conf) and add the following policy:
 <policy group="shutdown">
   <allow send_destination="org.freedesktop.Hal"
Now all the members of group shutdown will be able to switch off the computer by D-Bus. You just have to create the group:
# groupadd shutdown
And add your user to this group:
# gpasswd -a user shutdown
Finally you may want to create a script or desktop entry:
[Desktop Entry]
Exec=dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown

12 April 2010

Google maps: getMaxZoomAtLatLng and error 500

When I had to catch zoom level when 'no images available for this zoom level', I thought I had pretty quickly found the solution. But I was completely disappointed when this one didn't work. After some research I've managed to make it work :) First of all I needed this in GWT application. We were using GWT Maps (1.0.4 by that time) which lack this function as such. So here is how we can bridge this function using JSNI:
class GoogleMapsJsBridgeSample {
     * Wrapper function to native call
    public void getMaxZoomAtLatLng(MapType mapType, double lat, double lon) {
        getMaxZoomAtLatLng(mapType.getPeer(), lat, lon);
    private native void getMaxZoomAtLatLng(JavaScriptObject mapTypePeer, double lat, double lon) /*-{
        var latLng = new $wnd.GLatLng(lat, lon);
        mapTypePeer.getMaxZoomAtLatLng(latLng, function(response) {
            if (response && response['status'] == $wnd.G_GEO_SUCCESS) {
    private void doSomethingWithMaxZoomAtLatLng(int maxZoom) {

The point here is is NOT using MapWidget.getCurrentMapType() due a bug in gmaps-api (not GWT specific). According to the comments for the issue, problem appears only for hybrid map type, but for satellite and normal it is ok! So you can use to code above in the following manner in GWT:

GoogleMapsJsBridgeSample jsBridge = new GoogleMapsJsBridgeSample();
// ...
jsBridge.getMaxZoomAtLatLng(MapType.getSatelliteMap(), lat, lon);
// or use MapType.getNormalMap() for street map view

Such issues are sometimes specific to the version of gmaps-api you are using. You can always make sure what particular version is used in your application by outputting G_API_VERSION JavaScript variable.

Changelogs for each gmaps-api version are available at http://mapki.com/

17 March 2010

Eclipse to IntelliJ IDEA keymap migration cheatsheet

EclipseIntelliJ IDEAAction
Ctrl+OCtrl+F12Go to member popup
Eclipse: outline current source
IDEA: file structure popup
Ctrl+Shift+TCtrl+NOpen class by name
Eclipse: Open Type
IDEA: Go to - Class...
Ctrl+Shift+RCtrl+Shift+NOpen file by name
Eclipse: Jump to file
IDEA: Go to - File...
?F11Toggle bookmark
?Shift+F11Eclipse: ?
IDEA: Show Bookmarks
?Ctrl+]\[Eclipse: ?
IDEA: Move codeblock end\start

15 March 2010

IE Developer Toolbar for IEs4Linux

IEs4Linux is know the best approach of running Internet Explorer under Linux. Working on a web project I faced a need to fix some style bugs in IE. So I tried to install IE Developer Toolbar (for those who don't know - just like FireBug, but far less cool) and saw error message from msiexec saying "Internet Explorer Development Toolbar requires Windows 2000 or newer".

So this post is about how to install the toolbar anyway! :)

The point is that IEs4Linux runs IE in wine environment with Win 98 version (at least for IE6 this is true), that why developer toolbar doesn't installs. To fix this, execute:

$ cat `which ie6` | grep WINEPREFIX
export WINEPREFIX="/opt/.ies4linux/ie6" 

You will most probably see other path instead of  /opt/.ies4linux/ie6. So now we know where the wine environment for wine is located. The next thing to do is to run winecfg for this environment and change target Win version:

$ WINEPREFIX="/opt/.ies4linux/ie6" winecfg

A dialog window will appear and in drop-down in the bottom of the window select Windows XP and press OK.

With this changes your IE won't run. So, download MSI of developer toolbar to your home directory with your favourite browser and install it to your wine environment with the following:

$ cd ~ 
$ WINEPREFIX="/opt/.ies4linux/ie6" msiexec /i IEDevToolBarSetup.msi
After installing the toolbar, run winecfg just like we previously did and switch Win version back to Windows 98.

Voila, we have IE with developer toolbar :)

17 February 2010

Analogue of FreeBSD watch for Linux

Being using watch (8) utility in FreeBSD I have never knew it's analogue for Linux. When facing such a need I always managed to find another ways to meet it. Just yesterday I had much alike case :) and finally I've found what I needed all this time. Well, there are plenty of them actually :). I have found snoop, ttysnoop (haven't found web site, but there are a lot of prebuilt packages in the web) and ttyrpld.

Though the most watch-like of them seem to be snoop, other also may be worth trying. I have yet tried nothing of them, so comments are appreciated.

And before the end I would mention well-known screen.