By: Kevin T. Duraj, Los Angeles, California

Send each text lines as parameters to bash

Bash script executes on each line from text file as parameter passed into bash.

#-- text.txt --#
one
two
three

#-- receiver.sh --#
#!/bin/bash
echo "Line="$1

# -- execute ---#
cat text.txt | xargs -n1 ./receiver.sh

#-- output --#
Line=one
Line=two
Line=three

Perl how to use constants

package header;
#-----------------------------------------------#
use strict;
use warnings;
#-----------------------------------------------#
our @ISA    = qw( Exporter );
our @EXPORT = qw( APPLE PEAR );
#-----------------------------------------------#
use constant
{
    APPLE => "good",
    PEAR  => "tasty"
};
#-----------------------------------------------#
1;

#!/usr/bin/perl
#-----------------------------------------------#
use strict;
use warnings;
use header;
#-----------------------------------------------#
print "APPLE = " . APPLE . "\n";
print "PIER  = " . PEAR  . "\n";
#-----------------------------------------------#
__END__

Add INDEX IGNORE duplicates

UPDATE mytable SET myfield = LOWER( myfield );
ALTER IGNORE TABLE mytable ADD PRIMARY KEY ( myfield );

Reference: MySQL
http://dev.mysql.com/doc/refman/5.1/en/create-index.html

Count Slash Characters

echo -n "http://pacific-design.com/wp-admin/post.php" | tr -cd  "/" | wc -c

#output = 4

Database Management in PERL

#!/usr/bin/perl

use DBI
use strict;

  my $driver = "mysql";
  my $database = "TESTDB";
  my $dsn = "DBI:$driver:database=$database";
  my $userid = "testuser";
  my $password = "test123";
  my $dbh = DBI->connect($dsn, $userid, $password )
              or die $DBI::errstr;

 my $first_name = "john";
 my $last_name = "poul";
 my $sex = "M";
 my $income = 13000;
 my $age = 30;
 my $sth = $dbh->prepare("INSERT INTO TEST_TABLE
                          (FIRST_NAME, LAST_NAME, SEX, AGE, INCOME )
                           values
                          (?,?,?,?)");
 $sth->execute($first_name,$last_name,$sex, $age, $income)
             or die $DBI::errstr;
 $sth->finish();
 $dbh->commit or die $DBI::errstr;

Reference: http://www.tutorialspoint.com/perl/perl_database.htm

Starting with Android

Android SDK Starter Package
Reference:
http://developer.android.com/sdk/installing.html

Changing default text editor to VIM

sudo update-alternatives --config editor


  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
* 3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    10        manual mode

Bash Escape and Replace String

#!/bin/bash
# How to escape and replace string path in file

# escape string to \/home\/kevin\/data
BASE='/home/kevin/data'
ESCAPED=`echo $BASE | sed -e 's/\//\\\\\//g'`

# replace escaped string using sed
echo "ESCAPED="$ESCAPED
sed -i "s/path/$ESCAPED/" data_file.txt

Map Reduce Algorithms

Our world is being revolutionized by data-driven methods: access to large amounts of data has generated new insights and opened exciting new opportunities in commerce, science, and computing applications. Processing the enormous quantities of data necessary for these advances requires large clusters, making distributed computing paradigms more crucial than ever. MapReduce is a programming model for expressing distributed computations on massive datasets and an execution framework for large-scale data processing on clusters of commodity servers. The programming model provides an easy-to-understand abstraction for designing scalable algorithms, while the execution framework transparently handles many system-level details, ranging from scheduling to synchronization to fault tolerance. This book focuses on MapReduce algorithm design, with an emphasis on text processing algorithms common in natural language processing, information retrieval, and machine learning.

References:
Jimmy Lin
http://www.umiacs.umd.edu/~jimmylin/book.html

Power law

power law is a special kind of mathematical relationship between two quantities. When the number or frequency of an object or event varies as a power of some attribute of that object (e.g., its size), the number or frequency is said to follow a power law. For instance, the number of cities having a certain population size is found to vary as a power of the size of the population, and hence follows a power law. The distribution of a wide variety of natural and man-made phenomena follow a power law, including frequencies of words in most languages, frequencies of family names, sizes of craters on the moon and of solar flares, the sizes of power outages, earthquakes, and wars, the popularity of books and music, and many other quantities.

Reference: http://en.wikipedia.org/wiki/Power_law