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.

Friday, August 31, 2007

Plans for future development

Well, I'm finalizing the very first alpha version of my new CMS I'm developing for about four months now. So I decided to share a few plans of mine for the nearest future (next school year). As you may think the first thing is to finish the CMS, which I think will be really cool and will change the way people use CMS (but that's probably very optimistic :-) ). The CMS is Java-based, uses Hibernate for persistence and is designed to run in Tomcat. I have still a lot of work to be done to solve many issues from missing features to performance, but I'm quite happy with the results I'm getting now. So I made some time to write this post. The sad thing for most of you is probably the fact that it won't be open source probably. And I can't even tell you the features of CMS as it's "confidential". However one part of the CMS will be open source. The part is the templating system code-named FinalShape. FinalShape is templating system slightly similar to Apache Velocity. Unlike Velocity FinalShape is directly designed for being used in web environment. FinalShape is in fact alternative for JSP, ServerFaces, Servlets and similar stuff. Unlike servlets and similar FinalShape templates can't contain any executable code and can be safely used by non programmers to design HTML websites. In the CMS (I'm working on) web designer can safely change the template from the administration interface in runtime without any redeployment needed.

From other features I consider important are already implemented:
  • internationalization and localization support on template engine level
  • compilation of templates avoiding re-parsing templates again and again
  • 2-level caching (cached are both compiled form of templates and rendered pages)
  • compression support (all cached pages are compressed and passed to browser compressed if browser supports HTTP compression, otherwise the page is uncompressed before passing to browser - this minimizes memory used by cache and minimizes traffic)
  • structured documents support (nested blocks)
  • commonly used built-in page elements and possibility to implement custom elements
  • many other minor features :-)
OK. That sounds good, doesn't it? So when can you expect to download FinalShape and it's source code? - In early 2008. I know that doesn't sound soon, but I have a lot of other stuff to do and FinalShape needs some minor tweaks yet, some source code cleaning and also some documentation to help you start.
I have also another cool project in progress, but I will tell you about it sometime later. I would like it to be my dimploma thesis, so as soon as I find some guarantor and the topic gets public I'll write more about it here.

Thursday, August 30, 2007

Advertisement

I'm sorry for the advertisement here, but I would like to get some money via Google AdSense to pay me part of my time spend by writting this blog, if possible. I think Google AdSense is not very striking and offers quite relevant links. So I hope that it will help you to find something you are really looking for.

Strokeboard: Can touch screen be better than HW QWERTY?

So the time has come! :-) I would like to present my keyboard design to the wide public (or more probably to the few reading this blog). If you are not interested in history go to the end of the post to try how the keyboard works! If you want more information contact me via email wessan@email.cz

The keyboard I would like to show you was designed by me about 3 years ago when developing a Flash-based game. The game was never finished and the keyboard wasn't used for a long time.
Until the semester last school year. I had a subject called "Human Computer Interaction", in which we had to do some usability testing. Unfortunately I accidentally (email was marked as spam by my email client) missed a meeting for project assignments and I had to think of a project of my own. I had about a day to think it over and I remembered the old idea. I implemented first experimental version of the keyboard and performed some usability testing.
So I had the first version (you can see on the first picture) and asked few friends to use the keyboard for the first time. The first version was designed for stylus and usability testing showed that unexperinced used can type about 45 characters per minute with stylus. However the keyboard was quite unusable with fingers.

First version for the usability testing with stylus:
Second version with eliminated less-often used keys:
Third version with larger buttons for typing with fingers:
Screenshot of current version being prepared for next round of usability testing:I'm looking forward for comments and critics, whether positive or negative. But please remember that this is just a mokup application for future usability testing (the button for special symbols and BACKSPACE do not work and SHIFT work like CAPS LOCK yet). Also remember that this version is designed to be controlled by fingers on a PDA-like device.

If you would like to get more information about the keyboard or want to use it in you application or device, please inform me via email wessan@email.cz

Now enjoy the keyboard (flash demo):



How to use the keyboard?
  • click into the text field above the keyboard to start typing
  • letter in the middle of any box is written simply by clicking mouse button in the box
  • start writing a letter by pressing the mouse button anywhere in the box containing the letter
  • while holding the mouse button perform a stroke to the direction in which the letter is from the center of the box - move mouse to up-left to write 'A', up to write 'B', up-right to write 'C' etc.
  • you can leave the box when performing the stroke - you don't have to stay in the box at all cost :-)
  • release the mouse button and you are done writting a letter
  • ask in comments if something goes wrong :-)
You can notice that the letters are clustered by 9, so only 3 buttons are enough for whole English alphabet. Compared to QWERTY keyboards the buttons are much bigger. Every letter is then written by touching the button containing the desired letter and performing a stroke to the direction in which the letter is from the centre of the button. The letter in the middle can be written by simply touching the button without performing a stroke.
Sounds difficult? Try demos and you'll see how easy is it. But remember it's just demo developed for usability tests and it's not fully working. However it should give you an idea how to use the keyboard.

Old Java school stuff

This is a post from my previous blog I copied here because I thing it could be interesting for some starting Java developers.
I have very a good exam in physics, that I started to hate several years ago while encountering it for the first time at university. Fortunately I had a pretty cool professor last semester (Petr Kulhanek), so no "try-to-remember-as-much-as-possible-exam" was necessary, just to write single applet demonstrating you are able to work with physics in real life. Single Java product working as both applet and standalone application.

I also really tried CVS for the first time and it was quite a great experience with Tomas Prochazka who is the second author of the application. Great idea and code exchange. His programming style is quite close to mine and he understands Java as well as I do (hard to tell and not important to tell who is better). So, I say virtual "Thank You" to Tomas. Pretty good change from last time I used to work on another programmer's code.

So go to http://atom.mamto.cz/projekty/skola/F2P/ and try how it works. The site is in Czech, but you can simply find the link to applet and run it (it's already in english). Here is direct link to applet http://atom.mamto.cz/projekty/skola/F2P/run_applet.html and here to Java webstart http://atom.mamto.cz/projekty/skola/F2P/run_ws.jnlp

Wednesday, August 29, 2007

Extreme Yachting

Well, I know that this post is not exactly about programming. But as I have "holidays" I will post another holidays related stuff. Because of the very cool experience with sailing on yacht, I tried to find some videos about yacht racing. I have found some on YouTube and I think they are worth watching even when you have no experience with yachting.



Monday, August 13, 2007

The very first yachting in my life

Few days ago I returned back from a very special trip for me. I have spent about 6 days with some people on a yacht for the first time in my life. Every member of the crew was for the first time on a yacht in fact. Of course except for our captain, who put the crew together.

We were not exactly good friends, but that was not so important. Despite not being the best crew in the world I had a lot of fun and I guess all the others as well. As everybody kept saying there would be no such trip with the same weird crew again. So it seems that the trip was quite unique.

After about 2 days of almost no wind a storm came to make things little bit more interesting. We were eager (or at least I was) to try something exciting. We stayed in the middle of the lake when all others were packing their stuff and going to shore. So we made some prep and after short discussion with captain like ...

Crew: Why we raise our sail when others put them down?

Captain: They are chickens.

Crew: Why are we the only ship on the lake?

Captain: Because others are chickens.

... we started to enjoy the storm.

I kept recording as long as my camera was working. Unfortunately the rain was to heavy and my Sony alerted me with "MemoryStick Error" and few seconds later it stopped working totally. I took out the battery and passed it with the camera to a very brave crew member hiding himself in under deck.

I was afraid that the storm ended my Sony's short digital life. Fortunately when I turned it about a day later, it was working. So I'm able to show everyone a little taste of the beginning of the storm. Although the most interesting things happened after the recording, it should show you that sailing can be quite exciting from time to time.

Monday, July 16, 2007

Class loading in Java and C#

Java and C# are often told to be almost identical languages. C# is often being accused of being just a remake of Java. I would like to show some very core difference between how things work in Java and C#. Of course Java and C# are competitors despite their differences as C++, PHP, Objective-C, Python and others are also competitors of Java in specific areas of programming.
I would like to excuse a bit for not havingdeep knowledge of C#. So if find something that you think is wrong let me know. I describe here the difference I have discovered during some project I'm working on for some time. I wouldn't like to talk about this project to wide public yet, but some of my friends already know and this blog will be probably the first place I'll write about this cool project.
The process of executing code has evolved over the years. Starting with just machine-code being executed from the specified location. Dynamic libraries came later - these are the .dll, .so and other stuff you know from any operating system. Major advantage of dynamic libraries is that not all code has to me included in the programm itself. This mechanism is used from 80's to date. The special category of class execution are scripting languages. Applications in scipting languages usually came as a collection of text files that are executed when you open them or access them from the internet (JavaScript, PHP and a lot of others). The major advantage is that these scripts are human-readable can be modified anytime including right before execution (in extreme cases also during the execution by the application itself - but please do not do this at home without suprvision of adult person as it leads to producing VERY MESSY code).
When Java came it brought revolutionary new mechanism of loading new code. This was called dynamic class loading. The idea was great - the application can load any class from any location including but not limited to local file-system, internet server, SQL database etc. However this feature is not used very often in Java.


C#'s approach

Well, in fact, there is nothing what to write about. The C# is not much different from any other C-family language. Although it uses syntax similar to Java and has garbage collection in runtime it still behaves much like any older language.
C# in fact doesn't load classes. Instead it loads so called "asseblies" which are in fact several classes group together. I'm not sure whether the assembly is a whole .dll, but I think it's not.  However this is not so important. I don't also know why the classes are not loaded separately but it can be bacause of performance reasons and the fact that the object-oriented design is partialy sacrificed after compilation to CIL. This enables non-virtual method calls that cannot be used in Java and probably other optimization enabled by the fact that the classes are not strictly separated and "know more" about each-other.
The most important difference is that all code in C# is loaded by system. The application has no option to take care of the class loading. This enables that compiled code of .dll can be cached and the .dll doesn't have to be compiled from CIL to machine code every time the application runs.
I don't know why Microsoft has chosen this approach, but reasons are probably three:
  1. C# is more C++ than Java and compability with C++ requires using .dlls and loading in assemblies
  2. performance reasons - enable caching of compiled code, enable non-virtual method call etc.
  3. Microsoft in general is known for poor architecture of it's applications and Java-like class loading could be just a thing that wasn't considered important
Java approach

Although Java is older than C# it uses much more advanced aproach as it doesn't have a heritage of older languages and was designed from the ground without compatibility with any other language.
The class loading process in Java is pretty simple, flexible and can be customized by developer. The key to class loading is surprisingly class called ClassLoader. This class is abstract and can be extended by developer. Class loaders are structured into a hierarchy with root class loader being so-called system class loader. If you don't use your own class loader the system class loader usually does all the stuff.
So what is the purpose of class loaders? Their name explains it pretty clearly, doesn't it? But to be sure here are the things system class loader does:
  • locates byte-code of classes
  • locates resources (.properties files, image files and whatever else in your .jar archives)
  • passes byte-code of classes to JVM
So what's the great thing about that? Almost every language can load files and code dynamically. The great thing is that you can override all these methods :-). You still don't know what is so great about it? The great think is that you can load the classes from anywhere (for example download from IMAP acount if you are really crazy) and can do anything with the byte-code before you pass it to the JVM.

So, is there any practical use for that? I think you think that I can't think seriously you would think that this example would make think that class loading in Java is extra useful. Except the project I'm currenty working on , which would be impossible without custom class loading, there are few examples I can think of:
  • you can your classes store encrypted (when used on untrusted server) and decrypt them in runtime
  • you can instrument the code for collecting statistics (for example number of method calls etc.)
  • you can download classes of specified version directly from Subversion
  • you can optimize byte-code and cache it
  • you can generate custom classes in your class loader
And how to create custom class loader? Well, use the Javadoc and your fantasy. It's really long story to tell all what you you can do and how. When starting with Javadoc try ClassLoader.loadClass(String) method first and follow all related to it :-).

But I will tell a short story now. What you can't do with custom class loader?
  • you can't load classes in package java.*
  • you can't make custom compilation of byte-code to machine code (however you can optimize byte-code before passing it to JVM if you feel good enough :-))
And one last thing. Remember that MyClass loaded by class loader A is not compatible with MyClass loaded with class loader B although the classes are exactly the same.

Ufff. That was interesting. Let me know if you understand the post or not. I will have to fix it few times probably before making it clear enough.

Saturday, July 14, 2007

The very first post

OK, here I'm. I have finally decided to make my own blog. In fact I have one already, but haven't written a lot posts there yet and haven't updated it for quite some time. This should change now. I'm working on some cool stuff now. Or at least I think it's cool stuff and I would like to share few ideas about them from time to time.

I would also like to be more personal from time to time and show to public something I usually only show my drawer from the inside. But this won't happen very often I guess.
So the question is "why another blog?". The answer probably "because it's mine". I thought a bit about it and I decided to start because I really like discussing stuff about programming technology and all that stuff. I spend quite some time chatting with friends about that stuff and when I discussed such stuff with a very good friend of mine we both wrote simultaneously to the other that I should also write down some ideas from the chats and share them with public. By the way the good friend is Tomas P. or T. Prochazka to be anonymous. Tomas if you don't want the two people who will read my blog know your name, let me know and will delete you :-).