Showing posts with label quickie. Show all posts
Showing posts with label quickie. Show all posts

Thursday, 9 September 2010

Quick Tip: PUT - scp files from remote machine to local machine

It is often desirable to have a quick look at a file on a remote machine, such as an HPC cluster, on your desktop machine. I use MacFUSE and SSHFS for this but sometimes I like to move a file without finding my current location in a finder windows. I have written a quick wrapper around scp with a line to determine the IP address of my local machine, stored as an environment variable.

Add the following lines to your .bashrc on the remote machine.


export DESKTOP=$(last -100 |grep $(whoami) |head -n 1 |perl -ane 'print $F[2]')
put(){
if [ -z "$1" ]; then
    echo "put - Sends specified files to Desktop of local machine";
    echo "usage: put filesToSend";
else
find "$*" |xargs -I % scp % $DESKTOP:~/Desktop
fi
}

Then reload the file with source .bashrc. You should now be able to type put fileName, and the file will appear on your desktop. As long as you have your rsa keys set up, otherwise it will ask for a password too. It works for multiple files too, such as *.png. 

I find it useful for quickly viewing pdfs and images. 

Monday, 19 April 2010

R tip: Maximum screen width

R can be annoying in that even if you stretch your terminal or R GUI session to a whole screen width it will still only show 80 characters width. This can make wide tables really hard to read.

 options(width=150)

Use the options command width to set this parameter to what ever you like. Easy.

Friday, 26 February 2010

R tip: Finding the location of minimum and maximums

I can never remember this R command, so I am going to post it here which probably means I will always remember it and never have to look it up here again.

I sometimes want to find the location of a minimum or maximum value in a vector, so I can look up the corresponding position in another vector, or column or something. You can just use order but that is a bit clunky and more prone to error, so what you really need is which.min and which.max.

x <- sample(1:100,20)
which.min(x)

x <- matrix(sample(1:100,20),nrow=10)
x[which.min(x[,2]),1]

Not exactly earth-shatteringly useful but better than:

x <- matrix(sample(1:100,20),nrow=10)

x[order(x[,2])[1],1]

Or is it? Now I write that, it is actually less characters than which.min. Oh well.