Search This Blog

Sunday, December 07, 2014

first birth day of Hamsini

Today, my daughter, Hamsini, successfully completed her first trip around the Sun. Many many happy returns of the day, Kushi!

It has been an awesome year with great memories. She is growing up so fast, ever curious and all smiles, busy learning new tricks, playing with her friends and toys, watching ads in the TV, listening to rhymes, helping mom in the kitchen (:-))

I can never forget how she lights up when I come back from work, how excited she is to go out, how she wants to play pick-a-boo with her mom while I am holding her in my arms. Just the other day she started walking, decided that crawling is not really her game and is now running merrily around.

Raising an infant is hard, especially in the US, because it is just the two of us who have to take care of everything. But thanks to the dear wife, I had all the fun while she did all the hard work. So, thanks and congratulations, Prasanthi!

Sunday, June 08, 2014

Setting up Canon Pixma MX870 printer on Debian Jessie

Here are the steps I followed to set up my printer (Canon Pixma MX870) on a machine running Debian Jessie.

Setup details:
My printer is connected wirelessly to the router which in turn is connected to the internet. The desktop machine running Debian Jessie is connected to the same router via ethernet cable.

1) Find out the IP address of the printer.

root@hogwarts:~# arp-scan --interface=eth1 --localnet
Interface: eth1, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.8.1 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
192.168.0.1    20:e5:64:57:f1:12    (Unknown)
192.168.0.4    e8:99:c4:4c:d0:26    (Unknown)
192.168.0.8    00:1e:8f:97:25:3d    CANON INC.

3 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.8.1: 256 hosts scanned in 1.380 seconds (185.51 hosts/sec). 3 responded


This shows that the printer's IP address is 192.168.0.8

2)  Install and start the cups service
apt-get update
apt-get install cups
/etc/init.d/cups start
I have the following packages installed but it is possible that not all of them are necessary.
root@hogwarts:~# dpkg -l cups\* | grep ^ii
ii  cups                      1.7.1-12     amd64        Common UNIX Printing System(tm) - PPD/driver support, web interface
ii  cups-bsd                  1.7.1-12     amd64        Common UNIX Printing System(tm) - BSD commands
ii  cups-client               1.7.1-12     amd64        Common UNIX Printing System(tm) - client programs (SysV)
ii  cups-common               1.7.1-12     all          Common UNIX Printing System(tm) - common files
ii  cups-core-drivers         1.7.1-12     amd64        Common UNIX Printing System(tm) - PPD-less printing
ii  cups-daemon               1.7.1-12     amd64        Common UNIX Printing System(tm) - daemon
ii  cups-filters              1.0.50-1     amd64        OpenPrinting CUPS Filters - Main Package
ii  cups-filters-core-drivers 1.0.50-1     amd64        OpenPrinting CUPS Filters - PPD-less printing
ii  cups-pdf                  2.6.1-9      amd64        PDF writer backend for CUPS
ii  cups-pk-helper            0.2.5-2      amd64        PolicyKit helper to configure cups with fine-grained privileges
ii  cups-ppdc                 1.7.1-12     amd64        Common UNIX Printing System(tm) - PPD manipulation utilities
ii  cups-server-common        1.7.1-12     all          Common UNIX Printing System(tm) - server common files
3) Add the printer
Add a user to the lpadmin group. For example, this is what I have
rajulocal@hogwarts:~$ id
uid=1000(rajulocal) gid=1000(rajulocal) groups=1000(rajulocal),24(cdrom),25(floppy),
29(audio),30(dip),44(video),46(plugdev),104(scanner),107(bluetooth),
109(netdev),122(lpadmin)
Go to http://localhost:631/ in your local browser.
Click on "Adding Printers and Classes"
Click on "Add Printer"
For some reason, "Find New Printers" did not detect the printer. 
So I used "Add Printer" to add the printer manually.
If prompted, provide the user login and password details of 
the account which you added to the lpadmin group.
In "Other Network Printers" section, select "LPD/LPR Host or Printer" and click continue
In the connection field, enter
lpd://192.168.0.8/queue
and hit continue. Replace 192.168.0.8 with your printer's IP address.
In the next screen, provide a Name, Description and Location for the printer and hit continue. I have
Name: CanonPixmaMX870
Description: Canon Pixma MX870 Color Printer with Duplexer, scanner, fax
Location: Home
In the next screen, choose
Make = Canon
hit continue
Model = Canon PIXMA MX870 - Cups+Gutenprint v5.2.9 (en)
click "Add Printer"
In the next screen, I have set 2-Sided Printing = Long Edge (Standard) and left all other options as-is. Click "Set Default Options" when finished.

4) Test the printer setup
Print a test file using lpr.
rajulocal@hogwarts:~/x$ lpr -P CanonPixmaMX870 santhi.txt
Useful links:
  • https://wiki.debian.org/SystemPrinting
  • http://www.usa.canon.com/cusa/support/consumer/printers_multifunction/pixma_mx_series/pixma_mx870#DriversAndSoftware
  • https://lists.debian.org/debian-user/2014/06/msg00318.html

Friday, April 25, 2014

digital copy for passport size photos in New York City

You can get passport size photos (in both print and digital form) for US and Canadian visas at
 
Duane Reade
1251 Avenue Of The Americas
New York, NY 10020

Ph: (212) 391-1105
 
between 49th St & 50th St + 6th ave
located underground near the subway train station

They give both paper copies and digital copy. Service is great.

I was charged $29.91 (including tax) to get 2 prints of US passport photos + 2 prints of Canada passport photos + digital copy of the images written on a CD.

Monday, March 17, 2014

book read by Anton Roth in NBC crisis show

Yesterday (2014-03-16), I watched this show called crisis on NBC ( http://en.wikipedia.org/wiki/Crisis_(TV_series) ) . In that the kid who played Anton Roth reads a book titled "Passage to Perseid". Has anyone ever heard of this book? I searched in google, amazon but could not find it anywhere. Here is a screenshot of what I am talking about


Tuesday, January 14, 2014

perl one liner to print quotes around each line

Consider the sample input file
rajulocal@hogwarts:~/x$ cat input.txt 
1.1,k
2.2,ka
3.3,kam
4.4,kama
5.5,kamar
6.6,kamara
7.7,kamaraj
8.8,kamaraju
To put quotes around each line, use the following Perl one liner
rajulocal@hogwarts:~/x$ perl -lane '$sq="\047"; print "$sq$_$sq";' input.txt 
'1.1,k'
'2.2,ka'
'3.3,kam'
'4.4,kama'
'5.5,kamar'
'6.6,kamara'
'7.7,kamaraj'
'8.8,kamaraju'
Here we are using octal code of single quote. To put quotes around just one column, use
rajulocal@hogwarts:~/x$ perl -F',' -lane '$sq="\047"; print "$F[0],$sq$F[1]$sq";' input.txt 
1.1,'k'
2.2,'ka'
3.3,'kam'
4.4,'kama'
5.5,'kamar'
6.6,'kamara'
7.7,'kamaraj'
8.8,'kamaraju'

Related posts: awk remove quotes in a column

Tuesday, December 24, 2013

cvs equivalent of "svn status"


To get output similar to "svn status" while using cvs as the version control system, run
=> cvs -n -q update
U file1
U file2
M file3
M file4
? file5
? file6
This will display files modified upstream, files modified locally, files not tracked by cvs. The output is compact and similar to the output of "svn status".

Create an alias for this in the shell rc file
=> grep cvst ~/.cshrc
alias cvst    'cvs -n -q update'
Other Alternatives:
#!/bin/sh
#------------------------------------------------------------------------------
# Approach 1
# Initial version from : http://www.freshblurbs.com/blog/2009/02/08/cvs-status-one-svn-bash-script.html
# Problem: this will not display files not part of cvs.

patterns=( 
    '?' 
    'Locally Added'
    'Locally Modified' 
    'Needs Patch'
    )

for i in "${patterns[@]}"
do
  cvs -Q status -R . | grep -i "$i"
done
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Approach 2
# Initial version from : http://www.dzone.com/snippets/doing-something-equivalent-svn
# Problem: this will not display files not part of cvs.

cvs status 2>&1 | egrep "(^\? |Status: )" | grep -v Up-to-date
#------------------------------------------------------------------------------

Tuesday, September 17, 2013

file sizes of scanned images

When I scanned a passport (roughly 40 pages == 20 scanned images) in color with 600 dpi, the file size produced by Canon Pixma MX870 is 58 Mb. The same document when scanned using Xerox WorkCentre 7765 with same settings (color, 600 dpi) produces a file size of 2.3 Mb. In terms of speed, Pixma was like a grandma while the WorkCentre is very fast.

Up until now, I never fully appreciated the power of an industrial workhorse that costs around $34000 as opposed to a good personal inkjet printer ($130 on Amazon). Wow!

Tuesday, July 09, 2013

setenv does not work from script

This post explains how to export a variable from a shell script to a tcsh parent shell.
 
consider the following script
hogwarts:~/x> cat setup_var.sh
#! /bin/tcsh -f

setenv a RAJU
echo $a
The executable bit is set on the script
hogwarts:~/x> chmod +x setup_var.sh
hogwarts:~/x> ls -al setup_var.sh
-rwxr-xr-x 1 rajulocal rajulocal 39 Jul  9 03:40 setup_var.sh
 
I am using the tcsh shell
hogwarts:~/x> echo $0
tcsh
When executed, it shows that the variable "a" is getting the correct value
hogwarts:~/x> ./setup_var.sh
RAJU
However, the variable is not exported to the parent shell even though setenv is used in the script.
hogwarts:~/x> echo $a
a: Undefined variable.
The solution is to "source the script" instead of "dot executing".
hogwarts:~/x> source setup_var.sh
RAJU
hogwarts:~/x> echo $a
RAJU
Voila! Now the variable "a" is exported to the parent shell.

Happy shell script hacking...

Thursday, June 06, 2013

shell add multiple lines EOF

To create a file with multiple lines from a shell script you can use the following recipe
rajulocal@hogwarts:~/work/tcsh$ cat add_multiple_lines_to_file.sh
#! /bin/tcsh -fx

mkdir -p ~/x
cat << EOF > ~/x/junk1
k
am
ara
ju
EOF
Run this script using
rajulocal@hogwarts:~/work/tcsh$ ./add_multiple_lines_to_file.sh
mkdir -p /home/rajulocal/x
cat
The output will be stored in ~/x/junk1
rajulocal@hogwarts:~/work/tcsh$ cat ~/x/junk1
k
am
ara
ju
For further information
  1.  read the section on "Here-documents" in http://docstore.mik.ua/orelly/unix/ksh/ch07_01.htm
  2. http://en.wikipedia.org/wiki/Here_document
  3. search for "here document" in google

Thursday, February 28, 2013

generate random numbers with a given correlation in matlab

Q. How to generate random numbers with a pre specified correlation in Matlab?

Ans. Use mvnrnd() function.This function takes mean (vector of 1xk), covariance (matrix of k x k), number of points (n). The output is an nxk matrix which corresponds to the multivariate normal distribution with the specified mean, covariance.
>> n=1000; mu=[-2,2]; sigma=[1 0.5; 0.5 1]; X = mvnrnd(mu, sigma, n);
>> size(X)
ans =
        1000           2

>> mean(X)
ans =
   -2.0350    2.0157

>> cov(X)
ans =
    0.9950    0.4898
    0.4898    0.9894

>> plot(X(:,1), X(:,2), '.')
>> grid

The problem is underspecified if only the correlation matrix is known. In this case, set the mean to a zero vector, covariance to the given correlation matrix.

Tested in MATLAB 7.14.0.739 (R2012a),  Octave 3.6.2

Thursday, February 21, 2013

append a number to a string in matlab

Problem: Given a prefix say 'foo', generate a cell array of strings in Matlab such that each string has a number appended to it.

Ans:
>> n=5; cas = cellstr([repmat('foo', n, 1), num2str([1:n]')])

cas = 

    'foo1'
    'foo2'
    'foo3'
    'foo4'
    'foo5'
 Spaces are automatically appended when the appended numbers have wider range.
>> n=10; cas = cellstr([repmat('foo', n, 1), num2str([1:n]')])

cas = 

    'foo 1'
    'foo 2'
    'foo 3'
    'foo 4'
    'foo 5'
    'foo 6'
    'foo 7'
    'foo 8'
    'foo 9'
    'foo10'
Adding another string at the top of the array is easy
>> n=10; cas = [{'raju'}; cellstr([repmat('foo', n, 1), num2str([1:n]')])]

cas = 

    'raju'
    'foo 1'
    'foo 2'
    'foo 3'
    'foo 4'
    'foo 5'
    'foo 6'
    'foo 7'
    'foo 8'
    'foo 9'
    'foo10'
which can also be done by
>> n=10; cas = cellstr([repmat('foo', n, 1), num2str([1:n]')]); cas2 = [{'raju'}; cas]

cas2 = 

    'raju'
    'foo 1'
    'foo 2'
    'foo 3'
    'foo 4'
    'foo 5'
    'foo 6'
    'foo 7'
    'foo 8'
    'foo 9'
    'foo10'

Thursday, October 11, 2012

do a grep on a column

Consider the following data
$ cat data.txt
1,fruit,apple red,spherical
2,fruit,apple green,spherical
3,vegetable,peppers green,irregular
4,vegetable,peppers yellow,irregular
5,vegetable,peppers red,irregular
6,vegetable,broccoli,irregular and green
7,plant,green spinach,leaves
8,plant,very green spinach,leaves
9,plant,verygreenspinach,leaves
10,seed,green pea,spherical
11,unknown,green,undefined
The problem is to filter the lines where the third field ends in the word green. So the output should be
2,fruit,apple green,spherical
3,vegetable,peppers green,irregular
Short answer:- use awk with regular expression support
$ awk -F"," '{if ($3 ~ /\sgreen$/) print $0}' data.txt
2,fruit,apple green,spherical
3,vegetable,peppers green,irregular
Long answer:-
Naive use of grep gives a lot of false positives.
$ grep green data.txt
2,fruit,apple green,spherical
3,vegetable,peppers green,irregular
6,vegetable,broccoli,irregular and green
7,plant,green spinach,leaves
8,plant,very green spinach,leaves
9,plant,verygreenspinach,leaves
10,seed,green pea,spherical
11,unknown,green,undefined
line6 should not be printed as the word green appears in the 4th column (and not the 3rd).

lines 7,8,10 has the word green in the 3rd field. But they should not be printed since green does not appear at the end.

line9 - the letters green are present in the third field but is not preceded by a space, so should not be printed.

line 11 is most likely a data error. The third field has the word green but is not associated with any fruit, vegetable, plant etc.,


Further, to print all the spherical objects, one can use
$ awk -F"," '{if ($4=="spherical") print $0}' data.txt
1,fruit,apple red,spherical
2,fruit,apple green,spherical
10,seed,green pea,spherical
Here a full match on the 4th field is performed. However, this trick cannot be extended to the present problem as only partially matches on the third field are desired.

How the solution works:-
$ awk -F"," '{if ($3 ~ /\sgreen$/) print $0}' data.txt 
~       tests for a match
/ ... /  delimiters of the regular expression
\s       test for space
$        test for end of field

Tested on Debian Wheezy using
$ awk --version
GNU Awk 4.0.1
Copyright (C) 1989, 1991-2012 Free Software Foundation.

Thursday, August 23, 2012

kill all the open figures in matlab

The following function can be used to kill all the open figures in Matlab

function kill_figures
  % close all open figures
  delete(findall(0,'Type','figure'));
end
This function comes in handy when doing parametric studies. Say, there is a big chunk of code that generates 10 figures per run. In order to study the effect of a parameter for say 5 cases, we end up generating 50 (=5x10) plots. Once the study is done, this function comes in handy to kill all those figure windows.

Related tips:

To get the handles of all the figures, do
figHandles = findall(0, 'Type', 'figure');


Sunday, June 24, 2012

specify rsync location

If rsync fails with the following error,
$ /usr/bin/rsync -prltvzD user@machine.com:~/file.csv . -n
rsync: Command not found.
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(601) [Receiver=3.0.7]
the problem could be due to the non-standard location of rsync on the remote machine. For example, in this case, rsync was installed at /usr/local/bin/rsync on the remote machine. This location can be specified by using the "rsync-path" option. The following command succeeds.
$ /usr/bin/rsync -prltvzD --rsync-path=/usr/local/bin/rsync user@machine.com:~/file.csv . -n
receiving file list ... done

sent 20 bytes  received 58 bytes  3.47 bytes/sec
total size is 11473183  speedup is 147092.09 (DRY RUN)

Sunday, June 10, 2012

eBay should make the winning bid stick for at least an hour

Dear eBay[1],

In the current bidding process, the auction ends at a particular time which gives unnecessary importance to it. This can be evidenced by a lot of inactivity at the beginning and a frenzy of activity at the very end.

Eliminating this "auction-ending-time arbitrage" (AETA from now on) is very simple and easy. Just make each "winning bid" stick for at least an hour. If necessary, extend the "auction ending time" further.

You can be even more creative by providing this chance only to the previous "winning bidders". I will let your strategy team work out the finer details. But the underlying idea is very simple. You need to provide a better way for others to re-participate in the auction.

If you think I can be of further assistance, ping me kamaraju at gmail dot com.


Why is this such a big deal?

To be honest, the current system sucks. It is very easy to be outbid at the very last minute by a tiny amount.  There is not enough time left to reenter the bidding process when it happens. This can be very frustrating for the current winning bidder especially if he/she is leading the race for the last couple of days/hours. These winning bidders deserve a second chance to rebid and reparticipate in the auction.

This is not a big issue for items with a lot of bidders (high liquidity). But for items with a very few bidders (illiquid, niche items), the suggested improvement provides a good price discovery mechanism.

When you have a good price discovery platform, the sellers will be more inclined to use eBay resulting in more revenue. So it is a win-win for both eBay and its customers.

References:
  1. www.ebay.com
PS:- I have arbitrarily chosen the "sticky period" as one hour. But in reality, it can be any reasonable choice.

PPS:- If any one else agrees with me, go to http://pages.ebay.com/help/account/suggestions.html , click on the "Buying and searching" link, fill the form and make this suggestion to eBay.

Followers