Sunday, 14 April 2013

Atheros: Share Internet Connection via WiFi in XP

Say that your computer (running Windows XP) is connected to internet via LAN and you wanted to the connection to other devices via WiFi.
1. Goto control panel -> Network Connections.
2. Right-click on the Local Area Connection and choose Properties.
3. In the Advanced Tab under the Internet Connection Sharing, enable "Allow other users to connect through this computer's internet connection".

The next part is to create an adhoc wifi connection. My netbook comes with an Atheros wireless network adapter. So I am using Atheros Client Utility to configure wireless connections. You may use Windows XP's default tool as well.
1. Open Atheros Client Utility.
2. Under Profile Management tab, click New.
3. Fill in the profile name and give an name for identifying the wifi connection under the SSID1.
4. In the Advanced tab, change network type to Ad-Hoc.
5. In the Security tab, choose Pre-Shared Key (Static WEP) and click Configure.
6. In the popup menu, choose ASCII Text for Key Entry and give a password in the Encryption Keys section for WEP Key 1 (one would be enough). Depending on the chosen WEP Key Size, the length of the key varies.
7. Click Ok and finish the configurations.
8. Back in the Profile Management, choose the currently created profile and click Activate.

Now you can connect to the internet via the newly created Ad-Hoc WiFi connection. To connecting to the network, you need to enter the same password given for the WEP key in step 6 above.

Tuesday, 2 April 2013

Immediately-Invoked Function Expression (IIFE) in Groovy & JavaScript

Immediately invoked function expressions are anonymous function blocks executed soon at the end of the block giving the return value. IIFEs are very common in JavaScript.
// IIFE in js
(function(arg) {
    if (arg === 1)
        return "one";
    else
        return "not one";
})(1);
In Groovy the same thing can be done using anonymous blocks which the language names as 'closure'. It is not the lexical closure that we are talking about, though it can be. The 'Closure' in Groovy is just a block of code.
Anyway we can have an IIFE in groovy using blocks and invoking it at the end of the block as shown below. Since the evaluated value is returned, we can omit the return statement.
// IIFE in Groovy
{arg ->
    if (arg == 1)
        "one"
    else
        "not one"
}(1)