GNO Lab

All about nothing. Don't Panic!

Browsing Posts in Programming

I just bought a Nexus ONE Android device, and thought I should set up the SDK on my Windows 7, Swedish locale. Starting the emulator unscaled gave me a screen way too large, so I tried to start the emulator using the scaled display option. When started, I saw a number of black windows flying by, but no emulator was seen. When investigated what was started, using Process Explorer, I saw the emulator was started using -scale 0,5 (note the comma, not a dot as expected). OK, Eclipse constructs a command line, using some fancy ratio calculation, and the output is formatted according your current language. In my case Swedish where the fraction separator happens to be a comma.

Setting up Eclipse to run with an English locale solves the issue.  I added -nl en_US to the shortcut starting my Eclipse. Solved!

Do you have a lot of downloaded material, coming from bittorrent downloads, or from a FTP-session, where the content is encapsulated in big multi-volume archives like RAR and ZIP files (a.k.a. scene releases). Unpacking those archives can take a lot of manual effort before the actual content can be consumed.

This Python script tries to ease the burden of processing this kind of material, by investigating the directory and categorize its files as one of

  • archive, i.e. the files belongs to an archive, for example file.rar and file.001, etc. The archive also has a base file, that is, the first file in the archive, usually the file having the extension .rar in case of RAR-archives.
  • file, the file is an ordinary file, for example any *.nfo , and *.jpg file.
  • ignored, extra files, not needed for consumption, like those hash files (*.diz, etc.) used only to verify the downloaded content, and also sample, i.e a path matching *sample*.

The tool automatically unpacks the archives, and copies the files, to a given destination (or the current directory if you so like). Further, the destination directory can be derived  by removing a incoming base from the folder examined. The part left is appended to the destination given (or the current directory). Using this feature you can mimic  your content structure  within your download structure, without needing to create folders before moving the downloaded content into its final destination – all is taken care of within  btpostprocess.

Examples:

$ btpostprocess --process --incoming-base=/downloads/ready/pictures \
--base-path=/downloads/ready/pictures/cats \
/torrents/cats.torrent MyPictures

Finds archives and files in /downloads/ready/pictures/cats and a sub-folder indicated by the cats.torrent (or directly under /downloads/ready/pictures/cats) and unpack archives and copy files
into a cats sub-folder under MyPictures. The incoming-base is
used to construct a derived sub-folder under the destination folder.

Integration

The script was made with rtorrent in mind. By using  rtorrent’s  on finished capabilities the post processing can be set up using something like (version 0.8.2):

on_finished = process,"execute=btpostprocess,--incoming-base,/srv/incoming,--base-path,$d.get_base_path=,$d.get_tied_to_file=,/srv/depot"

Indicating downloads are to be found under /srv/incoming, and a folder given by the tied torrent file. Any files downloaded are unpacked (in case of archives) and copied into a sub-folder of /srv/depot.

In case you need to run some logic before spawning btpostprocess, for example, deciding if the download path is outside the normal download path, and in that case skip the post processing, all you need is to wrap the btprocess in a more specific on_finished script.

It’s all about automationDOWNLOAD

cvs log file | sed -n '/^symbolic names:/,/^keyword/ {
/^symbolic names:/d
/^keyword/d
p
}'

A simple script to remove empty directories in a checked out subversion repository:

#!/usr/bin/bash

find . -depth -type d -name .svn | while read d; do
d=$(dirname "$d")
echo >&2 ">>>> $d <<<<"
if [ 1 -eq $(ls -A "$d" | wc -l) ]; then
echo >&2 "Removing..."
svn remove --force "$d"
fi
done
svn status
  • Validate email address:
    ^([\\p{Alnum}_%\\+-]+\\.?)+\\@([\\p{Alnum}-]+\\.)+[\\p{Alpha}]{2,4}$

ASP.NET

No comments

I just is in the startup of using ASP.NET (and Ajax). To ease my understanding these links will help through the day:

JSTL (JSR 52)

No comments

JSTL comes in a number of flavors and implementations. The JSRs are the specifications.

A good tutorial on the issues can be found on Herong’s Tutorial Notes.

The JSTL libraries come in two flavors, the “rt” and the “el” libraries:

RT (run-time)

The “rt” tag libraries will accept request-time expressions for most attribute values as in:

<c:out value='<%= ((Foo)session.getAttribute("foo")).getBar()'%>/>
EL (Expression Library)

The tag libraries without the “rt” do not accept Request-time expressions but operate on EL (expression language) — for example:

<c:out value='${sessionScope.foo.bar}'/>

You can use both the “rt” and the non-rt (EL-supporting) tags in your JSP — just be sure and give them different prefixes in the taglib directives. In the long term, you want to get away from the rt tags – and use EL instead.

JSTL 1.0

Requirements: JSP 1.2 container Reference implementation:
http://www.apache.org/dist/jakarta/taglibs/standard/
EL-based tag libraries

EL-based tag libraries

Functional Area

URI

Prefix

Core http://java.sun.com/jstl/core C  
XML Processing http://java.sun.com/jstl/xml X  
Internationalization http://java.sun.com/jstl/fmt Fmt
Database Access http://java.sun.com/jstl/sql Sql

 

Runtime-based tag libraries

Functional Area

URI

Prefix

Core http://java.sun.com/jstl/core_rt c_rt
XML Processing http://java.sun.com/jstl/xml_rt x_rt
Internationalization http://java.sun.com/jstl/fmt_rt fmt_rt
Database Access http://java.sun.com/jstl/sql_rt sql_rt

JSTL 1.2 (May 8, 2006)

Requirements: JSP 2.0 container Reference implementation:
http://www.apache.org/dist/jakarta/taglibs/standard/

EL-based tag libraries

Functional Area

URI

Prefix

Core http://java.sun.com/jsp/jstl/core C  
XML Processing http://java.sun.com/jsp/jstl/xml X  
Internationalization http://java.sun.com/jsp/jstl/fmt Fmt
Database Access http://java.sun.com/jsp/jstl/sql Sql

 

Runtime-based tag libraries

Functional Area

URI

Prefix

Core http://java.sun.com/jsp/jstl/core_rt c_rt
XML Processing http://java.sun.com/jsp/jstl/xml_rt x_rt
Internationalization http://java.sun.com/jsp/jstl/fmt_rt fmt_rt
Database Access http://java.sun.com/jsp/jstl/sql_rt sql_rt

So, now I’ve actually used the .NET track and C#. I was in the the need of an unpacker, unpacking scene releases (you know all those RAR:ed multi-volume file sets). So I thought it could be nice way learn the Microsoft approach.

My first impression (compared to Java):

  • C# is a lot more talkative than Java. There are more keywords to make use of. There are structs and there are classes. Structs are always value types; when passed as an argument a copy is made (copy-by-value). C# also makes use of properties, where Java has its questionable bean approach (setters and getters). Same same, but different.
  • I made use of the IO classes of .NET framework (System.IO) for example the DirectoryInfo abstraction. Here I had to laugh; when I used the Equals() method, no value comparison was used. Having two objects, pointing to the same directory, ended up as false, when Equals() was applied. Of course I expected the equals method to compare if two directories where the same (and by same I do not mean by-reference). There were only for me to write my own helper functions, which also had to take care of trailing slashes as well, and of course translating to strings and then back to directory infos :(
  • The documentation could be better. Better description of return values, and also input parameters. I feel a lot of arguments are passed as strings, when the actually should be objects of a suitable class. A string is easy to pass, but gives the developer a hell, understanding what to pass in the string. Let i be a pattern, but what type of pattern? Regular expression, or maby a wild card pattern? I still don’t know.
  • Using the integrated form editor is not to hard. The default/only layout manager (anchor) does work. Just make sure you know how to revert to an earlier file in case your work goes amok ;)
  • GUI controls (WinForms) do lack things like a generic table (or list), where any kind of control can be used as column data.
  • The CodeProject is good place for help

This is something to remember, and evaluate. Can the standard be used to implement a CMDB? By reading, it seams as if JCR’s audience is towards CMS, but content could be anything. The following is interesting aspects:

  • Data stored as nodes and properties. Nodes can be associated with types, which dictate the kinds of properties, number and type of child nodes, and certain behavioral characteristics of the nodes.
  • Versioning
  • XPath search capabilities

Links