29 May

Xubuntu-desktop (XFCE) recipes

How to move from Ubuntu 13.04 to Xubuntu (Xfce)?

Good steb-by-step manual: https://sites.google.com/site/easylinuxtipsproject/alternative

How to create keyboard layout shortcut?

setxkbmap  -option grp:caps_toggle,grp_led:scroll "us,ru"

How to make desktop icons text transparent (icons shadow analog on Windows)?

Run vi ~/.gtkrc-2.0 and add the following config there:

style "xfdesktop-icon-view" {
  ## opacity of text background (0 - 255, 0 = transparent)
  XfdesktopIconView::label-alpha = 0
  XfdesktopIconView::selected-label-alpha = 100

  ## text background colors
  base[NORMAL]    = "#EDECEB"
  base[ACTIVE]    = shade (0.8, "#86ABD9")
  base[SELECTED]  = "#86ABD9"

  ## text foreground colors
  fg[NORMAL]      = shade (0.9, "#FFFFFF")
  fg[ACTIVE]      = shade (0.8, "#FFFFFF")
  fg[SELECTED]    = "#FFFFFF"

  ## whether or not unselected icon text gets truncated (...)
  # XfdesktopIconVIew::ellipsize-icon-labels = 1

  ## text shadow to be painted with the icon labels
  # XfdesktopIconView::shadow-x-offset = 0
  # XfdesktopIconView::shadow-y-offset = 0
  # XfdesktopIconView::shadow-color = "#000000"
  # XfdesktopIconView::selected-shadow-x-offset = 0
  # XfdesktopIconView::selected-shadow-y-offset = 0
  # XfdesktopIconView::selected-shadow-color = "#ffffff"

  ## spacing and sizing of icons on the grid
  # XfdesktopIconVIew::cell-spacing = 6
  # XfdesktopIconView::cell-padding = 6
  # XfdesktopIconView::cell-text-width-proportion = 2.5
}
widget_class "*XfdesktopIconView*" style "xfdesktop-icon-view" 
25 Nov

GWT using Activities and Places

I’ve tried to simplify and categorize my vision of “Activities and Places” in real application since HelloWorld app from Google’s page doesn’t provide overview of the full-cycle development and shows us only 10% of the iceberg. Maybe this diagram will help someone either. Although in most cases the whole page can be one active area, example shows how to use two independent displays on the page (in this case Menu and Content). It can be useful, for example if you have completely different page views for site-administrator and user.

25 Nov

Online tools for quick prototyping

All tools mentioned in this post are free at the time it’s been written

  1. wireframe.cc – very simple and nice tool for web-pages prototyping.
    Idea: Select an area and choose which type of the object it will be.
  2. moqups.com – tool with a little more sophisticated interface and therefore has more functionality.
    Idea: Make a composition from many proposed samples (eg. switchers, diagrams, buttons, combos, radio buttons, keyboards) or create your own using simple shapes
  3. cacoo.com – has a bunch stencils for creation of a different type diagrams, UIs and schemes
  4. lumzy.com – has a lot of common with Cacoo but has more kind of elements for interface prototyping. However Lumzy is clumzy, you need to be familiar with it to quickly find something you need. Catalog of the components has pure design and organization.
  5. iphonemockup.lkmc.ch – this one doesn’t fit current topic as it’s designed for iPhones’ UI wireframing only but I really like it. It’s so simple and of course pencil style is fantastic. Too bad I didn’t find something like that for multi-platform interfaces.
19 Nov

GWT Designer for Eclipse Juno on Ubuntu 12.X

Today I’ve tried to install Google Eclipse Plugin to draw some forms for my GWT-based app and caught the exception:

GWT http-server started at 127.0.0.1:45658
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fb2229d45a0, pid=8150, tid=140404439688960
#
# JRE version: 6.0_37-b06
# Java VM: Java HotSpot(TM) 64-Bit Server VM (20.12-b01 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libwebkitgtk-1.0.so.0+0x14245a0]  void WTF::freeOwnedGPtr<_GdkEvent>(_GdkEvent*)+0x15df0
#
# An error report file with more information is saved as:
# /home/ipcreeper/hs_err_pid8150.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Searching for at least an hour I’ve finally found the solution:

 

Step 1:

Download and install libhunspell package (xulrunner has a dependency on it):

http://packages.ubuntu.com/oneiric/amd64/libhunspell-1.2-0/download

sudo dpkg -i libhunspell-1.2-0_1.2.14-4_amd64.deb

Step 2:

Download and install xulrunner package:

http://packages.ubuntu.com/lucid/amd64/xulrunner-1.9.2/download

sudo dpkg -i xulrunner-1.9.2_1.9.2.28+build1+nobinonly-0ubuntu0.11.04.1_amd64.deb

Be aware that both libhunspell and xulrunner should be either i386 or amd64 version.

Step 3:

Open eclipse.ini and add path to installed xulrunner:
-Dorg.eclipse.swt.browser.XULRunnerPath=/usr/lib/xulrunner-1.9.2.28

Step 4:

If editor still not running, try to set the environment variable GDK_NATIVE_WINDOWS to false before starting Eclipse. Do it with following command:

export GDK_NATIVE_WINDOWS=false
11 Nov

How to switch version of Java in Ubuntu

Had a little headache trying to change version of JDK back from 1.7 to 1.6, so here is the instruction:

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install update-java

Then type:

sudo update-java

… and you’ll see the window with versions of Java to switch to.

Voila.

P.S. To extend the list of available JDK’s download the version you need and extract it to /usr/lib/jvm/

10 Mar

The importance of the hashCode()

Interviewers like to ask questions about the importance of hashCode() function, kind of “what would be if the hashCode() returns the same value for different objects” and vise versa, “what could be if it returns random number every time, can it break anything”?

I think the best way to memorize the answers for such a questions is to understand how it actually works in a real life code. Simple remember the following implementation from java.util.HashMap:

public V get(Object key) {
        if (key == null)
            return getForNullKey();
        int hash = hash(key.hashCode());
        for (Entry<K,V> e = table[indexFor(hash, table.length)];
             e != null;
             e = e.next) {
            Object k;
            if (e.hash == hash && ((k = e.key) == key || key.equals(k)))
                return e.value;
        }
        return null;
    }

Even just these two lines:

if (e.hash == hash && ((k = e.key) == key || key.equals(k)))
                return e.value;

As we see, two different keys can have the same hashes. If we make the hashCode() always return the same integer it won’t break anything but it will decrease performance of searching the key. HashSet collection is based on the HashMap and works the same way when we use it’s contains(Object key); method (basically it just delegates the task to the hashMap’s getEntry(Object key); method which is using the above algorithm).

So, the answers are: if we use a custom object as a key, we need to provide our own hashCode() to have a greater performance. If hashCode() returns random integer every time, the hashMap won’t probably ever find the key you’ve put into it.

14 Feb

HTML parsing in Java is really simple with Jsoup

The other day I needed to write an application which parses different data from a pile of web pages. I’ve found an excellent library that parses HTML with JQuery-like selection methods. You do not need any regexes which cause a headache.

For example, you need to get a title and URL of anchor from the HTML code below:

String html = "<div><a href="http://blog.romanvlasenko.com/">Click here...</a></div>";
Document doc = Jsoup.parse(html);
String title = doc.select("div.some-class a").text();
String url = doc.select("div.some-class a").attr("href");

Voila! You have what you needed.

If you need to parse a real web page, use Jsoup.connect() method instead of the Jsoup.parse()
Jsoup has it’s own HttpConnection that encapsulates some extra-work which you were needed to do with Java’s HttpURLConnection.

Document webPage = Jsoup.connect("http://blog.romanvlasenko.com/").userAgent("Mozilla").get();

Now you have downloaded web page ready for processing. Jsoup provides both POST and GET methods. For more details see the Jsoup project homepage.

29 Jan

GWT: client code optimization

I’d like to share with you one tip which I’ve learned only yesterday, in spite of the fact that you may already know it.

Our GWT project is written with a lot of modules that include initialization of child modules in their constructors which initialize a lot of another modules in their constructors and so on… Some modules can load different data for initial rendering, despite the fact that user won’t see them in current session, however this data and asynchronous calls are forcing application server to do unuseful job and weighty client code makes some delays on application start up in user’s browser.

Here is the solution! Recently I read about ReadAsyncCallback interface which allows to easily make deferred calls right in the client code. Just imagine, it allows you to make deferred method call in a client code in the same way as you make requests to your remote services:

GWT.runAsync(new RunAsyncCallback() {
    public void onSuccess() {
      new SomeModule().show();
    }
    public void onFailure(Throwable ohNoes) {
    }
  });

This really simple method tells compiler to split your code into parts if it possible without any bad consequences.

To learn some details and limitations of this feature read the official documentation.