eXTReMe Tracker
Oct 232014
 

To compute a transpose of an input file, i.e. converting columns to rows and rows to column using bash, you can accomplish that using awk and while loop.

#!/bin/bash
cols=`cat $1 | head -1 | wc -w`;
for i in $(seq 1 $cols);
do
awk -v "n=$i" '{print $n}' $1 | tr '\n' ' ';  # variable column output
printf "\n";
done

This example uses a variable to output a specific column from the input.

awk -v "n=$variable" '{print $n} ' input.txt

Will pass the variable to n and the nth column gets printed from input file.

Sep 252013
 

Before making any modification to any files, first create a backup of smb.conf file

sudo cp /etc/samba/smb.conf  /etc/samba/smb.conf.bak

The open the configuration file for editing:

sudo gedit /etc/samba/smb.conf

In the section identified as Share Definitions, insert this piece of code. The path string should be the path for folder you will be sharing. If you want others to have the ability to write to that directory –

sudo mkdir -p /path/to/shared/folder
sudo chown nobody.nogroup /path/to/shared/folder
[share]
    comment = Ubuntu File Server Share
    path = /path/to/shared/folder
    browsable = yes
    guest ok = no
    read only = no
    create mask = 0755

Once the configuration file has been saved, its time to restart the samba daemon

sudo restart smbd
sudo restart nmbd

Once the samba daemon has restarted, you need to add a list of users who can access samba folder.

sudo smbpasswd -a username

To access this directory from windows, open My Computer -> Tools -> Map Network Drive

Folder address for this share would be:

\\ip_address_of_your_server\share

NOTE: The folder is called share in the share definition. You can call it something else and edit the parameters based on the chosen share name.If you want to have access to this folder each time, make sure to save the password and check that option to reconnect at login.

 

 

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
Nov 202012
 

When you start getting this error, the easiest way to get around it is to boot through a Live CD and create a root password.

sudo passwd root
su root

Once you are logged in as root, navigate to your partition that has system installation.

chown root:root usr/bin/sudo
chmod 4755 usr/bin/sudo
chmod 0440 etc/sudoers
chmod u+s usr/bin/sudo 

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 302012
 

There is a compose functionality out there:

Linux umlaut typing

For the Gnome Desktop:

  • go to System -> Preferences -> Hardware -> Keyboard on the Gnome menu
  • select the Layouts tab
  • click the Options… button
  • expand Compose key position
  • check the box Right Ctrl is Compose or Right Win-key is Compose

The Right Ctrl or the Right Win key are now a “compose key”. With it you can compose symbols by combining two characters. The double-quote then the letter “a” equals an umlaut-a (ä). Tap the compose key, then tap shift+quote for a double-quote, then tap the a-key.

  • ä is compose, then “, then a
  • ö is compose, then “, then o
  • ü is compose, then “, then u
  • ß is compose, then s, then s

The list of compose key sequences can be found at:

Compose key sequences

Content found at blog: http://idolinux.blogspot.com/

Kül

 

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.

Jul 202012
 

In the newer versions of Linux, an open source driver is usually installed by default to run the graphic cards. However this driver can sometimes be absolutely messy, and it is essential to remove the Nouveau driver and install the binary driver from Nvidia.

However, if after you reboot into the service mode from grub menu, and try to install the NVIDIA-Linux-x86_64-xxx.run driver in the init 3 level, the program will kick you out saying that the Nouveau driver is still in use.

The way to disable the Nouveau drivers from kernel is to boot in the service mode and run the following commands:

echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
 update-initramfs -u

Once its done reconfiguring the kernel, you will need to reboot, and again get to service mode.

After that, get into init 3 mode, and install the NVIDIA-Linux-x86-64.xxx.run script. The installation should be successful at this point.