Paul - The Programmer

simple & stupid

Fix the Jython console on my Windows XP

The Jython console didn't work properly on my Chinese version Windows XP. It can not interprete the strings properly.

e.g.

>>> print "hello world"

....

Looks like it's looking for a futher input.  After I input a '\n', ther console crashed and complains

LookupError: unknown encoding 'gb18030'.

This error never happens on the English version Windows XP. So, this problem definitely caused by the system default encoding.

 

With a few hours study for the JVM & the Jython encoding setting, I found 2 solutions.

1)  Change the JVM default character encoding

Start up the jython with option -Dfile.encoding=UTF8,then the Jython console's encoding will be UTF8 as well.

e.g.

jython -Dfile.encoding=UTF8


For change the JVM encoding automatically, you can also create one environment variable JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF8.

e.g.

set JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8"

2) Change the Jython console character encoding

Start up the jython with option -Dpython.console.encoding=UTF8

e.g.

jython -Dpython.console.encoding=UTF8

Or add this setting in the Jython registry file. On my laptop, the file is C:\jython25\registry

 

Now, you enjoy.

 

 

 

find & insert new line with VIM

:%s/$/\rthis is a new line/g

\r is the new line character in VIM.

Have Perl modules all in one file

This is so good for me when I practise the OO concept in Perl. Do not need to switch among the module files anymore. :)

package Foo;  # start the class package

sub new {
    print "In Foo::new\n";
    my $self = bless {}, 'Foo';
    return $self;
}

package main;   # get back to the main package

my $bar = Foo->new; # this is the first line for interpreter to read
print "$bar\n";

 

 

 

Use -prune to skip directory while finding file

To ignore a whole directory tree, use -prune rather than checking every files in it.

find \(  -path '<directory-to-skip>'  -o -path '<another-directory-to-skip>'  \)  -prune -o -print

Furthermore, take the file nams in consideration.

find \(  -path '<directory-to-skip>'  -o -path '<another-directory-to-skip>'  \)  -prune -o -name '<file-name-pattern>' -print

This trick really saves me couple of  time when I do a find in a large filesystem.

use regular expression to find files

Say you want to list all the *.py, *.cc and *.h files.

You may use the command below.

find ./ -name '*.cc' -o -name '*.h' -o -name '*.py'

But there is always a better way! So, give a try to the option -regex.

find . -regex '.*\.\(cc\|h\|py\)'

What's the backslashes in expression used for?  Well, the find command uses emacs regular expression syntax!