linux

You are currently browsing articles tagged linux.

Lately I’ve been working on a pretty hefty spec for work (hint hint… it’s a REST API spec). I like writing my specs in TextMate using MediaWiki markup, so I can easily post them to our internal wiki once they’re ready.

One of the annoying things about this spec is that it involves dozens of examples in XML and JSON that are embedded in <pre> tags. I wanted to be able to develop and edit these samples as native XML and JSON files for convenience, but it was becoming a real pain to keep them updated in the main document via cut and paste. The obvious solution to this problem is a text preprocessor that would allow you to include a .xml file in the main .wiki document. There are dozens of these, but they’re all a pain in the butt to use and I didn’t feel like setting them up.

The solution, which couldn’t possibly be more obvious, was suggested, somewhat jokingly, by a coworker of mine:

cpp

Yup, the good old GNU C Preprocessor. If you run Linux, or you have a Mac (basically, any *nix), or you do any development whatsoever, chances are you have one hiding out on your machine somewhere. Chances are you’re also familiar with the #include "foo.h", which you’ve used since freshman year to have the preprocessor include the header for another C file before it passes it off to the actual compiler. But you never thought about using it to help you with your homework (or your specs) before.

Well cpp has a handy -P parameter that tells it to forgo the inclusion of the normal linemarkers it includes for the benefit of the compiler. This makes it perfect for simple stuff like embedding one text file in another.

In your main document, use a #include statement to include your example file:

document.txt:

== XML Example ==
The following is an example of the server's response in XML:

<pre>
#include "example.xml"
</pre>

example.xml:

<example>
      <message>Hello World!</message>
</example>

Then use a simple Makefile to build your output document:

Makefile:

all:
        cpp -P document.txt document.out.txt

Using a Makefile means you can use TextMate’s Makefile bundle to quickly and easily build your document.

There you go, a completely “duh” way of doing simple text includes on any *nix system.

Tags: , , , , , , ,

Maybe this will save somebody else some time, because I just spend about 3 hours banging my head against the wall on it.

PowerBook Stickers
PowerBook Stickers

If you’re getting a “550-Sender verify failed” error when Monit starts because its trying to send you an email via SMTP to let you know it’s started (or if you’re getting that error for just about any other reason), make sure that the email address that the message is being sent “from” actually exists.

If “monit@yourhostname.com” doesn’t exist, your SMTP server will likely reject the message and cause you all sorts of trouble.

Tags: , , ,

Sam's
Sam's

Yeah, that hurt. Well, everything seems to be working again…

Tags: , , ,

For the longest time I avoided using ACPI for power management on my Thinkpad X31 (instead I stuck with APM) because I could never get all the little hacks lined up properly. ACPI, since it is done primarily in hardware, requires a lot of tricks to get your machine to suspend and resume properly. Switching out of X, turning off LCD backlights, resetting graphics cards, etc etc. Its a real hassle.

However, if you’re fortunate enough to be running Debian Linux, you can install the “hibernate” package. Hibernate is basically sophisticated Bash script with pluggable options for all the most common ACPI hacks. I had ACPI up and running within minutes.

If you’ve got a Thinkpad X31 or similar machine, feel free to download my hibernate.conf and tweak it to your purposes. The only additions beyond a fairly standard hibernate configuration I had to make were adding hooks to turn the Radeon backlight on and off.

Tags: ,

Some Debian developer will probably see this and yell at me for doing something very evil, but I find this trick quite useful and thought I’d share it with the world. You might notice I also made use of it in my Debian Java mini-howto.

The Debian “alternatives” system is basically a set of utilities designed for manipulating what is no more than a complex collection of symlinks. However, the flexibility it affords users is wonderful. It allows the administrator to set up intelligent “default versions” for system utilities such as editors, pagers, and terminals.

And it also, if you abuse it slightly, gives you an easy way to manage applications installed into /opt.

Debian, as you might know, isn’t that great at always packaging applications that don’t agree with its “social contract”. So you’ll usually find yourself jumping through hoops to get anything that involves Java installed. I install apps like Eclipse, Azureus, and VMWare into directories in /opt (/opt/eclipse, /opt/azureus, etc). And then I use update-alternatives to add intelligent symlinks back into the main system:

update-alternatives --verbose --install [desired symlink] [name] [executable location in /opt/whatever] 500

For a specific example: update-alternatives --verbose --install /usr/bin/vmware vmware /opt/vmware/bin/vmware 500

If you also want to install a link for the manpage, you can also do that:

update-alternatives --verbose --install /usr/bin/vmware vmware /opt/vmware/bin/vmware 500 --slave /usr/share/man/man1/vmware.1 vmware.1 /opt/vmware/man/man1/vmware.1

(I know that actually points to the manpage of the vmware XF86 driver, but you get the idea…)

And since all the links are tracked by update-alternatives, I can easily remove them when I uninstall the application: update-alternatives --remove-all vmware

Tags: , ,

« Older entries