Author Archive

LaTeX – Customize page numbering

October 4, 2006

For changing the default, centered page numbering, use the fancyhdr package:

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear all header and footer fields
\fancyfoot[R]{\footnotesize Page \thepage\ of 2}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

This will print the page number on the right side of the footer, smaller font and in the format “Page % of 2”.

Advertisements

Variable reassignment in makefiles

August 5, 2006

To change the value of a variable assigned in makefile, inside a rule, use this:

target ... : variable-assignment

on a separate line by itself.

Example:

CC=gcc
...
prog: CC=g++
prog: prog.cpp
	${CC} -o prog prog.cpp

Found here:

http://www.gnu.org/software/make/manual/html_node/Target_002dspecific.html

Bundle files in Unix

August 5, 2006

Use this script to bundle files that will automagically unbundle when the file is executed:

#!/bin/sh
## Bundle --  put listed files into a bundle on stdout which sh will unbundle
# From "The UNIX Programming Environment," by Brian Kernighan and
#   Rob Pike, Prentice Hall, 1984.
echo "# To unbundle, sh this file"
for i
do
  echo "echo $i 1>&2"
  echo "cat >$i <<'End of $i'"
  cat $i
  echo "End of $i"
done

Unix/Linux — find & xargs — Spaces in filenames

July 30, 2006

Spaces in filenames can be a problem when using find | xargs combination.

To solve this, use:

find . -print0 | xargs -0 <command>

This tells find and xargs to use the ASCII NUL character instead of space to end (separate) the filenames.

VIM – Comment blocks of code

July 28, 2006

Mark the area which is to be commented using the *blockwise* visual mode (CTRL-V, in Windows this is CTRL-Q).

Press I (capital i) and write the text you want to prepend to each line of the selected block, e.g. %.

Then press ESC and the text will be inserted to the left of each line of the selected block.

Compile Python eggs

July 28, 2006

To compile a .egg from a standard setup.py based Python package, add

from setuptools import setup

to setup.py, before the other setup/distutils imports, and then run

./setup.py bdist_egg
This will create a .egg package in dist/ subdirectory, and can be installed with easy_install.

Double spacing in LaTeX

July 26, 2006

Add at the beginning:

\usepackage{setspace}

Then switch between different spacing options with:

\doublespacing
\singlespacing
\onehalfspacing

For other sizes use the \setstretch command like this:

\setstretch{1.8}

Speed up Firefox in Linux

July 20, 2006

The IPV6 in Linux slows down Firefox.

To fix this, open the file browser, go to /etc, right click on “modprobe.conf“, choose “open with” > “gedit” and add the lines

alias net-pf-10 off
alias ipv6 off

to the bottom of the file, then save and exit.

This will significantly increase browsing speed by decreasing DNS lookup time.

Process memory usage

July 20, 2006

pmap – report memory map of a process

Databases/SQL — MySQL — create database

July 20, 2006

How to create a database in MySQL:

# mysql -u root -p
mysql> create database db_name;
mysql> grant all privileges on db_name.* to
db_user@”localhost” identified by ‘db_pass‘;