Wednesday, September 5, 2007

"Smart Back" button for Opera

You know that: You go to a web gallery for example and open new images. You try the back button and nothing happens. Then you notice that the image opened in a new tab. So you close it to get back.

Well this was something I hated because I had to think whether I opened something in new tab or not. So I begged Opera developers to create better back button that would close the new window if there was no step back possible. Well Opera still has not the "Smart Back".

But fortunately Opera is pretty customizable and allows you to bind custom commands to keyboard shortcuts and mouse gestures and even create custom buttons. So I created one that doesn't work perfectly, but it's closer to the "Smart Back" button that the default one.

The behaviour can be emulated by this command "Back | Close page & Switch to previous page". You can assign it to the left mouse gesture, to ctrl+left keyborad stortcut or to any other. I have created the "Smart Back" button for you. Just click the following link and add the button to the toolbar.

Smart Back Button download

And here is how to setup Opera's mouse gestures and keyboard shortcuts:

First, check the "Open new tab next to active" check box:

Then go to shortcuts category and choose "Edit" for both mouse gestures and keyboard shortcuts:
Add "Back | Close page & Switch to previous page" to column actions instead of "Back" to GestureLeft:
Replace all keyborad shortcuts previously contaning "Back" with "Back | Close page & Switch to previous page":

Tuesday, September 4, 2007

New Opera 9.5 "Kestler" alpha

EDIT [en]: A good friend of mine noted that I haven't placed link to the best czech (as I'm from the Czech Republic) website about Opera - so here it is www.operacesky.net

EDIT [cz]: Jeden kamarád poznamenal, že bych sem měl dát link na nejlepší českou stránku o Opeře - takže tady je www.operacesky.net


Opera has released new 9.5 version of their browser. This version is only in alpha stage of development, so don't install it over the current version, because 9.5 is not yet for daily use. This post is already written form the 9.5. The hugest difference I noticed after several seconds of browsing is much improved speed, but there is list of other major changes:

  • rewritten ECMAScript (JavaScript) engine
  • history search (when typing address, your history is full-text searched for words you type in address bar)
  • synchronization with Opera server (every Opera on every computer you use will have the same bookmarks, speed dial, etc.)
  • restoring closed windows
  • 64bit version for Linux
  • VoiceOver support on MacOS X
  • mail improvements (underhood)

Read more here: http://www.opera.com/products/desktop/alfa/alfa.dml

Wisit Opera's desktop team blog: http://my.opera.com/desktopteam/blog/

Download here:

Windows: http://snapshot.opera.com/windows/o950a1_9500_en.exe

MacOS X: http://snapshot.opera.com/mac/o950a1_4404.dmg

Unix: http://snapshot.opera.com/unix/9.50-Alpha-1/

Monday, September 3, 2007

Content Aware Image Resizing

Content aware image resizing is a new way how to resize images. Everybody knows how common resizing works (image just gets smaller or larger). The problem is when you want to change the image aspect ratio to fit the image to some given dimensions. This would usually lead to croping the image (sacrificing part of it's content).
Content aware resizing shows that there is another way how to do that. It generaly keeps the "important" content unresized and shrinks or expands only the "unimportant" content. This means that the "important" content keeps it's aspect ratio (for example people won't be unnaturally thin or fat). The importance of every area is generally decided by how much the color varies in the every area, expecting that the unimportant areas are not so "colorful".
Watch the video to see what can be done with the software. The project looks very interesting and the idea is great. Do you think this technology has a future?

Saturday, September 1, 2007

Brain-twisters worth wasting time with

I have encountered few really cool brain-twisters I spent some time playing with. They have both very simple rules and that's reason why I like them. If you like logic games I'm sure you'll like these games too. I'm glad that Flash made it so simple for people to develop simple games that almost anyone can bring his/her ideas to public. So enjoy.











Removing diacritics (accents) from String in Java

Yesterday I was working on uploading files in my CMS. The file should be downloadable using nice path containing file original file name. The problem is that not all file names can safely be used. For example I wouldn't like to use file name "Výroční zpráva 2007", but I would like to replace it with something like "vyrocni-zprava-2007".

Well how to do it in Java elegantly? I will skip replacing spaces with dashes and lower casing the name as it should be clear and simple. The naive way is to replace all characters containing diacritics using String.replaceAll() method similarly to replacing spaces. The code would look like this:
public static String getPath(String name) {
return name.toLowerCase().replaceAll("[\\s]+", "").
replaceAll("[áàâ]", "a").
replaceAll("[èéêëě]","e").
... a lot of other similar lines ...
}

Well this would essentially work. But when I was think of writing something like that, I was thinking like: "That would look pretty lame and PHP-like and Java is much more advanced language except everything else also with core Unicode support. There must be a way how to write it better."
Except looking lame, the above code has also several disadvantages. The most obvious it that you would have to explicitly name every character with diacritics and that can be difficult as many languages have their own special characters. For example Swedish has characters like 'å', 'ö', 'ä', or Czech (my native language) has characters like 'ě', 'š', 'ř', 'ž', 'ý', 'ú' and even such stupid character as 'ů'. You would have to know languages pretty well to be able to name all the characters.
The other disadvantage is that such code would run pretty slowly as the complexity grows with number of characters you are finding to replace. I don't know a lot of languages, but I guess the number of such characters can even hit 100 mark.
So because of that I decided to look for better solution and the obvious place to start was java.text package. And this is what I got:
// you need to import java.text.*
public static String getPath(String name) {
name = name.toLowerCase().replaceAll("[\\s]+", "");
Normalizer.normalize(name, Normalizer.Form.NFD).
replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
}
So what does the code do? Firstly it replaces spaces and lower-cases the string. The second line decomposes every character with diacritics to more characters where the first is the character without diacritics, followed by characters representing the diacritics. As all characters representing diacritics are from specific Unicode range they can be easily replaced with single and simple replaceAll() method call.
So what are the disadvantages of the code? It works in 1.6 only. As alternative you can use sun.text.Normalizer available also in 1.5, however that doesn't lead to very portable code and would cause problems on Mac OS X for example.