2006-05-30

Python: The encodings

To make the picture complete in python batch files the encoding should be set explicitly

@python2.4 -x %0 & GOTO EXIT
# -*- coding: cp1251 -*-

print("Превед!!!");

"""
:EXIT
@rem """


Ha... if I would live on Linux only I'd never know about it. UTF-8, after all.

2006-05-24

Python2Bat

I've come across a looong discussion of the problem of embedding python code to batch files. To click and run.

The discussion is long, solutions are bulky.

There was no need to make all that fuss:
python2.4 -x %0 & GOTO EXIT

print("Hello, from python!");

"""
:EXIT
@rem """

2006-05-13

Java: Memory leaks

For all C++ monstrosity it brainwashes yet.

About six months ago guys had a problem with j2me app. Run tests: 1st passed, 2nd raises OutOfMemory error. Change the tests running order — now the ex-first test raises OutOfMemory. I looked at this, but could not tell anything reasonable.

I've just remembered about it and it seems to me I've understood what the kind of trouble was that. The problem is exactly between the two lines:

class MemoryLeak {
static int[] buffer = new int[0];

public static void reinitialise(int maxsize) {
if(buffer.length < maxsize)
buffer = new int[maxsize];
}
}


The problem is that Java machine acts too straightforward. The first call of reinitialise is normally, during the second call at first it tries to allocate memory for a new massive and in the case of success the result is assigned to a variable. And only after that the memory to which buffer was referred will be available to Garbage Collector. As a result for a normal work it is required 2*maxsize of memory. The solution is to set buffer to null before the memory allocation.

But IMHO Java machine could take care of it. And in rare cases when double memory allocation is required it is better to be described explicitly.

public static void reinitialise(int maxsize) {
if(buffer.length < maxsize) {
int tmpbuf[] = new int[maxsize];
buffer = tmpbuf;
}

2006-05-11

Usability: Pager


"The real danger is not that computers
will begin to think like men,
but that men will begin to think like computers."

Harris, Sydney J. American journalist


The standard behavior: there are 21 photos, it is required to place this treasure at a site. It's not cosher to dump all at once, it should be divided for separate pages, say, 10 photos per page. As a result on the last 3d page will be a single photo, which is not convenient. To look at one or two photo one should go to a link... wait...

The situation became worse when working with mail through web. Marking 11 messages as «read» takes the same time as for 20 messages.

Although it will take a programmers 15 minutes to place at the last page on 30 % more items, if it allows to avoid transferring remains to the next page.

2006-05-10

The programming: MFC nonsense

Nonsense:

This does not work:
combo.SetRedraw(FALSE);
//Blah-blah-blah
combo.SetWindowText("something not in list");
combo.SetRedraw(TRUE);


And this works:
combo.SetRedraw(FALSE);
//Blah-blah-blah
combo.SetRedraw(TRUE);
combo.SetWindowText("something not in list");

Sucks...

2006-05-04

Linux: Ubuntu on coLinux

I've discovered in coLinux Wiki a way of the installation Ubuntu and Debian to pure coLinux. A couple of years ago I started from ready Debian image and ever since update it from time to time. It turned out, I could just take installation Cds and make a clean installation.

IMHO ready installator installing and setting everything — net, sound, X would be a best variant for a beginner in Linux. Guarantee support all hardware (well, since on Windows everything works), no troubles with disks formatting — just study the system, get accustom to soft. And then, in a beautiful moment — done in a wink - and you are on Linux with the minimum of unpleasant feelings.

Actually, two years ago I did exactly so :)

2006-05-03

Web: Google mobile proxy

It's a miracle. I've logged in my gmail account through web interface from PDA and discovered an interesting google service. It seems, everybody already knows about it but I've found it just now — it's a proxy server optimizing pages for mobile devices. It is easy to use — just print http://www.google.com/gwt/n?u= and after the equals sign write the required site address.

Here, just now I've painted for my PDA a javascript page automatizing this thing. It's so good to be a programmer!


<html>
<head>
<script>
function go(form) {
var url = form.url.value;
if(url.substring(0,7) != "http://")
url="http://"+url;
window.location = "http://www.google.com/gwt/n?u="+url;
}
</script>
</head>
<body style="text-align:center">
<form>
<input name="url" type="text"/>
<input type="button" value="go" onclick="go(this.form)"/>
</form>
</body>
</html>