eXTReMe Tracker
Aug 212013
 

If the gnome/mate/cinnamon session becomes unresponsive, you can use the Ctrl+Alt+F1 key sequence to get to shell mode. Once there,  you can login and run the following command to end the graphical session:

sudo pkill -KILL -u USER_NAME
Jan 112013
 

To get the stock quotes for NYSE listings create some file named stockval and add it to your PATH.

Then gedit the file with the text:

#!/bin/bash

p=`printf "curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=$1&f=l1'"`
price=`eval $p`;
echo $price

stock_quote_ticker

 

 

 

 

 

 

 

 

 

 

Make that file executable

chmod +x stockval

Close out, and open a terminal. If you have the path correctly configured, execute the stockval command using the company symbol as an argument and it returns the stock price on the line below.

stockval goog

732.15 << output
Oct 292012
 

As it turns out the if statement in bash isn’t as friendly towards floating point variables as it is for integer and string variables.

First of all the -gt and -lt switches don’t work.Even the unary operators >,<, etc. don’t work. The only way is to do a comparison between the floating point variables using bc and using the logical outout as a comparison string.

a=11.5; b=11.3
compare_result=`echo "$a >$b" | bc`
 if [ $compare_result -gt 0 ]; then
 echo $a
else
echo $b
 fi

 

Sep 192012
 
Simple image compression algorithm using plain FFT computation

FFT2 based image compression

Test code to generate a circular mask that removes the low frequency components from an image.

Step through radius to get the percentage compression.

IM=imread('images_01.jpg');IM=IM(:,:,2); %Select a channel
%
cx=size(IM,2)/2; cy=size(IM,1)/2;
ix=size(IM,2);iy=size(IM,1);r=833;
[x,y]=meshgrid(-(cx-1):(ix-cx),-(cy-1):(iy-cy));
c_mask=((x.^2+y.^2)>r^2);
%
filtIM = fft2(IM).*c_mask;
filtIM = ifft2(filtIM);
IM2=abs(double(IM)-abs(filtIM));
%
x=size(IM,1)*size(IM,2); y=size(find(c_mask==1)); y=y(1);
res=y/x*100;
%
figure(1); 
subplot(2,2,1); imshow(c_mask);
subplot(2,2,2); imagesc(IM2); axis image; axis off;
subplot(2,2,3); imshow(IM); title('Origianl image');
subplot(2,2,4); imagesc(abs(filtIM)); axis image; axis off;
title(sprintf('Percent original: %0.2f',res));
Sep 102012
 

Submitting processing job to a queue

jobs=$scratch/jobs
sub=/lustre/scratch/subjects
# mkdir $jobs
# cp -r $HOME/subjects $scratch/
function run-recon-all() {
cd $scratch
#create submit script for each patient in the subjects directory
do
unset SUBJECTS_DIR
SUBJECTS_DIR=$sub
export SUBJECTS_DIR
cat > $jobs/recon-all-$patient.sh <<EOF
#!/bin/bash
#$ -S /bin/bash
#$ -cwd
#$ -N recon-all-$patient
# Set the hard and soft run time limits
#$ -l h_rt=30:00:00,s_rt=29:55:00,vf=2.5G
# set up FreeSurfer environment variables
# mri_convert -oi -os $SUBJECTS_DIR/$patient $SUBJECTS_DIR/$patient.mgz
recon-all -s $patient -all
EOF
done
#submit job script for each patient in the jobs directory to the cluster
pushd $jobs
for script in `ls -1`
do
echo "submitting job $script"
qsub $script
done
popd
}
run-recon-all
Aug 082012
 

Here’s a nifty little script I found.

You need to run it within the directory containing the wma files:

#!/bin/bash

current_directory=$( pwd )

#remove spaces
for i in *.wma; do mv "$i" `echo $i | tr ' ' '_'`; done

#Rip with Mplayer / encode with LAME
for i in *.wma ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm -ao pcm:waveheader $i && lame -m s audiodump.wav -o $i; done

#convert file names
for i in *.wma; do mv "$i" "`basename "$i" .wma`.mp3"; done

rm audiodump.wav

If you aren’t happy with underscores and want your spaces back, run this on the command line:

for i in `ls *.mp3`; do p=`echo $i | tr '_'  ' '`; mv $i "$p"; done

They will be in the proper format now, and google music compatible.

May 092012
 

If you are going for a complete reinstall of OS and you need to get a list of packages you have at present, so that you can reinstall them after you have installed Linux from scratch, run the following:

#!/bin/bash
sudo dpkg --get-selections | awk '{ ORS=" "; print $1; }' > packagelist.txt

This saves the everything to packagelist.txt. Mind blown!

 

Mar 042012
 

As a prank project we installed a webcam at the front desk of the our office suite, and plugged it into a Linux machine. Then we had a decommissioned 14 inch monitor face the person who was just walking in so that he/she could see themselves in the monitor with absolute clarity. The text beneath said “Smile for the camera”.

This was an one line implementation with VLC. The terminal command for this would be:

vlc --sub-filter "marq{marquee=\$t \$\smile for the camera,color=16776960,position=8}" v4l2:////dev/video0

A false sense of security with some false video surveillance. Of course you can save the stream and turn it into real surveillance.

 

Dec 282011
 

To monitor the instantaneous network usage, execute the ifstat command in bash. You may need to acquire it from a repository if you don’t have it already.

sudo apt-get install ifstat

To display usage on eth0, with a 5 second delay, just once:

ifstat -i eth0 5 1

You can change the number of seconds, and the number of times you want the output displayed. If you don’t specify the count, it will go on forever until you ctrl-c out of it.

So here is a script that displays the download rates in MB/s and upload rates in KB/s every 5 seconds until you hit ctrl-c.

while :
do
# Press ctrl-c to exit
x=`ifstat -i eth0 5 1 | tail -1 | tr '\t' ' '`;  #tail -1 takes the DL and UL speeds in KB/S
x1=`echo $x | cut -d ' ' -f1`; x2=`echo $x | cut -d ' ' -f2`;
x1=$(echo "scale=3; $x1/1024" | bc); # Convert DL rate to MB/S
printf "D: %0.3f MB/s\t U: %0.3f KB/s\n" "$x1" "$x2"
done
Nov 162011
 

On most Linux/Unix based systems, you can save your Matlab figure as a postscript instead of saving it as a png or jpg. One advantage of saving figures in this manner is that you can save multiple images as separate pages on that .ps document, whereas with png/jpg you have to save each image as a separate file.

To print the current image to postscript, all you need to run is:

print(‘-dpsc2′,’filename’);

To have multiple images appended within the postscript document, you need to use the -append switch.

print(‘-dpsc2′, ‘-append’, ‘filename’);

Your output postscript will have the name filename.ps

To convert the postscripts to pdf format, just run the ps2pdf command in the terminal window:

ps2fpdf filename.ps

The output of this would be filename.pdf

And you’re done.

Nov 102011
 

In order to install l1-SPIRiT Compressed Sensing Parallel MRI, we need to have a couple of programs installed – fftw3, lbz2.  Usually you encounter the following error while running build routine in Matlab.

/usr/bin/ld: cannot find -lbz2
collect2: ld returned 1 exit status

sudo apt-get install libbz2-dev

After installing libbz2-dev this error is corrected.

Sep 192011
 

The latest version of Ubuntu is heavily based upon Unity environment. Unfortunately Unity has no track record of playing nice with existing gnome programs. For network applications such as VNC, Unity crashes the program with whole bunch of errors. These crashes are observed occasionally in the Ubuntu 11.04 (Natty Narwhal) release, and most certainly in the latest beta 1 release of Ubuntu 11.10 (Oneiric Ocelot).

If you have gotten comfortable with Ubuntu and want to continue using Gnome as the main environment, you can do so by using Linux Mint 11 (Katya). It has the same repositories as Ubuntu and you can even use the ubuntu-restricted-extras and build-essential packages which lets you obtain some of the fonts, codecs and libraries that Ubuntu fetches for you.

Ubuntu is starting to put more emphasis on making their release into an eye-candy, at the cost of reduced functionality. Having used Ubuntu since Dapper Drake days, its sad to ditch it for another distro. IMO Ubuntu 10.04 was the cleanest distro they put out – things have been going downhill after that. Linux Mint on the other hand picked up at the point when Ubuntu started to go dysfunctional. It has everything that Ubuntu should have been. There isn’t much to write about Mint 11. Its very similar to Ubuntu 10.04, has a newer kernel 2.6.38.xx, clean graphics, and the same repositories as Ubuntu. The transition is very easy, and things look a lot more neater in Mint.

To recap: If you are currently using Ubuntu and are afraid to upgrade to the 11.10 release, your fear is quite justified. Make a backup of your /home folder and go for a clean install of Linux Mint instead. I moved to Mint about a month ago and have had a rather smooth sailing so far.