Count the number of occurrences of a word in a file in vim

May 29, 2013
:%s/./&/gn		characters
	:%s/\i\+/&/gn		words
	:%s/^//n		lines
	:%s/the/&/gn		"the" anywhere
	:%s/\<the\>/&/gn	"the" as a word
Advertisements

cant locate json.pm

May 22, 2013
$ sudo cpan JSON

Important Perl Libraries to know

May 22, 2013
  1. http://search.cpan.org/dist/URI/URI/Escape.pm
  2. http://search.cpan.org/~gaas/libwww-perl-6.05/lib/LWP/Simple.pm
  3. http://perldoc.perl.org/Data/Dumper.html

Perl Crash Course – demystifying and painless

May 21, 2013
  1. Arrays are started with @ 
  2. Scalars are started with $. A scalar may be a string or an integer,
    1. $x[0] = 15; # don’t have to warn Perl that x is an array first

    2. 2  $x[1] = 16;

    3. 3  $y = shift @x; # “output” of shift is the element shifted out

    4. 4  print $y, “\n”; # prints 15

    5. 5  print $x[0], “\n”; # prints 16

    6. 6  push(@x,9); # sets $x[1] to 9

    7. 7  print scalar(@x), “\n”; # prints 2

    1. 8  print @x,

    2. 9  $k=@x;

    3. 10  print $k,

    4. 11  @x=();

    5. 12  print scalar(@x), “\n”; # prints 0

    6. 13  @rt = (’abc’,15,20,95);

    7. 14  delete $rt[2]; # $rt[2] now = undef

    8. 15  print “scalar(@rt) \n”; # prints 4

    9. 16  print @rt, “\n”; # prints abc1595

    10. 17  print “@rt\n”; # prints abc 15 95, due to quotes

    11. 18  print “$rt[-1]\n”; # prints 95

    12. 19  $m = @rt;

    13. 20  print $m, “\n”; # prints 4

    14. 21  ($m) = @rt; # 4-element array truncated to a 1-element array

    15. 22  print $m, “\n”; # prints abc 

      1. @z = (5,12,13,125);
            @w = @z[1..3]; # @w will be (12,13,125)
            @q = @z[0..1]; # @q will be (5,12)
            @y = @z[0,2]; # @y will be (5,13)
            @w[0,2] = @w[2,0]; # swaps elements 0 and 2
            @g = @z[0,2..3];  # can mix "," and "..."
            print "@g\n"  # prints 0 13 125
        

     

    References : http://heather.cs.ucdavis.edu/~matloff/Perl/PerlIntro.pdf

     


Tools used to examine compiler output in C++

May 16, 2013
  •  nm (or objdump -t) to list the symbol table from an a.out or .so file
  • nm –format sysv simple

http://www.cs.swarthmore.edu/~newhall/unixhelp/compilecycle.html


Calling existing C++ libraries from Java using JNI

May 15, 2013

You don’t “convert C++ file to java style”. You need to create a JNI wrapper around your existing C++ code. This JNI wrapper is actually C++ code that can be called by Java.

By wrapper I mean that you shouldn’t have to modify your existing C++ code base. This wrapper, or better said this binding should generally be very thin. The wrapper code is only meant to expose existing functionalities, not to implement them. It is better to leave the implementation in the (portable) C++ code base.

If the code base isn’t too large, then I recommend that you write this wrapper by hand, as explained inThe JavaTM Native Interface Programmer’s Guide and Specification

Now, if you are trying to bind a large library, it may be problematic. So, in regard to tools, I haven’t used that, but have a look at SWIG, and the relevant SWIG Java documentation.

According to the homepage description, it’s what you’re asking for:

SWIG is typically used to parse C/C++ interfaces and generate the ‘glue code’ required for [Java, Python, PHP, …] to call into the C/C++ code.

javah can be useful in certain cases, but it’s not what you ask for. It extracts JNI boiler plate code out of native declarations found in Java classes.


Reading and Writing Hive data from Map Reduce

May 14, 2013
  1. http://www.nearinfinity.com/blogs/stephen_mouring_jr/2013/01/04/reading-hive-tables-from-mapreduce.html
  2. Chained Map Reduce Jobs
  3. MultipleInput and Multiple Output – chained mapper and chained reducer