[Back to the Front Page]

Bash Cheat Sheet

There are a lot of useful shortcuts on the bash command line. This site is a thorough overview of some common and more obscure ones. What I really need to learn them though is a cheat sheet to stick up next to my monitor - so I made one.

Added 20080826

perl raytracer

Having seen a rather nice looking raytracer written in C#, I thought I'd look at the code to learn some raytracing, and play around with getting it working in perl. As it turns out perl is a comfortable language for this. Sprinkle with a touch of SDL, and you get a perfect reproduction of the original render.

Code here

Added 20080826

Hidden files in the Gtk2 File Selector

For whatever reason, Gentoo or Gnome or some other djamfool have suddenly decided to take it upon themselves to show hidden files in the Gtk2 file browser. This means you get tonnes of .dot directories cluttering up the view. The fix is to change the ~/.config/gtk-2.0/gtkfilechooser file from:

<gtkfilechooser>
    <location mode="filename-entry"/>
    <show_hidden value="true"/>
    <expand_folders value="true"/>
</gtkfilechooser>

To:

<gtkfilechooser>
    <location mode="filename-entry"/>
    <show_hidden value="false"/>
    <expand_folders value="true"/>
</gtkfilechooser>

Update: Now you can right-click over the list of files, and tick/untick the "Show Hidden Files" box.

Added 20070514

Recovering Gentoo from a broken python

This may be a life saver. I noticed that I have two version of python installed on my Gentoo box. So I thought I'd try uninstalling the old one. This actually uninstalls the latest version libraries leaving me with a warning such as "ImportError: no such module time". This is bad as you cannot use emerge at all not even to emerge python to fix things. To fix, as root:
cd /root
wget http://distfiles.gentoo.org/distfiles/Python-2.4.3.tar.bz2
tar jxvf Python-2.4.3.tar.bz2
cd Python-2.4.3
./configure
make
./python emerge python
cd /root
rm -rf Python-2.4.3*
You are now fixed.

Added: 20060912

A perl print failure case

print can, of course, fail. Most perl programs don't check this, however for obscure and paranoid reasons I wanted to have a reproducible test case for a normal failure. Disk full is one such event, but I didn't want to fill up my laptop to test this. So thanks to the wonders of the loopback, here's how you can. This is a bit convuluted, but you get the idea:
dd if=/dev/zero of=test_fs bs=1024 count=10240
mkfs -t ext3 -q test_fs
mkdir ~/mnt/test_fs
sudo modprobe loop ext3
sudo mount -o loop ./test_fs ~/mnt/test_fs
dd if=/dev/zero of=~/mnt/test_fs/abc bs=1024 count=8243

You now have a 10Mb ext3 partition-in-a-file mounted on mnt/test_fs, with a large file "abc" pretty much filling it. Here is some perl that will fail on a print:
#!/usr/bin/perl
#

open (my $file, ">$ENV{HOME}/mnt/test_fs/def") or die "Can't open file: $!";
my $i = 0;
while (print $file "hello\n") {
	print $i++, "\n";
}
print "print failed: $!";
It gets to 681 on my box before reporting:
print failed: No space left on device

Added: 20060912

Dell E551 Monitor 1024x768 Scan Rates

I'm used to monitors just working with a wide range of scan rates - not this one. Tracking down the correct values was quite tricky (some guys ebay auction listed them). So here are the details you need in your xorg.conf.
Section "Monitor"
    Identifier  "Dell"
    HorizSync   31-54
    VertRefresh 50-120
EndSection

This finally lets you raise the screen resolution to 1024x768 from the default (and tiny) 800x600. This works for me - but please try at your own risk. Changing scan rates can permenantly damage your monitor. I am not responsible for any damage done.

Adding an NE2000 card on an ISA bus

Well, this was a fun one. I have a salvaged HP Brio 71xx machine which does duty as a gentoo http-replicator and portage mirror for my home network (see what a good netizen I am). This machine has 2 PCI slots and an ISA slot. It did have a soundcard in one PCI slot and a nice 3Com NIC in the other PCI slot. However the machine also sometimes doubles up as a spare desktop in the server room. It is quite unsubstantial for this as the max screen resolution I can get is 800x640. For Galeon it means half the screen is filled with buttons and bookmarks and what not, with precious little space for b3ta or popbitch or whatever drivel I am browsing. So when an ISA NE2000 card was on its way to the scrap-pile I rescued it, hoping to get a PCI graphics card down from the loft to improve the desktop capabilities.

ISA is a strange world of mystery, one which plunged me into a DOS-like world of IRQs and IO addresses that it has been over ten years into which I last delved. Most cards I slap into Linux these days Just-Work(tm) This generic NE2000 card didn't. What to do?

Well it turns out the secret to this is the isapnp package. emerge isapnptools, and then run pnpdump. The card was found as the last in the list, described as (NAME "ATIf430/4107577382[0]{ATI AT-2000 PnP Ethernet Network Adapter}"). pnpdump -c >/etc/isapnp.conf sets up your configuration. According to this command my card was on IO 0x240 and IRQ 3. Fancy!

Make sure your card is seated properly, without a wodge of dust in the slot - this stops it working. Then add isapnp to your start up: rc-update add isapnp default.

You now need to add NE2000 support to the kernel (You did already enable ISA bus support in "Bus Options"? Yeah, you did. Right?). This is a quick trip down the device drivers section. This should do it:

Device Drivers->Network Device Support->Ethernet (10 or 100Mbit)->[*] Other ISA cards-><M> NE2000/NE1000 support

Make, and install your new kernel. You now have a kernel modules called "ne" that supports this card.

Now you have to tell the kernel about the inner details. Create a file called (this is Gentoo specific) /etc/modules.d/net It should contain what you learned about the card earlier. Mine says this:

alias eth0 ne
options ne io=0x240 irq=3

Now, as I was replacing a PCI ethernet card I already had my network configured. So you'd think you just need to reboot. Right? WRONG Gentoo gets itself in a twist because by default it loads net.eth0 and then isapnp. Which means the ISA bus layer isn't ready, and net.eth0 fails Oh dear. The solution is simple. Edit net.eth0 and change the lines that say:

# For pcmcia users. note that pcmcia must be added to the same
# runlevel as the net.* script that needs it.
depend() {
use coldplug hotplug pcmcia usb isdn wlan

To add isapnp

# For pcmcia users. note that pcmcia must be added to the same
# runlevel as the net.* script that needs it.
depend() {
use coldplug hotplug pcmcia usb isdn wlan isapnp

And, and this bit is very important, run modules-update. Now reboot. There should be great joy as your card works. And hey! Nice man that I am, I've even opened a Gentoo bug to get net.eth0 fixed proper like.

But the bad news is, I never did find that PCI graphics card in the loft. Must have thrown it away. So its a trip to PC World for me to complete this project.

Added: 20050204

Adding sbl-xbl protection to postfix

This is a quick way to add sbl-xbl dnsbl protection to postfix to reduce the amount of spam you receive. Add the following line to your main.cf file:

smtpd_client_restrictions = reject_rbl_client sbl-xbl.spamhaus.org, permit

You can monitor this by grepping your mail log for NOQUEUE. Hopefully you'll see lots there.

Update: There's lots more good information about spam prevent with postfix in this article by Kirk Stauser.

[Back to the Front Page]

(c) Jon Mitchell