Archive for July, 2006

Emacs – add flyspell to text-mode

July 31, 2006

Flyspell is an in-line spell checker. It checks the spelling as you type.

To enable flyspell in text-mode add this in your .emacs file:

(dolist (hook ‘(text-mode-hook))
(add-hook hook (lambda () (flyspell-mode 1))))

Emacs – major mode

July 31, 2006

To change the major mode in Emacs use:

M-x mode_name-mode

To set the default major mode, which initially is Fundamental, add the following to your .emacs file:

(setq default-major-mode ‘mode_name-mode)

Emacs – auto-fill for text buffers

July 31, 2006

To activate auto-fill mode for all test mode buffers add this to .emacs:

(add-hook ‘text-mode-hook ‘turn-on-auto-fill)

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.

Unix/Linux — Find files that contain a string

July 30, 2006

To find the files that contain a string we can use:

find . -exec grep -l “string to find” {} \;

This starts the search from the current directory, looks for files that  contain the specified string, and then it prints their names.

Windows – cygwin – SSH server

July 29, 2006

To start the cygwin SSH server:

net start sshd

For more information:
http://www.chinese-watercolor.com/LRP/printsrv/cygwin-sshd.html

Databases/SQL — PostgreSQL — get tables and columns

July 29, 2006

In order to get the list of the available tables of a database in PostgreSQL, connect to that particular database and run:

SELECT tablename FROM pg_tables
WHERE tablename NOT LIKE ‘pg\\_%’
AND tablename NOT LIKE ’sql\\_%’;

In order to get the list of columns for a particular table in that database, run:

SELECT attname FROM pg_attribute, pg_type
WHERE typname = ‘table_name
AND attrelid = typrelid
AND attname NOT IN (‘cmin’, ‘cmax’, ‘ctid’, ‘oid’, ‘tableoid’, ‘xmin’, ‘xmax’);

Emacs – truncate lines

July 29, 2006

To set Emacs to truncate or not to truncate long lines:

M-x toggle-truncate-lines
To set Emacs not to truncate lines when you have the window split vertically:

M-: (setq truncate-partial-width-windows nil) RET

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.