Wednesday, 9 May 2012

Python Adventures Part 1

Add path using shell variable PYTHONPATH
then load module of your file (i.e. survey.py)

Must reload this everytime a change is made using reload(survey). Ugh.
To fix this, go to ipython and 
import ipy_autoreload. 
Then run 
%autoreload 2

 (other behaviours given by %autoreload ?)

To read csv, import numpy and then use function recfromscv

to get help with functions, import the module and type help(module.function)

To automatically make all things in a module accessible just do 
from module import *


Wednesday, 15 February 2012

Bash no clobber

either set noclobber to 0 or just use >| instead of >

Thursday, 19 January 2012

Remove Encryption from PDF

for i in *.pdf; do gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=${i%%.*}_unen.pdf -c .setpdfwrite -f $i; done;

Tuesday, 13 December 2011

Friday, 25 November 2011

SVN add project

svn import . path/to/repository

Monday, 17 October 2011

Make Matlab writable by pipes

mkfifo matin

Matpipe:
#!/bin/bash
((tail -f ~/matin | tee >(cat 1>&2)) & cat) | matlab

Writemat
#!/bin/bash
cat $@ | tee ~/matin

Vim function
vmap :call ExecuteMatlab()
function! ExecuteMatlab() range
:'<,'>!writemat
endfunction


Then pipe commands to matin.

This prints stuff sent to matin to the stdin of matlab and also to stderr, as well as able to read from the stdin of the terminal.

Keyword: process substitution - >(....) creates a temporary file in bash and feeds stuff to that process.