Actually this is more of a QIFAM (Questions I Frequently Ask
Myself)... various tidbits of mostly computer-related info, that for
one reason or another I tend to forget. Usually that's because it's
information that I use infrequently enough that it never gets
imprinted in my meory, so rather than have to look it up from first
sources each time I do need it, I just write it down here.
a2ps
(back to top)
for f in "$@"; do
a2ps --landscape $f --columns=1 --chars-per-line=120 --output=${f%.*}.ps
done
bash Bourne-again shell
(back to top)
if the invocation is
./somescript "1 2 3" a b c
then
$# is 4
$* has 6 parameters
"$*" has 1 parameter
$@ has 6 parameters
"$@" has 4 parameters
so, for forwarding parameters from one script to another, the
construct to use is "$@", including the double-quotes
pattern-matching
shopt -s nullglob # patterns with no matches expand to the empty string
shopt -u nullglob # patterns with no matches stay unchanged
readline history manipulation
Esc-. retrieves the last argument from the previous command;
subsequent presses retrieve the last argument from commands
further back in the history
variable manipulation
${var#pattern} remove the shortest matching piece
${var##pattern} remove the longest matching piece
right-stripping:
${var%pattern} remove the shortest matching piece
${var%%pattern} remove the longest matching piece
example:
var=/foo/bar/baz.tar.gz
${var%.*} --> /foo/bar/baz.tar
${var%%.*} --> /foo/bar/baz
${var#*/} --> foo/bar/baz.tar.gz
${var##*/} --> baz.tar.gz
substitution:
${var/pattern/string} replace first 'pattern' match with 'string'
${var//pattern/string} replace all 'pattern' matches with 'string'
line-oriented reading
read directly from a file into a file descriptor:
exec 6<fname
while read -u 6 line; do
echo "$line"
done
pipe a subshell's output into line-oriented reading:
(
svn status
) | (
while read line; do
case "$line" in
M*)
echo $line
;;
esac
done
)
Bayes bayes rule/theorem
(back to top)
P(A,B) = P(A|B) * P(B)
= P(B|A) * P(A)
=> P(A|B) = P(B|A) * P(A) / P(B)
posterior = likelihood * prior / constant
C/C++ programming
(back to top)
Just link to libefence (i.e. add "-lefence" to the link
command-line). Its best minimize the size of the input to the
program, since Electric Fence is a huge memory hog.
You can also use dynamic linking. If you're using a Bourne shell,
the statement export LD_PRELOAD=libefence.so.0.0 will cause
Electric Fence to be loaded to run all dynamic executables. The
command 'ef command' runs a single command under Electric Fence.
use libgmalloc under Mac OSX (try "man libgmalloc")
use the MALLOC_CHECK_ environment variable with glibc
export MALLOC_CHECK_=1 # print info to stderr about bad malloc/free
export MALLOC_CHECK_=2 # abort immediately if bad malloc/free
export MALLOC_CHECK_=3 # combination of (1)+(2)
setjmp/longjmp
#include <setjmp.h>
#include <cstdio>
int main()
{
jmp_buf state;
int val = setjmp(state);
if (val == 0)
{
printf("direct return\n");
}
else
{
printf("indirect return %d\n", val);
return 0;
}
longjmp(state, 3);
}
POINTERS pointers to constants and constant pointers:
char *const cp; // const pointer to char
char const* pc; // pointer to const char
const char* pc2; // pointer to const char
read the declaration left to right
corba CORBA omniORB omniorb
(back to top)
getting started:
need to edit /etc/omniORB.cfg to include the following line:
InitRef = NameService=corbaname::127.0.0.1
need this in ~/.bashrc so omniNames can run as non-root:
export OMNINAMES_LOGDIR=$HOME/local/var/omninames
then run omniNames as non-root with
omniNames -start # for the first time
omniNames # for subsequent times
CRON cron jobs
(back to top)
to reload crontab file crontab ~/.crontab
CVS cvs
(back to top)
Here's what I've learned about the modules file, and in particular
ampersand modules.
I had the following file directories in my $CVSROOT:
$CVSROOT/pkgs/mx/
$CVSROOT/pkgs/optim/
containing sets of C++ source files that I wanted to be able to
reuse in different projects, via different modules.
As well as
$CVSROOT/devscripts/
containing a set of scripts that I also wanted to reuse.
I wanted to set up an optimization module:
$CVSROOT/optimization/
for which the module, when checked out, would also contain the
following directory structure:
optimization/devscripts/
optimization/src/mx/
optimization/src/optim/
Here was my first attempt at a modules file:
pkgs_mx -d mx pkgs/mx
pkgs_optim -d optim pkgs/optim
optimization_src -d src &pkgs_mx &pkgs_optim
optimization optimization &optimization_src &devscripts
OK, so now I do a 'cvs co optimization'. I get the desired
directory structure. But then when I 'cd optimization' and 'cvs
update', cvs appears to not recognize the 'src' or 'devscripts'
direcgtories. The 'optimization/CVS/Entries' contains only a single
line:
D
I knew that I had seen something like this approach work before in
my previous efforts with cvs, so on a hunch I did a 'cvs add; cvs
commit' for a dummy file in the 'optimization' directory (which had
been empty until now... that is, $CVSROOT/optimization/ was an
empty directory). Now, when I do a fresh 'cvs co optimization', the
optimization/CVS/Entries file is still initially devoid of lines
referring to either devscripts or src... however, if I 'cd
optimization' and 'cvs update', then afterwards there is a new line
in CVS/Entries referring to devscripts. But still nothing referring
to 'src'.
Exploring more, I peeked inside the
'optimization/src/CVS/Repository' file and found
'CVSROOT/EmptyDir'... OK, so cvs is treating the 'optimization_src'
module specially because it consists only of ampersand directives.
So, on another hunch, I tried adding a new, empty directory in the
cvs repository:
$CVSROOT/dummydir
and then changed the optimization_src line in the modules file from
this:
optimization_src -d src &pkgs_mx &pkgs_optim
to this:
optimization_src -d src dummydir &pkgs_mx &pkgs_optim
Now, once more I do a fresh 'cvs co optimization'. As before, there
are initially no lines in CVS/Entries referring to devscripts or
src, but now if I 'cd optimization' and 'cvs update', both
'devscripts' and 'src' are recognized, and I subsequently get lines
for both in CVS/Entries.
Lesson:
Don't compose modules out of ampersand references alone; always
have at least a real "dummydir" at the beginning... not much of
a problem since a single "dummydir" will work for the entire
repository.
Debian debian Ubuntu ubuntu
(back to top)
rpm -qa dpkg-query -l
rpm -ql <pkg> dpkg-query -L <pkg>
rpm -qf <file> dpkg-query -S <file|pattern>
yum remove <pkg> apt-get remove <pkg>
Emacs emacs
(back to top)
forward-char C-f
backward-char C-b
previous-line C-p
next-line C-n
forward-word M-f
backward-word M-b
tab-to-tab-stop M-i
next-page C-v
previous-page M-v
delete-character C-d
kill-word M-d
backword-kill-word M-DEL
transpose letters C-t
transpose words M-t
transpose lines C-x C-t
quote message in reply C-c C-y
read-only toggle C-x C-q
generate etags table etags *\.[ch]*
load etags table M-x visit-tags-table RETURN
find-tag M-.
tags-loop-continue M-,
tags-query-replace M-x tags-query-replace RETURN
list-tags M-x list-tags RETURN
beginning-of-defun M-C-a
end-of-defun M-C-e
indent-region M-C-\
local variables
Note that the local variable list must be within 3000 characters of
the end of the file.
/* For emacs customization... */
/* Local Variables: */
/* tab-width: 5 */
/* End: */
The "/*" and "*/" can be arbitrary strings, as long as they are the
same on all of the lines.
Emagic Logic
(back to top)
to create: command-option click in lower third of ruler bar
to delete: grab marker text with cursor and drag downward
automation
to create a curve segment: control-option-drag on the middle of the
curve (drag left-right or up-down)
Fedora fedora network profiles
(back to top)
switch with
system-config-network-cmd --profile <profilename> --activate
trash /var/lib/dhclient/dhclient-eth0.leases
Firefox firefox
(back to top)
Go to about:config in your address bar and search for this:
network.http.sendRefererHeader
and set the value to 0.
Some unexpected pages might start breaking, so beware.
http://www.mozilla.org/quality/networking/docs/netprefs.html
gcj java
(back to top)
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
To make an executable main program:
gcj HelloWorld.java --main=HelloWorld
To make a *.class file:
gcj HelloWorld.java -C
To make a *.o object file:
gcj -c HelloWorld.java
To link C++ and Java code:
gcj test.cc HelloWorld.o
To make a CNI C++ header:
gcjh HelloWorld
To make a JNI C header:
gcjh -jni HelloWorld
To interpret Java bytecode:
gij HelloWorld
Gnutella
(back to top)
connect.newtella.net:6346
gnutellahosts.com:6346
router.limewire.com:6346
gnutella.hostscache.com:6346
GPG
(back to top)
gpg --gen-key
gpg --list-keys
gpg --export > somekeyfile
gpg --import somekeyfile
basic encrypt/decrypt
gpg (--recipient|-r) me@here.com (--encrypt|-e) somefile
gpg (--decrypt|-d) somefile.gpg > somefile
use (--armor|-a) to make the output be ascii-safe
use stdin/stdout:
cat somefile | gpg -r me@here.com -e > somefile.gpg
with signature
gpg --sign --encrypt test.txt
gpg -o test.txt --decrypt test.txt.gpg
graphviz dot graphing tool
(back to top)
use the "minlen" attribute on the joining edge, e.g. minlen=2 to
separate the nodes by at least two rank levels
hfspax
(back to top)
hfspax -wv -f thisfolder.pax -x cpio thisfolder
hfspax -rv -f thisfolder.pax
HP All-In-One OfficeJet series POC
(back to top)
when printer goes buggy, try re-running "HP All-In-One Setup Assistant"
Illustrator illustrator (Adobe)
(back to top)
Issue
When you try to open an Adobe Illustrator document, Illustrator
returns one of the following errors:
-- "Can't open the illustration. The illustration contains an illegal
or misplaced operator. Offending Operator: 'ter' Context: :/Dict;
/Part,/Part, /CompoundFilter : (Chain Style Filter) 0 0 /Filter." (for
a CMYK file)
-- "Offending operator: 'und' Context: ; /Dict ; /Part , /BasicFilter
: (Adobe Round Corners) 1 0 /Filter , (Round Corners) /PluginFileName
,(Round)" (for an RGB file)
After you click OK in the error dialog box, the document is blank or
severely corrupted.
Detail
The document contains the Wheelchair Access symbol from the Symbols
palette.
Solutions
Do one of the following:
Solution 1: Place the document into a new Illustrator file. Create a
new Illustrator file, and then place the damaged document into
it. Make sure that All Documents is selected in the Place dialog box.
Note: If you complete this solution, you will lose all styles,
symbols, brushes, blends, and warps. Other effects will be expanded,
and all layers will be merged.
Solution 2: Recover a plain-text version of the document. If the file
was saved with compression (the default), you must first recover a
plain-text version of the file, which you can then open in a text
editor.
Note: If you complete this solution, all of the editing capabilities
and layers that were in original file will be retained.
To recover a plain-text version of the document:
1. Exit from Illustrator, and then open the Adobe Illustrator
Preferences file in a text editor (for Windows, this is "Documents and
Settings/<username>/Application Data/Adobe/Adobe Illustrator CS
Settings/AIPrefs").
2. Look for the line "/enableContentRecovery 0" and change the value
from "0" to "1" so that the line reads:
/enableContentRecovery 1
[otherwise try EnableContentRecovery (i.e. with capital 'E')]
3. Start Illustrator, and choose File > Open.
4. Select the damaged document, and then click OK while holding down
Ctrl + Shift + Alt (Windows) or Command + Shift + Option (Mac OS). An
empty document opens. Close the document without saving
it. Illustrator extracts the data from the damaged document and
creates a new, uncompressed, document that has the same name as the
original (preceded by an underscore). Illustrator saves the new
document in the same folder as the original.
5. In a text editor that can save in text-only format (for example,
WordPad) open the new document.
6. Search the document for "Wheelchair Access." Delete the line
preceding the first occurrence (that is, %AI10_BeginSymbol) and all
other lines down to and including the line "%AI10_EndSymbol." Delete
the second occurrence of "Wheelchair Access."
7. Save the document with a new name, and then open it in Illustrator.
Background information
The Wheelchair Access symbol from the default Symbols palette is
damaged; Illustrator can't open files that contain this symbol.
To prevent this problem from recurring, delete the Wheelchair Access
symbol from both of the Adobe Illustrator Startup documents (in the
Plug-ins folder) and from the Symbols palette before you work on a
document.
i.e.:
/Applications/Adobe Illustrator/Plug-ins/Adobe Illustrator Startup_CMYK
and
/Applications/Adobe Illustrator/Plug-ins/Adobe Illustrator Startup_RGB
The line "enableContentRecovery 1" enables Illustrator to decompress
files that it can't open otherwise.
image/graphics files
(back to top)
http://www.lcdf.org/gifsicle
generating postscript from bitmap images
pnmtops
[-scale s]
[-dpi n] (default is 300dpi)
[-imagewidth n]
[-imageheight n]
[-width=N]
[-height=N]
[-equalpixels]
[-turn|-noturn]
[-rle|-runlength]
[-nocenter]
[-nosetpage]
[pnmfile]
to make nice eps images e.g. for LaTeX:
anytopnm img.xxx | pnmtops -nocenter -noturn -equalpixels -nosetpage > img.ps
eps2eps img.ps img.eps
Using 'eps2eps' to transform the output of pnmtops helps reduce
the size of the postscript file since it encodes the bitmap data
in a more compact format.
printing jpeg/jpg digital photos
jpegtopnm $f > {$f:r}.ppm
pnmtops -height 5 -width 7 ${f:r}.ppm > ${f:r}.ps
lpr ${f:r}.ps
iMovie export settings
(back to top)
video
compression: H.264
quality: High
framerate: 15 (or "current")
bitrate: 1500 kbits/sec
frame reordering: yes
encoding mode: multi-pass
dimensions: 640x480
audio
format: AAC
sample rate: 48.000 kHz
channels: stero
bit rate: 256 kbps
KDE kde keyboard shortcuts
(back to top)
To set keyboard shortcuts for minimizing windows, etc., go to the
KDE Control Center, then "Regional & Accessibility", then "Keyboard
Shortcuts"
Konsole konsole in KDE
(back to top)
New Shell Alt+Ctrl+N
Switch session Shift+Left, Shift+Right
Move session Shift+Ctrl+Left, Shift+Ctrl+Right
Change shortcuts Settings->Configure Notifications...
Linux linux
(back to top)
To use APM instead of ACPI:
The simplest way to do this is to add the "acpi=off" option to the
end of the "kernel" line in /boot/grub/grub.conf.
kernel /boot/vmlinuz-2.6.xxx ro root=LABEL=/ rhgb quiet acpi=off
(from http://www.cs.umd.edu/~nakamura/misc/t40.html)
flash memory
cat /proc/bus/usb/devices
cat /proc/scsi/usb-storage/2
sudo fdisk -l
# fstab:
/dev/sda1 /mnt/usb auto noauto,user,owner,sync 0 0
dmesg | grep -i usb
kernel modules
load with /sbin/insmod
put insmod commands in /etc/rc.d/rc.local to have them loaded at
boot time
list installed+loaded modules with /sbin/lsmod
kernel building
then run "sudo lilo -v -t" to test that lilo will succeed
then run "sudo lilo -v" to actually run lilo and update the boot sector
notes
18-Mar-2003 2.4.18-27-rjp failed after the first build+reboot,
because something was wrong with the initrd file. But,
just redoing "sudo make install" changed the initrd
size to normal, and then reboot worked fine. Perhaps
this is because I had edited lilo.conf in the meantime
to point to the new vmlinuz file?
30-Jul-2003 Identical experience to above, this time with
RH-2.4.20-19.8. (1) Did normal build+install. During
install, got the usual "no suitable template" error
from lilo/grubby. Suitably edited lilo.conf by
hand. (2) Reboot, and get an error just before the
init sequence would begin, including something like
"couldn't mount ext3 filesystem" and "try passing an
init=" option at the command line. (3) Reboot back
into working kernel. Looked at the initrd for the new
build, and as before, it was "too small" as compared
to the other initrd files laying around. (4) Went back
to kernel build directory and re-ran "sudo make
install". Now, the initrd file is twice as big. (5)
Once more reboot into the newly-built
kernel. Everything works fine now.
linux wireless networking
list open files
/usr/sbin/lsof
list open sockets
/usr/bin/lsof -VRi
-i to list internet/network files
-R to list PPID
-V be verbose if there were no matches for a given request
optionally:
-l to inhibit user-id --> username conversion
-n to inhibit ip-address --> hostname conversion
-P to inhibit port-number --> portname conversion
disconnect+reconnect process controlling terminals
start the process with
dislocate program_name args...
then use the escape sequence Ctrl-] to get back into 'dislocate' to have
the opportunity to disconnect the process from the terminal
then at a later time, on a different terminal, just do 'dislocate' with
no args to reconnect to the detached process
loopback disks
(back to top)
dd if=/dev/zero of=plaintext.img bs=1M count=20
losetup /dev/loop0 plaintext.img
mkfs -t ext2 /dev/loop0
mount /dev/loop0 mountpoint
dd if=/dev/urandom of=ciphertext.img bs=1M count=20
losetup -e aes /dev/loop0 ciphertext.img
mkfs -t ext2 /dev/loop0
mount -o loop,encryption=aes ciphertext.img /path/to/mountpoint
umount /path/to/mountpoint
losetup -d /dev/loop0
http://www.linuxjournal.com/article/8599
Mac OS X OSX macosx Darwin darwin
(back to top)
At the Aqua login window, enter ">console" for username (note the
first character is a 'greater-than' character)
This brings up a standard console login screen... enter
username+password there.
To run an X session, just run "startx"
NOTE: after logging out of X session, the system will appear to
hang... it isn't really, but the console video is confused. Two
options:
(1) when the system seems to be hanging, just blind-type
"logout<return>" and this should bring back the Aqua login
window.
(2) instead of starting X with "startx", do "exec startx"
instead; then when X session quits, the Aqua login will
return automatically
Finder
to reset default size/view/etc. of the Finder window for a given
folder, open the folder with Cmd-doubleclick and then change the
settings as desired
gcc build tips for Mac OS X
BIG KEY: --> unlimit stacksize
make CC='cc -no-pre-comp' bootstrap
kernel panics
how to get a kernel panic log:
open /Applications/Utilities/Console application, hit the "Logs" icon in
the toolbar, open /Library/Logs, and the contents of panic.log
keyboard shortcuts
from http://www.uark.edu/compserv/softsys/macintosh/macos/osx/osxkeybd.html
Option-Command-esc Force Quit
Control-Eject Restart, Sleep, Shutdown dialog box
Control-Command-Eject Quit all applications and restart
Option-Command-Eject or
Option-Command-Power Sleep
Press X during startup Force Mac OS X startup
Press Option-Command-Shift-Delete
during startup Bypass primary startup volume and seek a different startup volume (such as a CD or external disk)
Press C during startup Start up from a CD that has a system folder
Press N during startup Attempt to start up from a compatible network server (NetBoot)
Press R during startup Force PowerBook screen reset
Press T during startup Start up in FireWire Target Disk mode
Press Shift during startup start up in Safe Boot mode and temporarily disable login items and non-essential kernel extension files (Mac OS X 10.2 and later)
Press Command-V during startup Start up in Verbose mode.
Press Command-S during startup Start up in Single-User mode (command line)
ldd
from http://developer.apple.com/technotes/tn2002/tn2071.html:
The ldd command is not available in Mac OS X; however, you can
use the command otool -L to get the same functionality that
ldd does. The otool command displays specified parts of object
files or libraries. The option -L displays the name and
version numbers of the shared libraries that the object file
uses. To see all the existing options, see the manual page for
otool.
printer sharing in Leopard (10.5)
from: http://docs.info.apple.com/article.html?artnum=306984
cupsctl BrowseProtocols='"cups dnssd"'
shm
sysctl can't modify shm settings once they have been set the first
time during boot; therefore, they must be set in /etc/rc with a
line like this:
sysctl -w kern.sysv.shmmax=134217728 kern.sysv.shmmin=1 \
kern.sysv.shmmni=64 kern.sysv.shmseg=64 kern.sysv.shmall=32768
Terminal application
defaults write com.apple.terminal TerminalOpaqueness '0.75'
to copy escape sequences into the "Terminal Inspector", do the
following to get the sequence into the pasteboard:
echo -ne "\e[5C"|pbcopy
startup display resolution problems:
remove /Library/Preferences/com.apple.windowserver.plist
remove ~/Library/Preference/ByHost/com.apple.windowserver.*.plist
to make an app run with no menubar and no dock icon
add the following line to Whatever.app/Contents/Info.plist:
<key>NSUIElement</key><string>1</string>
verbose startup
hold cmd-v (openapple-v) during startup, or, to make verbose startup the
permanent selction, do:
sudo nvram boot-args="-v"
http://www.icsi.berkeley.edu/~wooters/mactips.html
Or, according to http://mfdh.ca/apple/mac_os_x.html, add lines like the
following to /etc/rc to make the change really permanent:
# Setting verbose option for next reboot.
#
nvram boot-args="-v"
ConsoleMessage "Verbose booting engaged."
Majordomo
(back to top)
from http://eleccomm.ieee.org/demo1/userdoc.shtml
A user can subscribe to a list, or ask about his or other users'
subscriptions, by sending mail to the majordomo server, usually
majordomo@hostname. Put the commands in the body of the mail message
(not on the "Subject:" header component). Other than white space,
the commands must be the first text in the message body; in other
words, don't begin with "Dear Majordomo."
Sends one-line summaries of majordomo commands. The first line of
output tells you which version of Majordomo the server is running.
info list
Sends an introduction to the list list.
subscribe list [address]
This command subscribes a user to the named list. Unless the user
includes the optional address, Majordomo will use the e-mail
address in the mail message header ("Reply-To:", if any, otherwise
"From:") to send mail to the user.
unsubscribe list [address]
This unsubscribes the user (or address) from list.
which [address]
Tells the lists to which the user (or address) is subscribed.
who list
Lists the subscribers of list.
index list
Gives a listing of files in the list archive. If the list is
private, only members can run this command.
get list filename
Mails a file named filename from the list archive. If the list is
private, only members can run this command.
end
Stops reading the message. This is useful for users whose mailer
adds text (like a signature) to the end of a message. A line that
starts with a dash (-) is also treated as an end command by newer
versions of Majordomo. Because many peoples' mail message
signatures start with some dashes, this avoids error messages.
Makefiles makefiles GNU make gmake
(back to top)
warn about undefined variables --warn
`$@' The file name of the target.
`$<' The name of the first prerequisite.
`$^'
`$+'
The names of all the prerequisites, with spaces between them.
For prerequisites which are archive members, only the member
named is used (*note Archives::). The value of `$^' omits
duplicate prerequisites, while `$+' retains them and preserves
their order.
.PRECIOUS: %.o
REAL_SOURCES = $(shell echo a b c | tee -a log)
SOURCES_INIT = $(eval SOURCES := $(REAL_SOURCES)) $(SOURCES)
SOURCES = $(call SOURCES_INIT)
all: foo1 foo2
foo1: $(SOURCES)
echo foo1: $+
foo2: $(SOURCES)
echo foo2: $+
Math
(back to top)
half-width at half-height == sqrt(log(4) * stddev)) ~= 1.177 * stddev
full-width at half-height ~= 2.355 * stddev
g = (1 / (sqrt(2*pi) * sigma)) * exp(-0.5 * ((x - mu)/sigma)^2)
logarithms
log_a(x) := ln(x) / ln(a)
MATLAB Matlab matlab
(back to top)
"matlab -Dgdb", where "gdb" is the name of the debugger
to draw a circle
h = rectangle;
get(h);
set(h, 'Curvature', [1 1]);
things that bug me about matlab
There isn't the same flexible concept of 'expression' as there is
in C/C++. In C/C++, anything you can do with a variable you can
also do with a value returned from a function, or with the result
of a math operator. But not so in matlab. E.g. if you want to
return the elements of the variable 'x' rearranged in a single
column, you can do 'x(:)'. But you can't do the same thing to a
function result, for example -- if you have a function 'foo' you
can't do 'foo(3)(:)'.
To me, this gives the language an uncomfortable sense of
incompleteness and non-uniformity.
to avoid lines, plots, etc. from being clipped outside the plot box
h=line([x1 x2], [y1 y2]);
set(h, 'clipping', 'off');
microsoft excel Excel
(back to top)
microsoft word Word
(back to top)
Page Setup: top faces right
Envelope: Custom Page Options: "Face up" "top facing left, centered"
Printer: load envelope with top facing left (go figure...)
MIME mime decoding
(back to top)
use munpack/mpack from ftp://ftp.andrew.cmu.edu/pub/mpack/
MPEG mpeg/mpg/mp3
(back to top)
mpg123 -w myfile.wav myfile.mp3
to extract a section of a .wav file
wavpipe -i foo.wav -t 1:12-2:45 foo.wav
to fade in/out a .wav file (destructive, in-place edit)
wavfade -d -T 1.5 -L 0 -t 1.5 -l 0 foo.wav
to mp3-encode a .wav file
lame -h -b 160 foo.wav foo.mp3
to render a figure in a pixel-precise way
set(gcf, 'units', 'pix', 'position',[100 100 w h]);
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperPosition', [0 0 w h]);
print(gcf, '-dpng', '-r1', 'test.png');
MySQL mysql
(back to top)
/usr/bin/mysql_install_db --datadir=/tmp/mysql
/usr/libexec/mysqld --socket=/tmp/mysql.sock --datadir=/tmp/mysql &
/usr/bin/mysqladmin -u root --socket=/tmp/mysql.sock password 'XXXXXX'
/usr/bin/mysql --socket=/tmp/mysql.sock --user root --password
/usr/bin/mysqladmin -u root -pXXXXXX --socket=/tmp/mysql.sock shutdown
ntp date time clock
(back to top)
on linux:
hwclock
service ntpd stop && ntpdate time.nist.gov && service ntpd restart
/etc/ntp.conf
service ntpd restart
ntpq -p; # query peers
ntpq -p time.nist.gov; ntpq -p clock.redhat.com
nvidia driver kernel module
(back to top)
check for latest driver:
http://www.nvidia.com/object/unix.html
extraact the contents of the package:
sh NVIDIA-Linux-x86-1.0-7676-pkg1.run -x
probably need to do 'unset ARCH' before running nvidia-installer
(otherwise it will think the kernel arch is supposed to be i686
instead of i386)
to build+install for a currently RUNNING kernel version:
./nvidia-installer --kernel-name=[KERNELNAME]
to build+install for a currently NON-RUNNING kernel version:
./nvidia-installer -K --kernel-name=[KERNELNAME]
where KERNELNAME is what the output of `uname -r` would be if the
desired kernel were actually running.
might need to do this:
cp -a /dev/nvidia* /etc/udev/devices
chown root.root /etc/udev/devices/nvidia*
AFTER installing the nvidia driver, but BEFORE
rebooting... otherwise the boot process might hang at "Configuring
kernel parameters"
if glx crashes, check whether /usr/lib/libGLcore.so.N.N.NNNN has
been modified relative to path/to/NVIDIA-Linux/usr/lib/libGLcore --
sometimes the file gets corrupted -- in that case, try reinstalling
OpenGL/Mesa/Linux/XFree86
(back to top)
/usr/X11R6/bin/glxinfo command to report glx extension info
from Matrox readme: DRI requires modules "agpgart" and "mga" add
"/sbin/insmod agpgart" and "/sbin/insmod mga" to /etc/rc.local
Strange crashes occur unpredictably -- terminal shows "Segmentation
Fault", but no core dump is produced. This seems to be alleviated
by requesting an indirect rendering context, and possibly by just
rebooting the machine... maybe this is a problem with the gfx card
driver/kernel module that handles the direct rendering?
oprofile
(back to top)
collect profiling data:
sudo opcontrol --reset # clear out data from previous session
sudo opcontrol --start # start the oprofile daemon (oprofiled)
... run /some/long/program
sudo opcontrol --shutdown # stop profiling
generate profiling report:
opreport --demangle=smart --symbols /some/long/program
opreport --exclude-dependent --demangle=smart --symbols /some/long/program
Parallels
(back to top)
If Parallels NAT and Parallels Host-Guest show self-assigned IP
addresses, then try the following:
sudo killall -HUP pvsnatd
sudo /Library/StartupItems/Parallels/pvsnatd
Perl perl
(back to top)
there are no htonl() or ntohl() functions in perl, but any network
read/write calls generally involve a perl pack() or unpack()
followed by a print, and pack() and unpack() have 'n' and 'N'
templates which can be used to convert a number to a network byte
order byte string (with pack()) or convert a network byte order
byte string to a number (with unpack())
edit file(s) in place
$ perl -p -i.bak -e "s/foo/bar/; ..."
line-oriented file reading/writing
#!/usr/bin/perl -w
open(FOO, "foo") or die "can't open foo for reading: $!\n";
while ($line = <FOO>) {
($f1, $f2) = split(" ", $line);
}
open(BAR, ">bar") or die "can't open bar for writing: $!\n";
# or open(BAR, "<filename"); # same as just "filename"
# or open(BAR, ">filename");
# or open(BAR, ">>filename");
# or open(BAR, "| output-pipe-command");
# or open(BAR, "input-pipe-command |");
Postfix postfix
(back to top)
also http://www.stepwise.com/Articles/Workbench/eart.index.html
also http://www.cutedgesystems.com/software/PostfixEnabler/
edit /etc/postfix/master.cf, uncomment the 'smtp' line
edit /etc/hostconfig, change MAILSERVER from -NO- to -YES-
start postfix with
# /System/Library/StartupItems/Postfix/Postfix start
(as root)
logs in /var/log/mail.log
edit /etc/postfix/mail.cf to set myhostname, mydomain, myorigin
edit /etc/postfix/canonical to set up address rewriting
edit /etc/postfix/mail.cf to point to /etc/postfix/canonical with
canonical_maps = hash:/etc/postfix/canonical
in case of permission problems, reset as follows (as root):
chown -R postfix /private/var/spool/postfix
chown root /private/var/spool/postfix
chown root /private/var/spool/postfix
chown :postdrop /private/var/spool/postfix/public
chown :postdrop /private/var/spool/postfix/maildrop
chown :postdrop /usr/sbin/postqueue
chown :postdrop /usr/sbin/postdrop
postfix start
procmail
(back to top)
man procmail
man procmailrc
man procmailex
$HOME/.forward should contain "|exec /usr/bin/procmail"
PS using ps to get all processes
(back to top)
ps aux on Sun machines
ps -efl on HP machines
Regular expressions
(back to top)
logical OR match in Emacs \(foo\|bar\)
RPM rpm redhat package manager files
(back to top)
rpm2cpio foo.src.rpm | cpio -idm '*.spec'
sendmail
(back to top)
/sbin/chkconfig sendmail off
/etc/init.d/sendmail stop
/etc/init.d/sendmail status
spamassassin
(back to top)
* download tarball and unpack
* perl Makefile.PL PREFIX=$HOME/local/i686/spamassassin-3.1.7
* make
* make install
* edit $pfx/share/spamassassin/10_misc.cf replace this:
add_header all Status "_YESNO_, score=_SCORE_ required=_REQD_ tests=_TESTS_ autolearn=_AUTOLEARN_ version=_VERSION_"
with this:
add_header all Status "_YESNO_, score=_SCORE_ required=_REQD_ tests=_TESTSSCORES_ autolearn=_AUTOLEARN_ version=_VERSION_"
to get the NETBL tests
had to install Net::DNS and Net::IP locally in order to have a
recent-enough version of Net::DNS
- go to search.cpan.org, search for Net::DNS and Net::IP and download
- unpack, then
* perl Makefile.PL --noxs PREFIX=/path/to/spamassassin-3.0
* make
* make test
* make install
NOTE: when running 'make test' for Net-DNS, it will need to find
the just-installed Net-IP module, so it needs to see that
directory in @INC, which can be done by setting the PERL5LIB
environment variable like this:
export PERL5LIB=/home/rjpeters/local/i686/spamassassin-3.1.7/lib/perl5/site_perl/5.8.5
- hand-edit /path/to/spamassassin-3.0/bin/spamassassin to have this
line:
use lib '/path/to/spamassassin-3.0/lib/perl5/site_perl/5.8.5';
since by default it only referred to 5.8.3
- edit ~/.procmailrc to point to the local config files:
:0 fw
| $SPAMASSASSIN -D --configpath=$SA_PFX/share/spamassassin --siteconfigpath=$SA_PFX/etc/mail/spamassassin 2>> $MAILDIR/sa.log
- debugging by
* adding -D to spamassassin cmd line, this showed that Net::DNS
had too old of a version
- reenable DCC in $PFX/etc/mail/spamassassin/v310.pre
To use sa-update
just run sa-update (optionally with -D for debugging), but no need
to give an --updatedir option; sa-update will automatically put the
updates under $PFX/var/spamassassin... if $PFX is non-default
Sys::Hostname::Long
Net::CIDR::Lite
Mail::SPF::Query
IP::Country
IO::Zlib
Archive::Tar
http://wiki.apache.org/spamassassin/InstallingRazor
shorter line length with 'fold_headers' configuration option
hand edited /path/to/spamassassin-3.0/lib/perl5/site_perl/5.8.3/Mail/SpamAssassin/PerMsgStatus.pm
like this diff:
- $Text::Wrap::columns = 79;
+ $Text::Wrap::columns = 70;
SSH ssh
(back to top)
setup: iMac is behind Linksys firewall/router
firewall is set to forward port 22 to iMac
iMac has its own firewall with port 22 open for ssh traffic
to run VNC server on iMac and VNC viewer on some other internet client:
client$ ssh -l username server_hostname -L 5900:127.0.0.1:5900
server$ cd /Applications/OSXvnc.app/Contents/MacOS/
server$ ./OSXvnc-server
2004-08-04 13:55:24.713 OSXvnc-server[26405] Main Bundle: /Applications/OSXvnc.app
2004-08-04 13:55:24.739 OSXvnc-server[26405] Waiting for clients
2004-08-04 13:55:24.739 OSXvnc-server[26405] Started Listener Thread on port 5900
so we ssh'd from the client into the server with port 5900 from the
server being forwarded to port 5900 on the localhost
(i.e. 127.0.0.1)
now, from another terminal window on the client:
client$ vncviewer 127.0.0.1:0
VNC viewer for X version 4.0b4 - built Nov 17 2003 13:17:08
Copyright (C) 2002-2003 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.
Wed Aug 4 14:05:33 2004
CConn: connected to host 127.0.0.1 port 5900
CConnection: Server supports RFB protocol version 3.3
CConnection: Using RFB protocol version 3.3
TXImage: Using default colormap and visual, TrueColor, depth 24.
CConn: Using pixel format depth 6 (8bpp) rgb222
CConn: Using ZRLE encoding
ssh automatic authentication without password
in ~/.ssh
ssh-keygen -t rsa1 -f identity
ssh-keygen -t rsa -f id_rsa
ssh-keygen -t dsa -f id_dsa
on host (hume)
copy literal contents of
client:~/.ssh/identity.pub
client:~/.ssh/id_rsa.pub
client:~/.ssh/id_dsa.pub
into host:~/.ssh/authorized_keys2
setup host:~/.ssh/config
add to ~/.ssh/config
PubkeyAuthentication yes
RhostsRSAAuthentication yes
HostbasedAuthentication yes
setup host:/etc/ssh/sshd_config
add to /etc/ssh/sshd_config
RhostsRSAAuthentication yes
PubkeyAuthentication yes
on client (locke)
make sure to "chmod og-rwx ~/.ssh"
eval `ssh-agent`
ssh-add ~/.ssh/id_rsa (enter passphrase)
scp between two remote machines
line in ~/.ssh/config:
ForwardAgent yes
Here's an explanation from a usenet thread:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=Xns92AAD5C8420EAcelfers%40127.0.0.1&rnum=6&prev=/groups%3Fq%3Dscp%2Blocalhost%26meta%3Dsite%253Dgroups
Say the host you are running the initial scp is A, and you're
doing scp B:foo C:bar. Your command has the effect of running a
second copy of ssh on B. It needs authentication information to
login to C; how will it get it? Password authentication will not
work at all, since scp on A invokes ssh with -n and provides no
pty for the exec channel, so ssh on B can't prompt you for
it. Public-key will be OK, but you have to use agent forwarding;
again, even if an appropriate key is on B, it can't prompt you for
a passphrase.
recursively copy a directory by piping tar through ssh
This works better than scp, since scp does not respect and preserve
symlinks, for example..
localhost# tar cvfz - {somedir} | ssh {remotehost} "cd dest; tar xfz -"
SIMD
(back to top)
single instruction multiple data
MMX == SIMD integer operations
SSE == SIMD floating-point operations
MMX has 8 x 64-bit integer registers (borrowed from floating-point stack)
mm0..mm7
SSE has 8 x 128-bit floating-point registers
xmm0..xmm7
SSE2 was introduced with Pentium-4 and allows operations on 64-bit
floating point operands
single-user mode
(back to top)
To boot into single-user mode in linux, select the desired kernel in
GRUB but press "a" instead of Enter. Then, append the desired
runlevel to the end of the boot parameters line, then press Enter to
continue booting. E.g., for single-user mode, append a "1", and for
text-only mode, append a "3".
Spotlight spotlight (Mac OSX)
(back to top)
To control from the command-line: use mdutil and mdimport.
SysRq "skinny elephants"
(back to top)
http://www.brunolinux.com/01-First_Things_To_Know/Skinny_Elephants.html
http://hehe2.net/linux-general/the-7-habits-of-highly-effective-linux-users/
If all is blocked and even Ctrl+Alt+backspace (what should be a last
resort) does not react, if your system does not react on any action
remember the next line:
Raising Skinny Elephants Is Utterly Boring
Here is how you "raise the elephant":
Alt+SysRq+r ( The LEFT Alt key ) ( SysRq is on the same button as print screen )
Alt+SysRq+s
Alt+SysRq+e
Alt+SysRq+i
Alt+SysRq+u
Alt+SysRq+b
Give a little time between keystrokes.
The r stands for put keyboard in raw mode
The s for sync the disk
The e for terminate all processes
The i for kill all processes
The u for remount all filesystems read only
The b for reboot the system
THIS IS THE VERY LAST SAVE YOUR BUTT PROCEDURE ! ONLY IF ALL ELSE FAILS !
NOTE: For the skinny elephants to work you need to have the
sysrq-key enabled in the kernel. (CONFIG_MAGIC_SYSRQ)
Tcl tcl
(back to top)
#!/bin/sh
# \
exec tclsh "$0" "$@"
http authentication
> Now, what do you put in extraHeadersList? Something like:
>set extraHeadersList "Authorization {Basic gqQls2l0daE60Gq9a39sBGE=}"
The encoding scheme is simple, too.
Basic authentication is just the user name and password, seperated by
a colon, and base64 (MIME) encoded.
For example, the encoded string for user "john" with password "today"
would the Base64 encoded string of "john:today".
tcl2perl
(back to top)
file delete $f --> unlink $f
file tail $f --> use File::Basename; basename($f);
file copy $f $g --> use File::Copy; copy($f, $g);
file rename $f $g --> rename($f, $g);
file extension $f --> use File::Basename; my ($name, $path, $ext) = fileparse($f, '\..*');
file size $f --> (-s $f)
file executable $f --> (-x $f)
file exists $f --> (-f $f) or (-e $f)
file isdirectory $f --> (-d $f)
file mkdir $f --> mkdir($f)
TIME/DATE to reset current date/time to match the fileserver
(back to top)
touch dt ; sudo date -s "`date -r dt`"; rm dt
timestamp: quick timestamps with 'date'
(back to top)
date +%Y%m%d-%H%M%S
Tripwire tripwire
(back to top)
tripwire --check
update the database to match a tripwire report
tripwire --update --twrfile /var/lib/tripwire/report/$HOSTNAME-$DATE-$TIME.twr
print a report
twprint --print-report --twrfile /var/lib/tripwire/report/$HOSTNAME-$DATE-$TIME.twr
usb USB nikon coolpix camera
(back to top)
lsusb; # to check if usb device was detected
sudo mount /dev/sda1 ~/cam
vi text editor
(back to top)
h Move the cursor left one character.
j Move the cursor down one line.
k Move the cursor up one line.
l Move the cursor right one character.
<arrows> The cursor arrow keys should work, too.
Commands to enter new text:
a Append new text, after the cursor.
i Insert new text, before the cursor.
o Open a new line below the line the cursor is on; start entering text.
O Open a new line above the line the cursor is on; start entering text.
<esc> Quit entering text and return to command mode.
Commands to delete text:
dd Delete the line the cursor is on.
x Delete the character the cursor is on.
Commands to write the file:
:w<return> Write the file with its original name.
:w file_name<return> Write the file with the name "file_name".
Commands to quit the editor:
:q<return> Quit editing and leave vi.
:q!<return> Quit, discarding any modifications.
"vision" executable in saliency project
(back to top)
how to just get the saliency map:
vision --just-save --save-salmap --exit-after-display foo.pgm
"winmail.dat" files from Outlook
(back to top)
Yech. Use ktnef or tnef to extract the contents.
Windows XP windows xp
(back to top)
dual-boot with Fedora
Fedora changes the MBR so that the XP install CD barfs
to get the XP install CD to work, need to boot into linux with a
linux rescue CD, then DON'T mount the hard drive, then zero out the
MBR like this:
dd if=/dev/zero of=/dev/hda bs=512 count=1
Then reboot with the XP install CD and install XP.
Save the mbr with
dd if=/dev/hda of=/boot/mbr.img bs=512 count=1
It can then be restored with:
dd if=/boot/mbr.img of=/dev/hda bs=512 count=1
or if you do not want/need to overwrite the partition table with:
dd if=/boot/mbr.img of=/dev/hda bs=446 count=1
as the partition table is kept in the last 66 bytes of the MBR.
X11
(back to top)
xmodmap -e "keycode 66 = " # to disable caps lock
xmodmap -e "keycode 66 = Caps_Lock" # to re-enable caps lock
xmodmap --help
xev
loadkeys
fonts
-maker-family-weight-style-spacing--pixel size-tenth points-horz res-vert res-mono/prop-ave width-charset
maker: adobe, etc.
family: courier, helvetica, etc.
weight: medium, bold
style: (r)oman, (i)talic, (o)blique
spacing: normal, condensed, narrow, double
pixel size: font size in pixels
tenth points: font size in tenths of a point
horz res: horizontal resolution for which font was designed
vert res: vertical resolution for which font was designed
mono/prop: (m)onospace, (p)roportional spacing
ave width: average width in tenths of a pixel
charset: character set of font, e.g. iso8859-1
key auto-repeat
xset q # to query current user preferences
xset r on # to turn on auto-repeat
xset r off # to turn off auto-repeat
xargs
(back to top)
find . -name \*.log | xargs -n 10 echo foo bar
gives
foo bar a.log b.log c.log d.log e.log f.log g.log h.log i.log j.log
foo bar 1.log 2.log 3.log 4.log 5.log 6.log 7.log 8.log 9.log 10.log
etc.
XCDROAST
(back to top)
ypcat
(back to top)
Updated Wed Dec 03 18:02:03 PST 2008