geo / scala — No comments
17
Jun 10
Here is a chunk of Scala code for getting lat/lon coordinates of geographical locations (cities or villages) using the wonderful geonames.org webservice which allows to search for geo entities by name. The getCoords() method returns a triple of (resolved entity name, lat, lon). The countryCode parameter is optional and will limit the search within the country when specified. The webservice often returns more than one result, in this case the method will return the coordinates of the first one.
import scala.xml._
import java.io._
import java.net.{URLEncoder, URL}
def getCoords(query:String, countryCode:String):(String, Double, Double) = {
val geonames = XML.loadString(readUrl(
"http://ws.geonames.org/search?featureClass=P&q=" + URLEncoder.encode(query) +
(if (countryCode != null) ("&country=" + countryCode) )))
if ((geonames \ "geoname").size > 0) {
var firstGeoname = (geonames \ "geoname").first
((firstGeoname \ "name").first.text + " (" +
(firstGeoname \ "countryCode").first.text + ")",
(firstGeoname \ "lat").first.text.toDouble,
(firstGeoname \ "lng").first.text.toDouble)
} else {
null
}
}
def readUrl(url:String) = {
val in = new BufferedReader(new InputStreamReader(new URL(url).openStream(), "utf-8"))
val response = new StringBuilder
var inputLine:String = null
do {
inputLine = in.readLine
if (inputLine != null) response.append(inputLine)
} while (inputLine != null)
in.close
response.toString
}
Calling getCoords(“Neuchatel”, “CH”) returns a triple (Neuchâtel (CH),46.99179,6.931).
hci — No comments
22
Jul 09
The question persists and indeed grows whether the computer will make it easier or harder for human beings to know who they really are, to identify their real problems, to respond more fully to beauty, to place adequate value on life, and to make their world safer than it now is.
Norman Cousins, “The Poet and the Computer”, 1966
java / my projects / photo / swing / ui — No comments
22
Jun 09
This weekend the weather was not that great so I spent it at home. Also my laptop almost run out of disk space, so I decided to do something about it. I had 50 Gb of photos in my Picasa albums (it’s because I mostly shoot RAW, I guess) which I always wanted to archive on an external drive keeping only the starred photos on the laptop, so that I can always have the best photos with me. But there is no easy way to do it in Picasa. Well, of course you can do it manually, but in my case it was not an option, because I had so many photos on my laptop.
Just improving the python script which I had been using for few years for backing up Picasa albums would not be an option, because this new tool would need a UI. The user needs first to have an overview over the albums and the disk space they consume, and then decide which one to archive.
So I decided to make a tool which would help me with it. On Saturday evening I started to code and have fun with the good old Swing, and finished it late on Sunday. And then the tool helped me to remove tens of thousands of non-starred photos which I didn’t want to have on my laptop (after backing them up) and free precious gigabytes just in few minutes.
Here it is: Picback. If you are an extensive Picasa user and photographer, I hope it can be useful for you too.

shell — 1 comment
19
Jun 09
If you use Subclipse, switching to another repository in a local working copy can be pain in the ass, because Subclipse (and I think svn itself) only allows to change the path of the repository if it’s still in the same repository. I had to change the path from http://.. to https://.. and couldn’t do it in Eclipse. Subclipse reported an error: “https://.. is not the same repository as http://.. “. As a last resort I decided to manually update the repository in all of the svn’s entries files using the magic xargs command. Running this command in the project root directory did the trick (works with Cygwin on Windows as well):
find . -name entries | xargs sed -i "s/http:\/\//https:\/\//g"
javascript / visualization / web — 1 comment
19
Mar 09
John Resig released a port of the Processing language to JavaScript. The demos are very inspiring.

db / debugging / java / web — No comments
17
Feb 09
After 8 months of development of a new project with extensive use of Hibernate I can now tell about my experiences with it. In general, Hibernate is a very useful tool. It saves a lot of time, because you don’t have to write SQL queries. If you make changes, you usually don’t have to rewrite queries, because there are only a few of them. The configuration using annotations is simple and powerful (and I personally prefer it to writing mappings in XML). Hibernate is able to generate database tables from mapped classes automatically and even update them as you add new fields to a class. Hibernate caching facilities are very useful. Finally, Hibernate allows to develop database vendor indepentent applications.
But there are few problems which I experienced:
- The most frustrating is in fact described in the Hibernate docs. An object returned by session.load() isn’t necessarily an object of the expected class:
Cat cat = (Cat) session.load(Cat.class, id); // instantiate a proxy (does not hit the db)
if (cat.isDomesticCat()) { // hit the db to initialize the proxy
DomesticCat dc = (DomesticCat) cat; // Error!
....
}
- No inheritance mapping for value objects: here is the JIRA issue that never gets fixed, and a workaround.
- The strong suggestion in the Hibernate documentation to use a join table for every unidirectional one-to-many association (in the section 2.2.5.3.2.2. “Unidirectional”). Another suggestion is discussed here.
- 2nd level caching should be used with caution: after deleting an object the stale version can still stay in cache which can lead to an ObjectNotFoundException. I found no other solution except disabling the 2nd level cache for the class.
java / my projects / piccolo / swing / ui / visualization — No comments
17
Sep 08
The CGVis project, our visualization tool for multidimensional data, is finally open-sourced. Hurrrah!

python / web — No comments
12
May 08
At the Grazer Linuxtage I liked most the Armin Ronacher’s talk about Werkzeug which is a Python library for building web applications that doesn’t limit you in the way you build your web app (like many of the existing frameworks do). Werkzeug is rather a handy set of tools and utilities for making web apps than a framework.
The most impressive part of the talk was when Armin demonstrated the “online” debugging feature on a standard error page generated by Werkzeug. Upon each error the context in which it happens is stored on the server (only if the app is in the debug mode). Thus on the error page itself you can directly interact with the Python interpreter which is “frozen” in the very state in which the error happened. So you can use the full power of the interactive Python interpreter directly on the standard error page. That’s awesome.
shell — No comments
21
Apr 08
I didn’t know that it’s so simple to make directory aliases on Windows 2000+. There is an undocumented utility for it: linkd.exe (part of Windows Server Resource Kit), which is roughly equivalent to ln -d in UNIX. So you can write:
LINKD Docs C:\Documents and Settings\Ilya\My Documents
And voila! You have now C:\Docs which links to My Documents.
More here