Search This Blog

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'

Followers