Tuesday, May 16, 2017

Converting JSON to LCOV (infofile)

Wrote a small NPM module that converts JSON to LCOV data


Tuesday, May 9, 2017

Install Cpanm module error : No such file or directory opening compressed index

system$ HOME=/tmp /home/perl/5.10/bin/cpanm REST::Client
! Finding REST::Client on cpanmetadb failed.
! cannot open file '/tmp/.cpanm/sources/http%www.cpan.org/02packages.details.txt.gz': No such file or directory opening compressed index
! Couldn't find module or a distribution REST::Client



The problem is because of "LWP::Protocol::https" module.

Removing the directory worked for me :

/home/perl/5.10/lib/site_perl/5.10.1$ rm –rf LWP*

or try with option "--no-lwp"

Example: cpanm REST::Client --no-lwp

Error while installing Perl 5.10.1

 Error while installing Perl 5.10.1

a -Wdeclaration-after-statement -Wendif-labels -Wc++-compat 
cc -fstack-protector -L/usr/local/lib -o miniperl \
      gv.o toke.o perly.o pad.o regcomp.o dump.o util.o mg.o reentr.o mro.o hv.o av.o run.o pp_hot.o sv.o pp.o scope.o pp_ctl.o pp_sys.o doop.o doio.o regexec.o utf8.o taint.o deb.o universal.o xsutils.o globals.o perlio.o perlapi.o numeric.o mathoms.o locale.o pp_pack.o pp_sort.o  \
    miniperlmain.o opmini.o perlmini.o 
pp.o: In function `Perl_pp_pow':
pp.c:(.text+0x2d79): undefined reference to `pow'
pp.o: In function `Perl_pp_modulo':
pp.c:(.text+0x3b22): undefined reference to `floor'
pp.c:(.text+0x3b58): undefined reference to `floor'
pp.c:(.text+0x3b90): undefined reference to `fmod'
pp.o: In function `Perl_pp_atan2':
pp.c:(.text+0x8985): undefined reference to `atan2'
pp.o: In function `Perl_pp_sin':
pp.c:(.text+0x8b22): undefined reference to `sin'
pp.o: In function `Perl_pp_int':
pp.c:(.text+0x8fc1): undefined reference to `floor'
pp.c:(.text+0x9031): undefined reference to `ceil'
pp.o:(.rodata+0x120): undefined reference to `cos'
pp.o:(.rodata+0x128): undefined reference to `sin'
pp.o:(.rodata+0x130): undefined reference to `sin'
pp.o:(.rodata+0x138): undefined reference to `exp'
pp.o:(.rodata+0x140): undefined reference to `log'
pp.o:(.rodata+0x148): undefined reference to `sqrt'
pp_pack.o: In function `S_pack_rec':
pp_pack.c:(.text+0x740b): undefined reference to `floor'
pp_pack.c:(.text+0x742e): undefined reference to `floor'
pp_pack.c:(.text+0x7453): undefined reference to `floor'
collect2: error: ld returned 1 exit status
makefile:347: recipe for target 'miniperl' failed

make: *** [miniperl] Error 1

This link helped me to find what i was missing: https://rt.perl.org/Public/Bug/Display.html?id=55980

and finally this worked for me

Step 1: find your lib path which has all libm* files
In most systems it will be under /usr/lib64. Search for the files in your system. 
system:/usr/lib64 $ ls libm*
libm.a         libmcheck.a     libmenuw.so.5    libmpc.so.3.0.0    libmpfr.so.4  libmpx.so.0.0.0      libm.so         libmvec.a
libmagic.so.1      libmenu.so.5    libmenuw.so.5.9  libmpdec.so.2      libmpfr.so.4.1.4  libmpxwrappers.so.0      libmspack.so.0      libmvec_nonshared.a
libmagic.so.1.0.0  libmenu.so.5.9  libmpc.so.3      libmpdec.so.2.4.2  libmpx.so.0   libmpxwrappers.so.0.0.0  libmspack.so.0.1.0  libmvec.so
Step 2: Use the path with glibpth option while doing configure
./Configure -des -Dglibpth='/lib/lib64 /usr/lib64'
or I see some forums suggested plibpth
./Configure -des -Dplibpth='/lib/lib64 /usr/lib64' -Dglibpth='/lib/lib64 /usr/lib64' -Dlibpth='/lib/lib64 /usr/lib64'

I have answered the same here :  http://stackoverflow.com/a/43878868/453486

Friday, April 28, 2017

How to place Perl modules in non-standard locations and use it

If this is the project structure,

    -- Libary2.pm   

    -- file1.pl  
    -- file2.pl  
    -- Libary1.pm    

In `file1.pl`, we can include both libraries by,

    use lib '/home/directory/project';
    use lib '/home/directory/lib';


    #include both directory at once, 

    use lib qw(
    use Libary1;
    use Libary2;

`file2.pl`, will have the same path,

    use lib qw(
    use Libary1;
    use Libary2;

The above code is good for 1 or 2 files. But if there are 10+ perl files, we have to include the same lib path in all files. If the library path changes, we had to change all files with the correct path name.
So what I did was to have 1 module `config/LibPaths.pm` that will have the paths, and all files will include the module.

    -- Libary2.pm 

    -- file1.pl
    -- file2.pl
    -- Libary1.pm  

    -- LibPaths.pm 

In `LibPaths.pm`

    package LibPaths;
    use lib qw(

and I include the `LibPaths.pm` module In `file1.pl` as follows

    use File::Basename;
    use Cwd qw(abs_path);
    use lib dirname (abs_path(__FILE__)) . "/config";
    use LibPaths;

-   `use Cwd qw(abs_path)` is needed to get the current file.
-   `use lib dirname (abs_path(__FILE__))` will get the directory name of the current file
-   `use lib dirname (abs_path(__FILE__)) . "/config";` will include the config folder. I liked to put the `LibPaths.pm` under a config directory and my project has 50+ files. But If the module is in same directory, including config is not needed.

**So now when the library paths changes, I can update in 1 place which is `LibPaths.pm` **

There are other Perl modules like “FindBin” which will serve this purpose, But I didnt want to introduce a new dependency in my project. So I followed the above hack. I might be an ugly hack, but it works :D


Monday, April 24, 2017

How to private chat using node.js and socket.io

Create a room with conversation_id and make users to subscribe to that room, 
so that you can emit a private message to that room it by,

var socket = io.connect('http://ip:port');

socket.emit('subscribe', conversation_id);

socket.emit('send message', {
    room: conversation_id,
    message: "Some message"

socket.on('conversation private post', function(data) {
    //display data.message

socket.on('subscribe', function(room) {
    console.log('joining room', room);

socket.on('send message', function(data) {
    console.log('sending room post', data.room);
    socket.broadcast.to(data.room).emit('conversation private post', {
        message: data.message

Here is my Stackoverflow answer : http://stackoverflow.com/a/23623724/453486