Sam's Homepage
This is Sam's (a.k.a. Peabody's) homepage. Send me mail at
peabodyenator AT gmail.com. I'm interested in meeting new
people, especially those who come by here. I'm surprised anyone
would bother. I'll especially love you if you find a grammar or
spelling misake mistake (and tell
me about it).
What's Here?
Stuff. I mostly only place pictures,
musings, and pointless programs I write. I tire of maintaining
links since I write all my html in Emacs. Sorry about the long
page.
What's New?
I got straight A's again at UC Davis (spring quarter 2008)!
Old Stuff
I finally found a really
good article on configuring Emacs PSGML mode with document
type definitions. PSGML mode is what I use to edit this
homepage.
Other Pages
I gruadually add other things when I feel like it. I have regular expressions page an editor wars page and a netpbm page.
I've used Unicies of various kinds and my trouble is my memory's
spotty. So when I come across something in the Unix world I like, I
try and jot it down here. I also jot down other notes and craziness
regarding things less Unix centric, such as Python notes or Firefox
notes.
Organization's not my strong point. Good luck readin' this.
I hope you find it useful.
Rename the extension on a group of files -- ls *.ext | while read
item; do mv "$item" `echo '$item' | sed 's/\.ext/.newext/'`; done
Downcase all the filenames in a folder -- ls * | while read item;
do mv $item `echo "$item" | sed 's/.*/\L&\E/'`; done
I've been trying to move anything I type to version control.
It hasn't happened yet though (I'm lazy).
- Creating a repository. -- svnadmin create
<folder>
- Importing -- svn import <files> <url>
-m 'message'
- Checkout -- svn co <url>
- Commit -- svn ci <files> -m 'message'
- Setting RCS keywords -- svn propset svn:keywords
<keywords> <files>
- ssh -L <localport>:<tunneled remote
host>:<port on remote host> user@host --
The magical incantation for local port forwarding.
- ssh -R <remoteport>:<tunneled local
host>:<port on local host> user@host --
Basically the opposite of -L, a great way to get into a
machine behind a firewall if you have local access. Just ssh
out from it to your home computer, or a computer with ssh
access. Leave the connection open and then tunnel right back
in.
- ssh-keygen -t rsa then scp
~/.ssh/id_rsa.pub to the host and cat it onto
~/.ssh/authorized_keys. Be sure the directory permission is
700!
- ssh -L 5901:localhost:5901 <host> --
This will tunnel vnc via ssh. Very worthwhile.
- The follow is pretty much how I always use rsync to update
conf files between machines: rsync -r -tv -e ssh localdir1
localdir2 ... localdirn user@host:.. Turns on
recursion, preservation of timestamps, verbose output, and use
ssh.
Find is quite possibly the most important utility in any Unix admin's
toolbox. I've listed some examples below. Read the man page for more
information.
Notice I've appended | tee ~/find.log to the end of each
command below. It isn't necessary, but I really prefer to do this so that
my search results get saved to a file I can work with later.
In fact, a fun way to work with find is to create a shell function so that
this always happens:
function find {
/usr/bin/find "$@" | /usr/bin/tee ~/find.log
}
One last point...because of fuse, my home folder has recently become
home to network and encrypted filesystems. Making -xdev the first
option of the search expression avoids searching these filesystems.
- Find all files modified exactly 24-hours ago in your home folder:
find ~/ -mtime 1 | tee ~/find.log
- Find all files modified within the last 24-hours in your home folder:
find ~/ -mtime -1 | tee ~/find.log
- Find all files modified within the last 5 hours in your home folder:
find ~/ -mmin -$((60 * 5)) | tee ~/find.log
- Find all regular files which have any of their execute bits set:
find ~/ -perm -ugo=x -type f | tee ~/find.log
- Find all directories missing any of their execute bits:
find ~/ -perm +ugo=x -type d | tee ~/find.log
- Find all jpeg files regardless of case:
find ~/ -regex '.*\.[jJ][pP][eE]*[gG]' | tee ~/find.log
- Find all broken symbolic links:
find -L ~/ -type l
- Prune (ignore) part of a directory tree:
find ~/ -path ~/'folder*' -prune -o (actual search here)
- Find all backup files older than two weeks and delete them:
find ~/ -name '*~' -type f -mtime +14 -exec rm {} \; | tee ~/clear.log
- Only search the current folder:
find ~/ -maxdepth 1 (search goes here) | tee ~/find.log
- wget --no-host-directories/-nH I think
this is an annoying default, but it does help keep things a bit
safer and accounted for.
- wget -m for mirror mode. If I'm pulling
down more than one thing off the web I generally use
this.
- You almost always want to call wget with -np which stands
for No Parent and means that you don't recurse higher than
the first directory fed to wget. Trust me on this one, it can
be very bad.
In a rescue system, to access lvm drives try vgscan,
vgchange -ay, vgmknodes. mount drives before the
chroot and then chroot target. You may have to also mount
-t proc proc /proc to make some utils happy.
I used to run Fedora, but I've switched to Ubuntu. Now
everything uses dpkg so this is here to remind me how to
investigate packages.
- List Package Contents -- dpkg -L <package
name>
- Show Package Description -- dpkg -p <package
name>
- Show All Installed Packages -- dpkg --list
- Show Which Package 'filepath' Belongs To -- dpkg -S
filepath
This section coming soon. I've been playing around with Vim
lately. I'll be adding a section here shortly.
I use GNU emacs where I can get away with it. It's hard
sometimes, it often won't come on small bootable Linux systems
of which I find myself in from time to time, in which case it's
often Nano or vi (yes, I have to use sometimes). My problem is
I often forget the emacs-lisp incantations I like to keep in my
.emacs file, so here's my safe, simple, emacs
file in case I need it, as well as my Elisp libraries I use, and here's a list of common
emacs lisp settings I can't live without and can't often
remember. I usually to spend time tweaking GNU emacs when I
load it up for the first time on a system. I've set this place
up as my cheat sheet.
I can't emphasis enough how useful the Emacs Wiki is. It's
invaluable.
- When in doubt, launch emacs with "-q". This starts
a clean Emacs that ignores your startup file. Use --no-site
to run emacs without custom site-wide
configurations
- For Emacs novices, you can use the menu, even in a
terminal. F10 will get you to the menu, but if the terminal
emulator you're using doesn't let you send f10, you can push
ESC ` instead. There's lots of useful
functions you can access easily from the menu, and if one of
them happens to be bound to a keyboard shortcut, it'll tell
you what it is after using it.
- (setq
backup-directory-alist '(("." . "~/.my_backups")))
Helps keep those backup files from cluttering your
directories. Make sure the directory "~/.my_backups"
exists! Scratch that. I've grown found of the default
way backup files are kept.
- M-x normal-erase-is-backspace to fix
backspace problems when jumping between Mac/PC environments
and terminal emulators.
- Saving
editing sessions is incredibly useful
with(desktop-load-default) (desktop-read)in
the .emacs file. Don't forget to save your session the first
time with M-x desktop-save and don't forget
to start Emacs in the same directory as before! CVS
Emacs (which is what I use now) only needs
(desktop-save-mode). The previous advice is still useful if
you're stuck with a previous version of Emacs.
- (setq dired-recursive-copies t) and (setq
dired-recursive-deletes t) to copy and delete
recursively in Dired (Emacs' DIRectory EDitor). Admittedly, I
don't really use this.
- There are several useful rings in Emacs. Sometimes I
forget about them. There's the kill ring, the search ring,
and the mark ring. To cycle through the kill ring
C-y then M-y to cycle through
the last few things killed in the current buffer. They're
always there until the kill ring runs out of room, and it'll
keep looping, so it's a great robust way to save text. The
search ring preserves your previous searches and can save
lots of typing. Use M-p and M-n to cycle through previous
searches. There is a seperate ring for every type of search.
The mark ring is perhaps the most under used and under
appreciated feature of Emacs in my opinion. You can set the
mark with C-<SPC> which will also allow
you to set the region by moving the point, but you can also
move back to the mark and cycle through all your recent marks
in the current buffer with C-u C-<SPC>.
Using the mark ring in conjunction of searching is a great
way to zip around a file quickly. Makes me wonder why we even
need mice.
- Macros, Macros, and more Macros. Never forget about
Macros. C-x ( to start one, and C-x
) to finish it off. C-x e to execute
it. C-u C-x ( to execute and add more to it.
M-x name-last-kbd-macro to name it for later.
C-x C-k Edit a previously defined keyboard
macro, and M-x
apply-macro-to-region-lines to run it over your
highlighted region. CVS Emacs has expanding macro
functionality. There is now a macro ring that preserves the
last few macros, and start-kbd-macro and end-kbd-macro have
bindings to F2 and F3. Don't forget M-x
insert-kbd-macro, I have a tendency to write useful
macros out to a hidden file in the working directory of a
project called ".macros.el" so I can load 'em later. If you
want to make a named keyboard macro the current keyboard
macro, just define another macro and call the macro via
M-x
- Dired is awesome once you get used to it. I've heard that
people who despise Emacs will use it. It's the ultimate tool
to clean up Emacs' poo (backup files, auto-save files, etc.);
search the contents of each file in a directory structure for
a regular expressions; copy, compress and make backups; load
and compile elisp libraries; and batch rename files. Pop into
a directory with C-x C-f. Use this awesome
sequence of commands to rename a series of files based on
regular expressions: * % <type your regular expression
with groupings> RET new name with groupings. If you don't
know regular expressions yet, this is a very good reason why
you should learn them ;).
- Emacs is the ultimate BBEdit
for unix when it comes to converting ascii formats and
character sets. C-x RET f let's you change
what format the text you're working on is for writing. A
super quick way to convert Mac->PC->Unix Ascii.
- Any character can be typed in Emacs by quoting it with
C-q. The rest is up to your terminal emulation software and
its ability to send that character.
- Info-directory-list is a useful variable
for maintaining locally installed Info documentation. If you
don't have root on a machine, it's impossible to install Info
documentation site wide so you'll need to use this variable.
However, the better mechanism is to set the INFOPATH
environment variable. This can be tricky, because you need to
explicitly point INFOPATH to site-wide directories as well.
Mine looks like this on the SDF:
INFOPATH="~/.elisp/info/":"/usr/pkg/info/":"/usr/share/info/"
That Block Game
A simple Tetris clone I wrote in Pygame. For free as in beer
and in freedom under the GPL v2.
Hangman
What computer isn't complete without a game of hangman? Written in C++,
uses getopt.h, so it might not compile on windows.
hangman.cpp
My speed tests for my comcast connection. Not bad if I do say so
myself.
