Search This Blog

Friday, 30 October 2009

script to delete recursively all the CVS folders from a directory on Windows

Here comes a useful script to be run on the root folder of a CVS checked out project, in order to recursively delete all the CVS system folders named "CVS".

This comes useful when I need to copy some folders directly from a CVS project to another file systems without the need to export the project from the CVS.

FOR /F "tokens=*" %%G IN ('DIR /B /A:D /S *CVS') DO rmdir /S /Q %%G

If you paste the script directly in the Windows console, replace %%G with %G.

batch script on Windows to get the current date

I've come across the need of getting the current date,
inside a batch file on Windows, here's how to do it:

FOR /f "tokens=1,2,3,4 delims=/ " %%a IN ('date /t') DO (
SET FileDate=%%c-%%b-%%a

echo executing backup in date %FileDate%

Subversion resources

I've found a complete and interesting description of the Subversion system, at

Intervals intersection in SQL

An interesting problem, elegantly solved with the use of language SQL, is the calculation of intersections between sets of intervals.

An example of this problem is: arrange a meeting for a group of people who express availability of different times.

In that case you must calculate the time slots in which all persons of the group are able to participate at that meeting.


1 3 5 12 20 21
A ---- -------------- ----
B -------- ------
C --------------------

the solution is the following set of intervals
{[5,6], [10,12]}

Let's create the table TIMESLOTS (uid, start, end) whose rows contain for each person, identified by uid, timeslots which fit. They are defined by the start and end column.
The table in our example would be populated as follows
person start end
A 1 3
A 5 12
A 20 21
B 2 6
B 10 13
C 4 14

Assuming that in the table TIMESLOTS for each person timeslots are disjoint, that is they don't overlap (this is a non-restrictive assumption, in general) we can solve the problem of the intersection by mean of the following considerations:

the solution contains intervals whose delimiters are delimiters of some intervals in TIMESLOTS: actually, for example, the solution interval [5, 6] is delimited by the point 5, being a delimiter for the interval [5, 12] belonging to the A person, and by the point 6, being a delimiter for the interval [2, 6] belonging to the person B.

Considering the Cartesian product of the table TIMESLOTS, we get couples of the form ([fst.start, fst.end], [lst.start, lst.end]) representing all the possible combinations of delimiters for the intervals included in the table. The solution will then contain intervals of the form [fst.start, lst.end]. Among all these couples, those that concern us are the ones for which it holds fst.start<lst.end, namely the left delimiter is less than the right one, and for which every person has a suitable time availability, that is for every person it exists a "covering" interval.

The reasoning may translate in SQL query:

SELECT DISTINCT fst.start, lst.end
FROM timeslots fst, timeslots lst
WHERE fst.start<lst.end
( -- number of intervals covering [fst.start, lst.end]
FROM timeslots t
WHERE t.start<=fst.start AND t.end>=lst.end
) <=
( -- number of persons in the table
FROM timeslots

the hypothesis that the intervals of a single person must be separated, in TIMESLOTS, is justified by the subquery

FROM timeslots t
WHERE t.start<=fst.start AND t.end>=lst.end

that only under such circumstances makes it possible to count the number of people who have time availability compatible with the time interval [fst.start, lst.end].

Bibliography: Vadim Tropashko, "SQL Design Patterns: Expert Guide to SQL Programming", Rampant Techpress

A minimal microcontroller based project involving serial port communication

link to a pdf file explaining a minimal microcontroller based project involving serial port communication.

how to find a Java class inside a set of jar files

These are commands to be run from the shell to locate a Java class into a set of jar files, usually in a WEB-INF/lib directory in a J2EE application server.

On Windows
Make sure to run the script from a dos console with the delayed environment variable expansion option enable, that is cmd /V:ON

The script is to be called with two arguments, the first is the folder where to search in, the second is the class name

echo off
FOR /F %%G IN ('DIR /S /B /S %1\*.jar') DO (
echo %%G
jar -tf %%G | findstr %2

On *nix
find -ls -exec sh -c '/usr/jdk1.5.0_07/bin/jar tf $1 | 
grep JavaClass.class' {} {} \;

where /usr/jdk1.5.0_07 is the path where the JDK resides and JavaClass.class is the class name to be searched