Entries from November 2002 ↓

Learning Japanese

I started a Japanese language course at the EIC Japanese Language Center. I only have 3 weeks left in London, and 2 evenings per week available for lessons. Normal lessons would not suit because my existing knowledge of Japanese is weird: I understand some advanced grammar but my vocabulary is miniscule. The staff at EIC handled my requirements very well, and I really like my new set of flash cards.

Origami with Vim

Imagine you have a sheet of A4 paper with some of your code printed on it. (You need a good imagination; maybe you should go and print some code now…) Now find the start of a block, any block. Carefully make a mountain fold just below the first line of you chosen block, then make a valley fold in the middle of your block. Now look at your code.

You chosen block has vanished, apart from the first line, but the rest of your code is still visible. Now, assuming you know what the missing block does, your code is easier to read because it fits on a smaller page. Wouldn’t it be great if you could fold your screen?

Vim can do this for you, without damaging any hardware.

Look at your (imaginary) sheet of paper again. Lift it up to eye level and look at its side: your fold is Z shaped; so vim uses the z character for folding commands:

  • zo opens a fold so you can see the hidden parts;
  • zc closes a fold, hiding its contents;
  • zf creates a fold that you mark with a cursor movement;

For all the details, see :help folding in Vim.

If you’re using Perl and you want Vim to automatically make folds for your blocks and POD, add the following to your .vimrc:

  let perl_fold = 1
  let perl_fold_blocks = 1

Indenting code

Code indentation is a good idea (although probably not as good an idea as the Python people think), so Vim will indent your code for you.

First, put filetype plugin indent on in your .vimrc to enable the smart language-specific indentation algorithms (and other fancy features). If you don’t you’ll be using the simple old-vi-compatible indentation.

That’s mostly it. As you edit, vim will indent.

If you need to reindent an entire file, goto the first line and type =G in non-insert mode.

DHCP

Now that I have a DNS server that can be easily redirected, I needed a DHCP client that could easily redirect it. I had been using pump, but there didn’t seem to be an easy way to make it write the resolver data to somewhere other than /etc/resolv.conf. I knew that dhcpcd would be able to do it, but it always seemed to be over-complex, and I think it relies on netlink devices.

I tried udhcpc and I was pleased. It has a clear division between DHCPing and configuring the network: it will DHCP then simple sends all the information it received to a seperate configuration script. I can replace this script with anything I want, so I can do all my strange configuration. I liked this so much that I have decided to move all my non-DHCP configuration to a compatible format.

Caching DNS

I move my GNU/Linux laptop bewteen different networks quite regularly, and I’ve never been totally happy with its configuration. Many other people do the same thing, and they have a few different methods for auto-configuring networking. But none of them seem perfect for me.

I used to use pdnsd, and it worked well when I knew the nameservers for each network I connected to. The pdnsd.conf contains a list of nameserver details, and allows you to configure tests to check if those servers are available.
When I move between networks I could also use pdnsd-ctl to explicitly enable an appropriate set of nameservers. But this isn’t very useful when I connect to a new DHCP network where I don’t have the details of the nameservers until I connect. I could write a script to dynamically rewrite the pdnsd.conf, but this seems a bit messy.

After some research (in the Debian package list) I choose dnsmasq.
It doesn’t have a persistant cache like pdnsd, and it won’t let me configure a whole set of nameservers like pdnsd, but it does allow me to easily change the default nameservers to use for forwarded queries.

By default, dnsmasq uses /etc/resolv.conf (like everything else) to get the addresses of nameservers to contact, so when dnsmasq is running on a firewall, the internal machines can use the firewall machine as nameserver. But I don’t want that. I want my resolv.conf to have the loopback address as the nameserver, and I want dnsmasq to read from another file. This is trivial to setup, and that is why I’m now using dnsmasq.

A long time ago…

It’s been more than a month since I’ve written anything here, and lots of things have happened in that time. I’ll like to promise that my blog will catch up with my life, but I’d break that promise tomorrow. Some events from the past may appear here in the future (especially the ones with pictures), but it will not be complete.

So I’m starting afresh. After some helpful advice from Marc (Don’t panic: I only took his advice, not his really bad drugs!) I have a new plan for my blog, starting tomorrow. I hope you like it.