Java

simple map iterator

Two versions of Java map iterators.
The good old while-hasNext like way:
Iterator<Map.Entry<Key, Value>> it = theMap.entrySet().iterator();
while (it.hasNext())
{
    Map.Entry<Key, Value> entry = it.next();
    Logger.print(entry.getKey().someMethod() + :  + entry.getValue().someMethod());
}
or the modern for-each way:
for (Map.Entry<Key, Value> entry: theMap.entrySet())
{
}
depending of VM version and implementation, they can have different or equal performance, so be careful.

Ant: copy some files from non-flat dirs to one flat dir

A piece of ant script, which would copy all *.txt and all *.jks files from different directories and subdirectories to one flat directory.
This uses regexp mapper to delete directory part of paths to found files.
<!-- copy non-compiled files (e.g. class resources) if needed -->
<copy todir="${bin.dir}" verbose="true">
    <fileset dir="${workspace}">
        <include name="**/src*/**/*.txt"/>
        <include name="**/src*/**/*.jks"/>
    </fileset>
    <mapper type="regexp" from="^([^/]+)/([^/]+)/(.*)$$" to="\3"/>
</copy>

PHP

Storing a file from a remote url to the local dir

The PHP 5 way of saving remote file (by http URL) to the local dir.
file_put_contents('the.jpg',  file_get_contents('http://mysite.com/the.jpg'));
this is yosh personal site,
which of purpose is not precisely described...
© 2007 - 2012 by Kemu
All rights reserved
code & design: KEMU
contact: ss@ke.mu
generation: 525 ms