Search This Blog

Monday, September 03, 2007

initializing multi dimensional arrays in octave

In octave, multi dimensional arrays can be initialized using the reshape function. As an example, consider the following script.

$cat multidimensional_array.m
1;
a = zeros(1, 24);
for i=1:24
a(i) = i;
end
a
b = reshape(a, [4 3 2])

The output looks as follows

$octave -q
octave:1> multidimensional_array
a =

Columns 1 through 16:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Columns 17 through 24:

17 18 19 20 21 22 23 24

b =

ans(:,:,1) =

1 5 9
2 6 10
3 7 11
4 8 12

ans(:,:,2) =

13 17 21
14 18 22
15 19 23
16 20 24



octave:2>

Wednesday, August 29, 2007

thecarpcstore website is down

$date
Wed Aug 29 13:16:35 EDT 2007

In case you do not know, the support forum for complainterator hosted at http://thecarpcstore.com/phpbb2/ is currently down due to a massive DDoS attack. This is the second time spammers have DDoSed complainterator forums. On a positive side, this shows what an enormous effect complainterator reports are having in shutting down spammer's websites. Good job complainterator! You rock!

Related Links :
  • http://complainterator.com/news.html
  • http://weblog.complainterator.com/

Tuesday, August 14, 2007

gmail and orkut got hacked or what?

$ date -R
Tue, 14 Aug 2007 20:34:30 -0400

Am I seeing this correctly? Did someone really manage to hack into google's servers? Some of google's popular websites such as gmail, Orkut seem to be down. I assume it is a temporary problem (a DDOS attack?). Whatever it is, it is impressive to see some non-english garbage on these popular websites.

Oh, I almost forgot, here are the screenshots for posterity :-)


Tuesday, July 17, 2007

tabs inside krusader

Krusader is a very nice file manager with lots of features. One thing that I find useful everyday is its ability to have multiple directories in different tabs. The following screenshot shows the location of these tabs in both the panes.




Here I am using Debian Etch (Stable), Qt: 3.3.7, KDE: 3.5.5, Krusader: 1.70.1 "Round Robin" . The above screenshot is produced by ksnapshot, edited by kolourpaint.

Thursday, June 21, 2007

Special shell variables in bash

Bash defines some special variables which are useful while writing shell scripts. They are

$0 = Filename of script
$1 = Positional parameter #1
$2 - $9 = Positional parameters #2 - #9
${10} = Positional parameter #10
$# = Number of positional parameters
"$*" = All the positional parameters (as a single word)[*]
"$@" = All the positional parameters (as separate stings)
${#*} = Number of command line parameters passed to script
${#@} = Number of command line parameters passed to script
$? = Return value
$$ = Process ID (PID) of the script
$- = Flags passed to script (using set)
$_ = Last argument of previous command
$! = Process ID (PID) of last job run in background

[*] Must be quoted, otherwise it defaults to "$@"

Reference :- Appendix B of "Advanced Bash-Scripting guide" by Mendel Cooper, Version 5.0. Debian users can get this document by installing the abs-guide package.

sudo apt-get install abs-guide

The necessary files can be found in /usr/share/doc/abs-guide . However, the abs-guide package contains only the html version of the document. A pdf version can be downloaded from http://www.tldp.org/LDP/abs/abs-guide.pdf .

Tuesday, June 12, 2007

which manpage am I looking at?

Q. which manpage am I looking at?
A.

man -w keyword

gives the filename of the manpage that would be displayed when

man keyword

is entered at the commandline.

To get a list of all plausible manpages use

man -aw keyword

The -w option works for info also.

Q. which info page am I using?
A.

info -w keyword

gives the path of the info file that would have been displayed if the command "info keyword" is used.

Ref :- The manpages of man, info!

Tuesday, June 05, 2007

Stapling paper

When stapling a bunch of letter or a4 sized sheets, staple sizes can be chosen using the following table.

Number of sheets Stack height Staple size
25 1/8'' 1/4''
60 1/4'' 3/8''
90 5/16'' 1/2''
160 9/16'' 3/4''

I assumed the thickness of paper is roughly around 0.1 mm (which might not always be correct!).

Disclaimer: The above info is just a guideline. Use it at your own risk. I am not responsible for any losses that you may incur due to using it.

Tuesday, May 15, 2007

updating texmacs to new upstream release

As of Tue, May 15, 2007 Debian contains the following versions of Texmacs.

Stable (Etch) : 1:1.0.6-10
Testing (Lenny) : 1:1.0.6-11
Unstable (Sid) : 1:1.0.6.9-4

On my system, I am using Debian Etch, texmacs 1.0.6.9-2. Couple of days back, texmacs released 1.0.6.10. As a maintainer of this package, I want to build the 1.0.6.10 package which can eventually be uploaded to Debian Sid. This document provides a recipe of commands to achieve this goal.

Here I assumed that you are using pdebuild for the first time. If you have used it before, skip the appropriate steps.

$cp /usr/share/doc/pbuilder/examples/pbuilder-distribution.sh ~/bin/pbuilder-sid
$mkdir -p ~/pbuilder/result
$sudo aptitude install cdebootstrap
$pbuilder-sid create # if second time, use 'pbuilder-sid update'

$cat ~/bin/pdebuild-distribution.sh
#!/bin/sh

DISTRIBUTION=`basename $0 | cut -f2 -d '-'`
BASE_DIR="$HOME/pbuilder"
pdebuild --buildsourceroot fakeroot \
--buildresult $BASE_DIR/result \
--auto-debsign \
-- --basetgz $BASE_DIR/$DISTRIBUTION-base.tgz \
--distribution $DISTRIBUTION $@

$cp ~/bin/pdebuild-distribution.sh ~/bin/pdebuild-sid
$chmod +x ~/bin/pdebuild-sid

$cd ~/practice/

Obtain the latest source from texmacs website

$wget ftp://ftp.texmacs.org/pub/TeXmacs/targz/TeXmacs-1.0.6.10-src.tar.gz

Rename the upstream sources

$tar xzvf TeXmacs-1.0.6.10-src.tar.gz -C .
$mv TeXmacs-1.0.6.10-src texmacs-1.0.6.10
$tar czvf texmacs_1.0.6.10.orig.tar.gz texmacs-1.0.6.10
$rm -rf TeXmacs-1.0.6.10-src.tar.gz texmacs-1.0.6.10
$ls texmacs*
texmacs_1.0.6.10.orig.tar.gz

Obtain the latest sources available in Debian Sid

wget http://ftp.debian.org/debian/pool/main/t/texmacs/texmacs_1.0.6.9.orig.tar.gz
wget http://ftp.debian.org/debian/pool/main/t/texmacs/texmacs_1.0.6.9-4.dsc
wget http://ftp.debian.org/debian/pool/main/t/texmacs/texmacs_1.0.6.9-4.diff.gz

Create the corresponding Debian source for 1.0.6.10

$dpkg-source -x texmacs_1.0.6.9-4.dsc
$cd texmacs-1.0.6.9/
$uupdate -u ../texmacs_1.0.6.10.orig.tar.gz
New Release will be 1:1.0.6.10-1.
-- Untarring the new sourcecode archive ../texmacs_1.0.6.10.orig.tar.gz
Success! The diffs from version 1:1.0.6.9-4 worked fine.
Remember: Your current directory is the OLD sourcearchive!
Do a "cd ../texmacs-1.0.6.10" to see the new package
$cd ..
$rm -rf texmacs-1.0.6.9/

Update the changelog and do other necessary stuff

$cd texmacs-1.0.6.10/debian/
$dch
...
$cd ..
...

Build the package. The final packages will be in ~/pbuilder/result

$pdebuild-sid
$cd ~/pbuilder/result
$ls texmacs*1.0.6.10*
texmacs_1.0.6.10-1.diff.gz texmacs_1.0.6.10-1_i386.changes texmacs_1.0.6.10.orig.tar.gz
texmacs_1.0.6.10-1.dsc texmacs_1.0.6.10-1_i386.deb texmacs-common_1.0.6.10-1_all.deb
$linda texmacs_1.0.6.10-1.dsc
$lintian texmacs_1.0.6.10-1.dsc

Tuesday, April 24, 2007

gnuplot with GNU readline and history support

By default, the gnuplot packages in Debian are not built with libreadline (GNU readline). This is due to licensing issues (see /usr/share/doc/gnuplot/README.Debian for more info). Having the libreadline support is useful as it enables tab completion of file names inside gnuplot. Using GNU readline, one can also access the commands used in previous gnuplot sessions. The recipe for recompiling the gnuplot packages (in the Debian way) with support for GNU readline and history file is given below.


$cat ~/makefiles/gnuplot.install
#add the following or similar entry into the /etc/apt/sources.list
deb-src http://ftp.us.debian.org/debian/ etch main contrib non-free
# other possible entries look like
# deb-src http://ftp.us.debian.org/debian/ unstable main contrib non-free

# install packages necessary for building gnuplot
sudo apt-get install fakeroot
sudo apt-get build-dep gnuplot
# see the versions of gnuplot available
rmadison gnuplot
# I decided to use gnuplot 4.0.0-5

# go to the place where you normally compile packages
cd /home/software/compileHere/gnuplot

# (optional) move files from previous versions/compilations if they exist
# mv gnuplot-4.0.0/ /tmp
# (optional) move old binary deb files also if necessary
# mv gnuplot*deb /tmp

apt-get source gnuplot=4.0.0-5
dpkg-source -x gnuplot_4.0.0-5.dsc
cd gnuplot-4.0.0/debian/

# Edit the file named "rules" and change
--without-gnu-readline
TO
--with-readline=gnu

# Enable the history file by adding
--enable-history-file

cd ..
dpkg-buildpackage -us -uc -rfakeroot
cd ..

ls gnuplot*deb
gnuplot_4.0.0-5_all.deb gnuplot-nox_4.0.0-5_i386.deb
gnuplot-doc_4.0.0-5_all.deb gnuplot-x11_4.0.0-5_i386.deb

sudo dpkg -i gnuplot*deb

apt-cache showsrc gnuplot

Friday, April 20, 2007

calculate md5sums in windows

A free, open source software called winMd5Sum is available from http://nullriver.com/winmd5sum . This software can be used to compute md5sum values of files.


tested on : Windows XP

Saturday, April 14, 2007

recipe for building texmacs package with pdebuild

As of Fri Apr 13, 2007, the stable branch of Debian (Etch) carries texmacs 1:1.0.6-10, unstable branch of Debian (Sid) carries texmacs 1:1.0.6-11 . Assuming that pdebuild is used for the first time, the following recipe can be used to build the unstable's texmacs packages on a machine running Debian Etch (stable).
$cp /usr/share/doc/pbuilder/examples/pbuilder-distribution.sh ~/bin/pbuilder-sid
$mkdir -p ~/pbuilder/result
$sudo aptitude install cdebootstrap
$pbuilder-sid create # if second time, use 'pbuilder-sid update'

$cat ~/bin/pdebuild-distribution.sh
#!/bin/sh

DISTRIBUTION=`basename $0 | cut -f2 -d '-'`
BASE_DIR="$HOME/pbuilder"
pdebuild --buildsourceroot fakeroot \
--buildresult $BASE_DIR/result \
-- --basetgz $BASE_DIR/$DISTRIBUTION-base.tgz \
--distribution $DISTRIBUTION $@

$cp ~/bin/pdebuild-distribution.sh ~/bin/pdebuild-sid
$chmod +x ~/bin/pdebuild-sid
$cd ~/practice/
$wget http://ftp.debian.org/debian/pool/main/t/texmacs/texmacs_1.0.6-11.dsc
$wget http://ftp.debian.org/debian/pool/main/t/texmacs/texmacs_1.0.6.orig.tar.gz
$wget http://ftp.debian.org/debian/pool/main/t/texmacs/texmacs_1.0.6-11.diff.gz
$dpkg-source -x texmacs_1.0.6-11.dsc
$cd texmacs-1.0.6
$pdebuild-sid
The commands can be changed accordingly for other packages as well as for distributions other than sid. The ~/bin/pdebuild-distribution.sh performs similar function for pdebuild as /usr/share/doc/pbuilder/examples/pbuilder-distribution.sh does for pbuilder.

Tested on Debian Etch, using pbuilder 0.161

recipe for building texmacs package with pbuilder

As of Fri Apr 13, 2007, the stable branch of Debian (Etch) carries texmacs 1:1.0.6-10, unstable branch of Debian (Sid) carries texmacs 1:1.0.6-11 . Assuming that pbuilder is used for the first time, the following recipe can be used to build the unstable's texmacs packages on a machine running Debian Etch (stable).
$cp /usr/share/doc/pbuilder/examples/pbuilder-distribution.sh ~/bin/pbuilder-sid
$mkdir -p ~/pbuilder/result
$sudo aptitude install cdebootstrap
$pbuilder-sid create # if second time, use 'pbuilder-sid update'
$cd ~/practice/
$wget http://ftp.debian.org/debian/pool/main/t/texmacs/texmacs_1.0.6-11.dsc
$wget http://ftp.debian.org/debian/pool/main/t/texmacs/texmacs_1.0.6.orig.tar.gz
$wget http://ftp.debian.org/debian/pool/main/t/texmacs/texmacs_1.0.6-11.diff.gz
$pbuilder-sid build texmacs_1.0.6-11.dsc
The commands can be changed accordingly for other packages as well as for distributions other than sid. More info can be found at /usr/share/doc/pbuilder/pbuilder-doc.html

Tested on Debian Etch, using pbuilder 0.161

Wednesday, April 11, 2007

executing octave scripts

Using Octave 3.0.1, bash 4.1.5(1)-release on Debian Squeeze (stable)
$cat even_odd.m
# prevent Octave from thinking that this is a function file
clear;

function even_odd1(m)
# use bitand instead of mod to figure out if a number is odd or even
# if (mod(m, 2) == 1)
if (bitand(m,1))
printf("%d is odd\n", m)
else
printf("%d is even\n", m)
endif
endfunction

n = 25
even_odd1(n)
n = 30
even_odd1(n)
The above octave script can be run
1. Directly at the command line by doing
$octave -qf even_odd.m
n = 25
25 is odd
n = 30
30 is even
2. Inside Octave by doing
$octave -qf
octave:1> even_odd
n = 25
25 is odd
n = 30
30 is even
octave:2> n
n = 30
The advantage of first method is that no interaction is necessary. Useful for well tested scripts. The advantage of second method is that variables can be accessed even after the script is executed. Useful while debugging.

3. Source the script inside Octave
$octave -qf
octave:1> source("./even_odd.m")
n = 25
25 is odd
n = 30
30 is even
This approach comes in handy if the name of the script contains any special characters (ex:- '-' hyphen) or if the script has to be called by its relative path name.

Tuesday, April 10, 2007

insert page numbers in a texmacs document

To insert page numbers inside a texmacs document, do

Document -> Page -> Type -> Paper
Document -> View -> Page Layout -> Show header and footer

Sunday, April 08, 2007

copy paste code into blogger

The difference between pasting some random text and pasting source code is that, it is necessary to preserve the formatting (indentations etc.,) when pasting the source code. If you would like to list some program inside the articles posted via blogger, then you can do the following:
  • Convert all the tabs in the program to spaces. While this step is optional, I suggest this since there would be no unwanted surprises with tabs in the final document. If you are using a good editor such as vim, this takes less than a minute.
  • Go to "Edit Html" tab when editing the post
  • Put your code inside

    <pre class="verbatim" xml:space="preserve">
      ...
    </pre>
    tags. 
  • You can also use

    <pre class="literal-block">
      ...
    </pre>
    tags. 

That's it.

Followers