Programming Tips

See also Barata's tips and Leozinhos' tips

Down them all

wget -r -nd --accept='$WhatIWant' $link

Remove duplicate lines of a file

sort -u file

Access your files via HTTP

Python

import SimpleHTTPServer
http = SimpleHTTPServer.BaseHTTPServer.HTTPServer(('',8000),
SimpleHTTPServer.SimpleHTTPRequestHandler)
http.serve_forever()

Powered by Matheus

How to read each line of a file in...

Script SHELL

    while read line; do
echo $line
done < FILE

Python

for line in open('file'):
print line

Java

… forget it, too many lines of code to write :-o

SSH without password

ssh-keygen -t dsa
cd ~/.ssh/
cp id_dsa.pub authorized_keys

Starting another X

startx -- :2

Cumulative sum of an specified column using awk

awk '{sum += $NF} END {print sum}' file

$NF is the last column. $1 is the first, $2 the second and so on. The default separator is a blank space, if you need to specify another separator use -F'separator' option.

Reading an specific line of a file in...

Python

import linecache
line = linecache.getline(file, index)
print line

Script SHELL

head -index file | tail -1

where index is the line to read.

Generating statistics with octave

octave
data = load $data_file;
statistics(data)

This will returns a matrix with the minimum, first quartile, median, third quartile, maximum, mean, standard deviation, skewness and kurtosis of the columns of x as its rows.

Genereting numbers permutations

octave
perms([1, 2, 3])

The function perms(v) generates all permutations of a given vector.

Converting UF-8 files to ISO-8859-1

iconv -f utf-8 -t iso-8859-1 file > new_file

Extracted from here .