Slavus programing blog

My random programing (and other) tips.

Fetching Html Page Over Http in Java Using Google-guava

| Comments

I am using google-guava for some time know, I used it when there was only google-collections, and it is absolutely fabulous. Here is simple trick how to fetch whole html page over http in Java using google guava in one line:

Resources.toString(new URL("[")][],Charsets.UTF_8);

Go ahead and try out google-guava. Guava is great java lib.

Java 1.6.0_21 and Eclipse

| Comments

If you update to newest version of Java 1.6.0 update 21 and try to run Eclipse you surely seen on of this: - Unhandled event loop exception - PermGen space

So Eclipse started to become pretty unusable WTF. However for now there is simple workaround just edit your eclipse.ini like this:


You have to add -XX:MaxPermSize=256m.

The most interesting thing about this is reason why this problem reappeared, an old problem actually.

The reason is because somebody at Eclipse team hard-coded to check jvm signature by checking the file jvm.dll if the company name is “Sun Microsystems”. And as we all know because of the Sun-Oracle merge, and end of Sun existence, the company name changed to “Oracle”, and also the jvm.dll signature changed. more about this read on link

What have we learned from this, never ever hard-code a string that can change in the future, even when it is not likely to change, maybe there is some kind of “Oracle” that will come and “buy your string”.


Django FormMediaContext

| Comments

Django has great abstraction for forms. Feature that I find very useful in forms, is media meta class.

For example:

class SimpleForm(forms.Form):
    class Media:
        css = {
            'all': ('pretty.css',)
        js = ('animations.js', 'actions.js')

Vrijeme Je Za 1234567890

| Comments

Još malo i biti će 1234567890 sekundi od kad se računa Unix vrijeme. Da li ste spremni dočekali ovaj povjesni trenutak? I kako ste ga proslavili? Ja ću tu sekundu posvetiti svim Unixodima i onima koji će tek to postati.

Python Source File Encoding Hint

| Comments

When I program in Python I have bad habit writing comments in Croatian. When using characters like šđčžž i get some stupid errors. Some thing like this:

SyntaxError: Non-ASCII character '\xc4' in file

I know I have write first special comment, to tell Python I am writing in UTF-8., but I always forget what exactly I have to write. So here it is:

# -*- coding: utf-8 -*-

Django I Dodatne Aplikacije S Svojom Putanjom

| Comments

Ovo je prvi članak iz serija Django u Hrvata.

Ovdje ću opisati jedan kratki trik koji ja koristim da bi u svoj Django projekt ubacio neku od već gotovih Django aplikacija koje postoje u bespućima i github-a.

Moja navika je sve dodatne aplikacije staviti u poseban direktorij lib izvan django projekta. No onda imam problem dodavanja skinutih aplikacija u PYTHONPATH. Prvobitno riješenje mi je bilo postaviti PYTHONPATH varijablu okoline ljusci. No ovaj pristup se pokazao nedvovoljno fleksibilan (neprenosivost putanja na različitim računalima, različite ljuske na različitim operacijskim sustavima).

Interactive Django Shell in Eclipse/PyDev Interactive Console

| Comments

We all know that Django is great Python web framework, however one thing that bothers me is the lack of good development tool (Yes, I know there is VIM, and there is Emacs but guys it is 2008.) In my humble opinion best development tool for python is PyDev, Eclipse plugin for Python. The irony is that the best Python IDE is written in Java :).

With PyDev and Aptana, another irreplaceable plugin(but that is another story), you can do great Django development.

There are lot’s of tutorial how to use Django and PyDev (Configuring PyDev to work with Django : configuring pydev to work with django is a good place to start).

One thing that is very nice in Django is interactive shell, but this feature must be integrated with IDE, I missed this feature for long time, but in version 1.3.15 PyDev released new interactive console, great feature. First you need PyDev version 1.3.15 or higher (try to use latest one).