" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %
Tuesday, 9 July 2013
Vim sudo write
Tuesday, 16 April 2013
Tuesday, 12 February 2013
Javascript, clone array
Jiggery pokery to copy the data, useful, but not here
http://stackoverflow.com/questions/3865139/cast-javascript-object-to-array-how-to#answer-3865808
var d = $.extend(true,{},arrel);
d.length = arrel.length;
var dd = Array.prototype.slice.call(d);
Tuesday, 6 November 2012
Remove lines from file 1 that are in fiel 2
grep -v -x -f f2 f1 should do the trick.
With some explanations:
-v for select non-matching lines
-x for matching whole lines only
-f f2 to get patterns from f2.
sgrep like a player
Used to remove nodes with a given colour from a SVG file
sgrep -i 'inner("<"..">") not containing ("#00ffff" or "#ff00ff" or "#ff0000")' < survey_plain.svg > survey_really_plain.svg
sgrep -i 'inner("<"..">") not containing ("#00ffff" or "#ff00ff" or "#ff0000")' < survey_plain.svg > survey_really_plain.svg
Friday, 26 October 2012
Create favico using GIMP
Take image,
make sure Image > Mode RGB is selected.
Scale to 32x32
Save as GIF (indexed using default settings)
Save a copy as Microsoft Windows Icon and choose bpp. 4 Worked nicely last time.
make sure Image > Mode RGB is selected.
Scale to 32x32
Save as GIF (indexed using default settings)
Save a copy as Microsoft Windows Icon and choose bpp. 4 Worked nicely last time.
Wednesday, 23 May 2012
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
Thursday, 9 February 2012
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
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.
Matpipe:
#!/bin/bash
((tail -f ~/matin | tee >(cat 1>&2)) & cat) | matlab
Writemat
#!/bin/bash
cat $@ | tee ~/matin
Vim function
vmap
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.
Friday, 19 August 2011
Save wrong line bash
A simple thing to do when you realize you just typed the wrong line is hit Ctrl+C; if you want to keep the line, but need to execute something else first, begin a new line with a back slash - \, then Ctrl+C. The line will remain in your history.
Latex Dashes
Hyphen: daughter-in-law, X-rated\\
En dash: pages 13--67\\
Em dash: yes---or no? \\
Minus sign: $0$, $1$ and $-1$
En dash: pages 13--67\\
Em dash: yes---or no? \\
Minus sign: $0$, $1$ and $-1$
Bash trim filename
However, buried in there is a section on Parameter Substitution which tells us that $foo is really a shorthand for ${foo} which is really the simplest case of several ${foo:operators} and similar constructs.
- Given:
- foo=/tmp/my.dir/filename.tar.gz
- We can use these expressions:
- path = ${foo%/*}
- To get: /tmp/my.dir (like dirname)
- file = ${foo##*/}
- To get: filename.tar.gz (like basename)
- base = ${file%%.*}
- To get: filename
- ext = ${file#*.}
- To get: tar.gz
-
- ${variable%pattern}
- Trim the shortest match from the end
- ${variable##pattern}
- Trim the longest match from the beginning
- ${variable%%pattern}
- Trim the longest match from the end
- ${variable#pattern}
- Trim the shortest match from the beginning
Thursday, 10 February 2011
Reverse Tunelling and x2x
To control a box behind a firewall using keyboard and mouse on another computer.
On firewalled computer run
ssh -R 22222:localhost:22 user@localcomp
On local computer run
ssh -p -X 22222 user@localhost
In the last ssh tunnel run
x2x -east -to :0
On firewalled computer run
ssh -R 22222:localhost:22 user@localcomp
On local computer run
ssh -p -X 22222 user@localhost
In the last ssh tunnel run
x2x -east -to :0
Wednesday, 5 May 2010
Gvim invisible cursor after vsplit
Vim code:
From:
http://old.nabble.com/Cursor-become-invisible.-td20630223.html
let &guifont=&guifont
From:
http://old.nabble.com/Cursor-become-invisible.-td20630223.html
Subscribe to:
Posts (Atom)