Pages

Tuesday, 17 December 2013

Change Mouse Icon in XFCE 4

Just installed brand new Debian Wheezy x86_64 with XFCE 4 on my 2010 model netbook having an Intel Atom processor. XFCE is fast and is less resource hungry. As it's the case with much of the distros, the UI themes are not so very eye-candy. So, in the process of making it look more beautiful, I got stuck with not being able to change the mouse pointer icon. The interesting thing is that rest of the mouse icon type changes. Also when I am within Firefox, I can see the updated icon. Everywhere else I get the default adwaita icon. Fixing this is simple.
cd /usr/share/icons     # cd to global icons dir
sudo rm default         # remove if default exists
# create a symlink setting oxy-neon (which is the name of the folder containing mouse icon theme) as the default mouse theme
sudo ln -s oxy-neon default
Choose Mouse option from Applications Menu -> Settings and select the Theme tab and choose Default as the pointer. Logout and the new mouse theme appears.

Sunday, 8 December 2013

Running LFE in Windows

Building LFE (Lisp Flavoured Erlang) does not seem to work in Windows. Running make gives the following error.
rebar was unexpected at this time.
make: *** [compile] Error 255
However, if you have access to a GNU/Linux system, you can build it there, get the .beam files inside the ebin directory over to Windows, which can be loaded by the EVM running on Windows.
Say you placed it under C:\lfe-ebin, open the Erlang shell and run the following
1> cd("c:/lfe-bin").
c:/lfe-bin
ok
2> lfe_shell:start().
LFE Shell V5.10.3 (abort with ^G)
<0.331.0>
>
Enjoy!

Thursday, 5 December 2013

Fun with FizzBuzz

Here is my shortest Groovy version of FizzBuzz in 62 characters and legible.
(1..100).each{println"${it%3?'':'Fizz'}${it%5?'':'Buzz'}"?:it}
JavaScript version in 66 characters, but a bit convoluted.
i=0;while(i++!=100)console.log((i%3?'':'Fizz')+(i%5?'':'Buzz')||i)

Sunday, 1 December 2013

Groovy Parallel and Async Tasks with GPars

Groovy is a very pragmatic language. It keeps ceremony to the minimum while taking advantage of the mighty JVM and the Java platform. The GPars library is a convenient way to run computations in parallel, async or concurrent. The same thing can be achieved to an extend with plain Java with the java.util.concurrent.* classes. An article by Edgardo Hernandez demonstrates the usage with Java. Let's use Groovy and GPars to do something similar.
import groovyx.gpars.GParsPool

public class Task {
    def compute(int msg) {
        String str = "";
        long begTest = new java.util.Date().getTime();
        System.out.println("start - Task "+ msg);
        try {
            Thread.sleep(1000);
            for(int i = 0; i < 20000; i++)
                str = str + 't';
        } catch (InterruptedException e) {}
        Double secs = new Double((new java.util.Date().getTime() - begTest)*0.001);
        System.out.println("run time " + secs + " secs");
        return msg;
    }
}

final def task = new Task()
def seq = {
    println "sequential"
    long b = new Date().getTime()
    (1..5).each {
        task.compute(it)
        long e = new Date().getTime()
        println e-b
    }
}()

println "\nparallel"
GParsPool.withPool { //pool size will be automatically computed (if nothing is specified).
    long b = new Date().getTime()
    (1..5).eachParallel { // executes each block in parallel and statement within the block sequentially.
        task.compute(it)
        long e = new Date().getTime()
        println e-b
    }
}

println "\nasync (demo)"
long start = new Date().getTime()
// Say we have few tasks that needs to be computed asynchronously while doing other computations.
def a = {task.compute(1)} // define the tasks in a block
def b = {task.compute(2)}
def c = {task.compute(3)}
def d = {task.compute(4)}
def e = {task.compute(5)}
def results = GParsPool.withPool {
    [a,b,c,d,e]*.callAsync() // perform the tasks in the background
}
// continue with other tasks..
results*.get() // now we need the results to continue further. Get the result (if not done yet, it waits till done).
// do further computation with the obtained results..
long stop = new Date().getTime()
println stop-start
This can be run using groovyConsole. GPars must be in the classpath or included using grapes. In my test system having dual cores, the time taken are around 10375ms, 6578ms, 6234ms for sequential, parallel, and async tasks respectively. In a single core atom processor the average time for 3 runs are as 13792ms, 10771ms and 9078ms respectively.