Friday, November 15, 2013

Handy bash and vim tips that I've used from time to time

1. Copying files while retaining their directory structure
find ~dir1/ -name "*.mat" | xargs -I{} cp {} ~/<destination>
The directory structure below ~dir1/ where the *.mat files are found are copied to <destination> retaining the structure
2. Scp-ing only a set of files from multiple directories (using find and then scp-ing those files out retaining directory structure
find -name "*.mat" -print0 | tar --null --no-recursion -czf archive.tar.gz --files-from -

1. To comment or uncomment a block of code
ctrl+v --> select your block of code --> :norm I# (inserts a # in front of each line) or :norm ^x (removes the first character from each line in the selected block)

Thursday, October 31, 2013

Installing java on your linux machine without removing the native version it comes with

I like to have all my software installations in a single place so I know exactly what state my machine is in by glancing at a single directory, say ~/Software
My ancient CentOs setup doesn't have jdk 1.7 in its repo, so instead of fooling around with alternatives <shudder>, I downloaded the jdk version I wanted and put it into said ~/Software directory.

Here's a simple way to go about changing the default version of java that your system picks up without having to uninstall the native java that it comes with.

1. Switch to su
2. Create a file,say in /etc/profile.d/ containing :


3. Save out the file, and logout and log back in to your machine.
4. To test out your java version, run
java -version
5. To see which executable will be picked up, run
which java

Wednesday, September 25, 2013

Installing 32 bit java on my 64 bit CentOs6 machine

This is a right old pain to do, so unless you really need to, I would say find a way to stick to the native 64 bit jre/jdk install.
As of this writing, the latest jdk version available is 1.7.0_40

A quick listing of the steps I followed are below. The commands are italicised.

1. yum erase jdk (to remove the existing 64 bit java devel environment)

2. Download the x86 version of jdk (the rpm), say jdk-7u40-linux-i586.rpm

3. yum provides
    yum install libgcc-4.4.7-3.el6.i686 
(which is what came up as the reqd package from the command above)

4. yum install jdk-7u40-linux-i586.rpm

5. Check your installation with the usual 
    java -version

In case you want both the 64 and 32 bit versions of java installed, you'll have to muck about with alternatives, which I happily chose to avoid!

Wednesday, July 3, 2013

Handy git tricks

Using Git is a blessing, truly it is. Today is just one of those days when I feel like chopping a limb off because git can't understand what I want it to do.
"Restore a file I deleted from my ide, then revert it to its state when I added that line in, then checkout a single file blah blah jabber jabber"

Each time I discover a neat trick to do what I want in git, I shall henceforth make a note of it here :)

  1. Restore a file that you deleted by accident in the repo or Undo all the changes in a file but haven't committed yet.
  git checkout HEAD^ <path to file>

This should bring the file back to the state it is in in the remote repo.

  2.  List all the files included in a commit

git log master

find the commit reference from here eg: 7bdf3a80243c7029508357c45bf4b918ce2bab86
git show --name-only 7bdf3a80243c7029508357c45bf4b918ce2bab86

Saturday, September 1, 2012

Cancer killing virus...Are you kidding me?!

I couldn't believe my eyes when I stumbled across this nugget online. Why on Earth hasn't this been plastered over the front page of every newspaper, the top of every science feed list or on billboards along the highway!
Before I get ahead of myself and incite an outrage, let me briefly tell you what I understood of the article.
At Uppsala University Hospital in Sweden, Prof Magnus Essand and his team have created a virus that eats cancerous cells. When a healthy cell is infected by a virus, it dies to prevent the spread of the virus to other cells. Cancerous cells change this behaviour and prevent their sacrifice (this is what make cancerous cells evil). But if a virus can be created to take advantage of this very feature of a cancerous cell, it would enter the cell, multiply uncontrollably and cause the cell to 'lyse' or explode, thereby spreading the cancer-munching virus (babies?) to other cancerous cells. This isn't a new idea apparently!
Oddly enough, in the 1890s, an Italian clinician found that prostitutes with cervical cancer showed alleviated symptoms when vaccinated against rabies. He then proceeded to roam the countryside injecting women with dog saliva. (Sigh!). In the 1900s, a 14 old year old boy with lymphatic cancer, found his swollen liver and spleen return to normal size after catch chicken pox. (and you never thought that you would find a bright side to chicken pox!).
The virus that Prof. Essand and his team have is said to attack neuroendocrine tumours (the same kind that assailed Steve Jobs). The virus, however, is in cold storage, refrigerated until it can go into human trials.
To be reasonable, the virus' success in rats doesn't necessarily translate into human viability, but that's what human trials are meant for! Money, is a blocker (surprise surprise). They need 1 million pounds to go through phase 1 and 2 of the trials and 2 million pounds to develop a better variety (I'm not really sure what this is even supposed to mean. Doesn't the virus either do its job or not? what does it get better at with an additional million pounds worth of research?) In any case, the virus remains unnamed and the team has agreed to name it after the person who donates a million pounds. I quote verbatim from the article
To donate money to Professor Magnus Essand's research on viral treatments for neuroendocrine cancer, send contributions to Uppsala University, The Oncolytic Virus Fund, Box 256, SE-751 05 Uppsala, Sweden, or visit Contributions will be acknowledged in scientific publications and in association with the clinical trial. A donation of £1 million will ensure the virus is named in your honour

I also found another rather interesting tidbit. The details of the virus have already been published. This no longer allows them to file a patent (who would have thunk!). Without a patent, a pharma company that would have ordinarily take over the expense of the 3rd phase of human trials in order to profit from subsequent manufacturing and distribution when the drug goes commercial, won't think of investing the money. Devoid of an avenue to accrue profits, pharma companies would shrink away into the darkness. Unless....unless the team makes a modification to the virus, and redoes the entire process, this time taking care to file a patent before a publication. Politics in a nasty business.
Here's hoping that the virus does succeed in human trials, that the team does get the money it seeks to continue their research and that patients with NETs (Neuroendocrine tumours) have a lantern bobbing brightly on the horizon.
If this were to succeed, I would be very excited to see how the results could be modified to deal with other kinds of cancers....could we truly be on the cusp of a breakthrough?
Cheering on the Uppsala team, here's wishing them all the very best of luck!


Tuesday, June 26, 2012

Afo the Giant Clove tree

This was one of the most interesting tidbits to come out of the 'From your own Correspondent' podcast (An excellent podcast about events from around the world told in the form of first person narrative stories as bbc's correspondents become immersed characters in the tales)
Its about a giant clove tree on top of an active volcano in Indonesia!
The tree is on the slopes of a volcano on one of the Spice Islands of Indonesia called Ternate. At its peak, it used to be 40 metres tall and 4 metres wide, but sadly all that is left of it today is a stump. No one knows how old it really is, but estimate it to be a 350-400 ancient.

After the Spanish and Portuguese were routed from the country by the Dutch in 1652, the very first multinational company (called the VOC or the Netherlands United East India Company) formed between them and the East India Company, started to regulate spice exports. They behaved much like MNCs today do; controlling supply artificially to keep demand and prices high. They would allow only 800-1000 tonnes of cloves to be exported per year and the rest of the harvest would be burned or dumped in the sea! Any clove tree that wasn't controlled by the VOC was razed to the ground. Afo escaped this horrendous fate somehow, perhaps because of its remote location

It seems that man's thirst for money (aka power) is unquenchable, today, 500 years ago and cynically, yet realistically 500 years hence. He apparently doesn't care for anything or anyone that causes so much as a speck on his monetary horizon. That rant aside, what are we to do about our beautiful planet if ravaging her is this deeply ingrained in our psyche?

BBC article -
Spice Islands -
FOOC podcast link -

Thursday, March 29, 2012

Matlab and Movie making

I realize that this is completely against the spirit of my blog, yet I find myself sighing so loudly with relief at having finally been able to make the 'movie making in matlab' process work for me, that I just needed to put it down here (for future reference and for everyone having the same problem)...Believe me, I know how madly annoying it can be to run an 'addframe' command in loop 5000 times, relinquishing control over your screen for an hour, only to find at the end of this excruciating process that the avi is distorted!!!

In matlab...

filename = sprintf('images/Pic%04d.jpg', index);
imwrite(image_matrix, filename);

In the terminal...
ffmpeg -i Pic%04d.jpg -sameq -r 25 outmovie.mp4
ffmpeg -i Pic%04d.jpg -sameq -r 25 outmovie.avi
To slow down the movie,
ffmpeg -i Pic%04d.jpg -sameq -r 25 -vf "setpts=2.0*PTS" outmovie.mp4
To speed up the movie,
ffmpeg -i Pic%04d.jpg -sameq -r 25 -vf "setpts=0.5*PTS" outmovie.mp4

And wala!, I now have a perfect movie :D