Node.js

Override console.log locally

To override console.log for local debugs:
function connectionLog(...args)
{
    console.log("[WebSocket]", ...args);
}
Add some colors and flexibility:
require('terminal-colors')
const logPrefix = '[WebSocket]'.lightBlue;
function connectionLog(...args)
{
    console.log(logPrefix, ...args);
}

Selenium: Turn off "--ignore-certificate-errors" flag

The Selenium Chrome Driver calls Chrome with flag
--ignore-certificate-errors
which is not supported starting from Chrome 35.
To turn this off for Node.js driver you can add "--test-type" argument.
Short code (CoffeeScript/JavaScript):
webdriver = require('selenium-webdriver')
webdriverChrome = require('selenium-webdriver/chrome')
chromeOptions = new webdriverChrome.Options()
chromeOptions.addArguments("--test-type")
caps = webdriver.Capabilities.chrome()
caps.set('chromeOptions', chromeOptions)

driver = new webdriver.Builder().
   withCapabilities(caps).
   build()

C

8 - bit reverse in ANSI C

Clean and fast way to reverse 8 bits.
static unsigned char bitReverseU8(unsigned char x)
{
    x = ((x & 0xaa) >> 1) | ((x & 0x55) << 1);
    x = ((x & 0xcc) >> 2) | ((x & 0x33) << 2);
    x = ((x & 0xf0) >> 4) | ((x & 0x0f) << 4);
    return x;
}

Log timestamp in linux

Log the time:
struct timeval time;
gettimeofday(&time, NULL);
printf("---[%ld:%03ld]\n", time.tv_sec, time.tv_usec / 1000);

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'));

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>
JavaScript failed !
So this is static version of this website.
This website works a lot better in JavaScript enabled browser.
Please enable JavaScript.