A Django site.
October 7, 2008

Byron Clark
byronc
byronc bits
» application/vnd.fdf and pdftk

So, if a webserver ever serves you a fdf file, you can view the resulting form with evince or your favorite pdf viewer. Just check the beginning of the fdf file to see which form the fields should be applied to and then run

pdftk form.pdf fill_form my.fdf output filledform.pdf

August 15, 2008

Byron Clark
byronc
byronc bits
» Mercurial Presentation

I'm presenting on Mercurial at the Utah Python Users Group tonight. Probably not as useful without the demos, but here are my slides: mercurial.pdf. Sadly, the slides really just seem to be my notes on a pretty background.

August 13, 2008

Byron Clark
byronc
byronc bits
» Using the verbatim Environment and listings Package with Beamer

I finally figured out how to make the verbatim environment work with Beamer. Beamer can't handle the following code:

\begin{frame}{A Title}
    \begin{verbatim}
    Don't mess with my text.
    \end{verbatim}
\end{frame}

To make it work, you need to include the fragile option for the frame. Example:

\begin{frame}[fragile]{A Title}
    \begin{verbatim}
    Don't mess with my text.
    \end{verbatim}
\end{frame}

If you use the listings package, the same trick works for the lstlistings environment.

July 4, 2008

Byron Clark
byronc
byronc bits
» VirtualBox OSE Additions 1.6.2

Better late than never, right? I finally updated the VirtualBox OSE Guest Additions for Windows to the 1.6.2 release last night. Nothing too exciting, although the installer actually supports upgrades now and the tray icon shipped with VirtualBox looks better.

March 28, 2008

Byron Clark
byronc
byronc bits
» The Vimperator Strikes Back

I don't know why I put off trying it for so long, but Vimperator is incredibly cool. Now I really can drive almost everything I use with the keyboard, and with Vi-like keybindings to boot.

February 23, 2008

Byron Clark
byronc
byronc bits
» Utah Sales Tax Information

It seems to me that sales tax in Utah used to be 6.25%. Then an extra 1% was added to prepared food. Then other small chunks were added in. If you've ever wanted to see the sales tax breakdown for where you live, there's a helpful chart on the Utah state website.

April 12, 2007

Byron Clark
byronc
byronc bits
» VirtualBox OSE Additions Installer

If you've been running Windows in VirtualBox OSE you've probably noticed that it doesn't include a prebuilt copy of the guest additions. I've been working on a project so that you won't have to setup a build environment on a Windows box and then install the drivers by hand on your virtual machine. So, here it is, a VirtualBox OSE Windows Guest Additions Installer. It should work on Windows 2000, XP, and Vista, but has only been tested on XP.

March 17, 2007

Byron Clark
byronc
byronc bits
» Editing ViM Macros

At the BYU UUG meeting this week, Peter mentioned a great ViM trick that I've never seen before. Here's my feeble attempt to document it.

Because ViM macros are stored in registers they can be edited. This means that if you create a long macro and then realize that you forgot to send the cursor to the beginning of the line before finishing the recording, you don't have to create the entire macro again, you can just add the motion command. You use it like this:

  1. Start recording your macro by typing q and then the single character ([0-9a-zA-Z"] are allowed). The single character is the register your macro will be stored in.
  2. Enter the commands you want included in the macro.
  3. Type q to finish recording the macro.
  4. At this point you could run the macro by using @ and the register name.
  5. To modify the macro, move to a blank line and type "Rp replacing R with the register name of your macro. This will paste all the commands in your macro to the current line.
  6. After making the changes you need, save the macro by typing 0"Ry$ replacing R with the register name you want to use for the macro. The register name does not have to be the same as the original.

February 14, 2007

Byron Clark
byronc
byronc bits
» Python TUI Programming

I've heard rumblings about Urwid occasionally; today I actually had a chance to use it. For those who haven't seen it before, Urwid is a pure Python library for console user interfaces. It can uses curses as the backend or speak directly to the terminal emulator. The library isn't too complex and as long as you can pick colors better than I can the TUIs look pretty nice. Check it out the next time you don't want to write a GUI.

August 14, 2008

Byron Clark
byronc
byronc bits
» Mercurial Presentation

I'm presenting on Mercurial at the Utah Python Users Group tonight. Probably not as useful without the demos, but here are my slides: mercurial.pdf. Sadly, the slides really just seem to be my notes on a pretty background.

August 13, 2008

Byron Clark
byronc
byronc bits
» Using the verbatim Environment and listings Package with Beamer

I finally figured out how to make the verbatim environment work with Beamer. Beamer can't handle the following code:

\begin{frame}{A Title}
    \begin{verbatim}
    Don't mess with my text.
    \end{verbatim}
\end{frame}

To make it work, you need to include the fragile option for the frame. Example:

\begin{frame}[fragile]{A Title}
    \begin{verbatim}
    Don't mess with my text.
    \end{verbatim}
\end{frame}

If you use the listings package, the same trick works for the lstlistings environment.

July 4, 2008

Byron Clark
byronc
byronc bits
» VirtualBox OSE Additions 1.6.2

Better late than never, right? I finally updated the VirtualBox OSE Guest Additions for Windows to the 1.6.2 release last night. Nothing too exciting, although the installer actually supports upgrades now and the tray icon shipped with VirtualBox looks better.

March 28, 2008

Byron Clark
byronc
byronc bits
» The Vimperator Strikes Back

I don't know why I put off trying it for so long, but Vimperator is incredibly cool. Now I really can drive almost everything I use with the keyboard, and with Vi-like keybindings to boot.

February 23, 2008

Byron Clark
byronc
byronc bits
» Utah Sales Tax Information

It seems to me that sales tax in Utah used to be 6.25%. Then an extra 1% was added to prepared food. Then other small chunks were added in. If you've ever wanted to see the sales tax breakdown for where you live, there's a helpful chart on the Utah state website.

April 12, 2007

Byron Clark
byronc
byronc bits
» VirtualBox OSE Additions Installer

If you've been running Windows in VirtualBox OSE you've probably noticed that it doesn't include a prebuilt copy of the guest additions. I've been working on a project so that you won't have to setup a build environment on a Windows box and then install the drivers by hand on your virtual machine. So, here it is, a VirtualBox OSE Windows Guest Additions Installer. It should work on Windows 2000, XP, and Vista, but has only been tested on XP.

March 17, 2007

Byron Clark
byronc
byronc bits
» Editing ViM Macros

At the BYU UUG meeting this week, Peter mentioned a great ViM trick that I've never seen before. Here's my feeble attempt to document it.

Because ViM macros are stored in registers they can be edited. This means that if you create a long macro and then realize that you forgot to send the cursor to the beginning of the line before finishing the recording, you don't have to create the entire macro again, you can just add the motion command. You use it like this:

  1. Start recording your macro by typing q and then the single character ([0-9a-zA-Z"] are allowed). The single character is the register your macro will be stored in.
  2. Enter the commands you want included in the macro.
  3. Type q to finish recording the macro.
  4. At this point you could run the macro by using @ and the register name.
  5. To modify the macro, move to a blank line and type "Rp replacing R with the register name of your macro. This will paste all the commands in your macro to the current line.
  6. After making the changes you need, save the macro by typing 0"Ry$ replacing R with the register name you want to use for the macro. The register name does not have to be the same as the original.

February 14, 2007

Byron Clark
byronc
byronc bits
» Python TUI Programming

I've heard rumblings about Urwid occasionally; today I actually had a chance to use it. For those who haven't seen it before, Urwid is a pure Python library for console user interfaces. It can uses curses as the backend or speak directly to the terminal emulator. The library isn't too complex and as long as you can pick colors better than I can the TUIs look pretty nice. Check it out the next time you don't want to write a GUI.

April 13, 2007

Byron Clark
byronc
byronc bits
» VirtualBox OSE Additions Installer

If you’ve been running Windows in VirtualBox OSE you’ve probably noticed that it doesn’t include a prebuilt copy of the guest additions. I’ve been working on a project so that you won’t have to setup a build environment on a Windows box and then install the drivers by hand on your virtual machine. So, here it is, a VirtualBox OSE Windows Guest Additions Installer. It should work on Windows 2000, XP, and Vista, but has only been tested on XP.

March 17, 2007

Byron Clark
byronc
byronc bits
» Editing ViM Macros

At the BYU UUG meeting this week, Peter mentioned a great ViM trick that I’ve never seen before. Here’s my feeble attempt to document it.

Because ViM macros are stored in registers they can be edited. This means that if you create a long macro and then realize that you forgot to send the cursor to the beginning of the line before finishing the recording, you don’t have to create the entire macro again, you can just add the motion command. You use it like this:

  1. Start recording your macro by typing q and then the single character ([0-9a-zA-Z"] are allowed). The single character is the register your macro will be stored in.
  2. Enter the commands you want included in the macro.
  3. Type q to finish recording the macro.
  4. At this point you could run the macro by using @ and the register name.
  5. To modify the macro, move to a blank line and type "Rp replacing R with the register name of your macro. This will paste all the commands in your macro to the current line.
  6. After making the changes you need, save the macro by typing 0"Ry$ replacing R with the register name you want to use for the macro. The register name does not have to be the same as the original.

February 15, 2007

Byron Clark
byronc
byronc bits
» Python TUI Programming

I’ve heard rumblings about Urwid occasionally; today I actually had a chance to use it. For those who haven’t seen it before, Urwid is a pure Python library for console user interfaces. It can uses curses as the backend or speak directly to the terminal emulator. The library isn’t too complex and as long as you can pick colors better than I can the TUIs look pretty nice. Check it out the next time you don’t want to write a GUI.

February 8, 2007

Byron Clark
byronc
byronc bits
» Digital Design for Cheapskates

I’m usually a software guy, but I find myself doing more and more digital design these days. One common question I hear get is “What’s a good way for a programmer to get started with digital design?” The good news is that if you get to use an HDL like VHDL or verilog, digital design can be somewhat similar to writing software. Actually writing the HDL code will be the subject of later posts; the point of this post is to help you set up a fairly simple digital design environment using open source software. Please note that this is an area where there are very high quality proprietary tools that you may want to use.

First, we need to decide whether to use VHDL or verilog. These languages look different but the concepts and constructs are very similar so it’s mostly a matter of taste and the tools you have available. In the open source world we have Icarus Verilog for verilog and gHDL for VHDL. After checking the package repository on my Debian box and seeing that gHDL probably isn’t going to make it into the next release it would appear that verilog is the best choice for now. Besides, Sun released the design for the OpenSPARC-T1 as verilog code. We’ll also need a waveform viewer to view simulation results. GTKWave seems to work fairly well with Icarus Verilog.

After installing both of those packages, it’s time to write some code. I wrote a simple D Flip-Flop for demonstration. Since wordpress will probably eat the code if I include it in the post you can download the module and testbench with these links: module: dff.v, testbench: dff_tb.v. Please don’t mock my verilog code too much, I haven’t written any before today.

After downloading the two files you can build them with Icarus Verilog using the command: iverilog -odff dff.v dff_tb.v.

You can now run the simulation:

$ vvp dff
VCD info: dumpfile dff.vcd opened for output.
d=0, q=x
d=0, q=0
d=1, q=0
d=1, q=1
d=0, q=1
d=0, q=0

After running the simulation, you can use GTKWave to examine the internal state:

  1. gtkwave dff.vcd
  2. Add the waves you want to see by clicking on Search->Signal Search Regexp
  3. Use the signal search box to select all the signals in the d_flip_flop instance.
    GTKWave Signal Search Window
  4. Examine the waveform to make sure the module worked properly.
    D Flip Flop Waveform

January 21, 2007

Byron Clark
byronc
byronc bits
» Getting Started with VirtualBox

Earlier this week, VirtualBox was released under the GPL (with one piece under the LGPL). I had a chance to try it out today and was very pleasantly surprised. There are no official tarballs, so I had to use subversion to check out a copy of the code. I followed the Linux host build instructions and had a working install in under 25 minutes. I had been worried that the build would take forever because they include a portion of the Mozilla sources, but my fears were unfounded. Note that your build times should be much better, my build machine is a Pentium 3 1.13 GHz laptop.

The GUI looked good and finding what I needed was easy enough. Creating and running a virtual machine was simple. I immediately installed Windows XP and didn’t run into a single problem. The virtual machine feels more than fast enough for my needs.

The only thing I needed that was not included in the open source edition was a pre-built version of the Windows Guest Addition. I mostly wanted the tool to resize the virtual machine display to the current window size. I’ll be working on setting up the build environment for that in the next few days. It’s too bad they can’t be cross compiled but understandable because the required tools include the Windows Driver Development Kit.

Thank you, InnoTek, for a great tool.

January 19, 2007

Byron Clark
byronc
byronc bits
» Happy Iceweasel Day

In honor of Iceweasel landing in Debian etch it’s time for a list of the iceweasel/firefox extensions that I just can’t live without.

  1. Adblock Plus. That one should be pretty obvious.
  2. Download Statusbar. The download manager window gets on my nerves, especially because ion3 and non-transient windows like the download manager become full frame windows. Still, I like to see progress on my downloads.
  3. Fission. Shows page loading progress in the address bar, somewhat like Safari. For those of us stuck on 1024×768 (or smaller) monitors it means some saved screen real estate because the status bar can go away.

January 18, 2007

Byron Clark
byronc
byronc bits
» How do I do that in a C Program?

Yesterday, Topher asked the plug mailing list how to get your IP address from C. He got the answer on the mailing list, but I wanted to add a little bit about how to find answers to questions like this.

When I want to figure out how to get or set some bit of system information programmatically it always helps to try to rephrase the question. Instead of asking “How do I do foo programmatically?” I like to ask “Is there a program that does foo?” If there is a program that has similar functionality, here are three helps to find out how it works, in order of increasing difficulty.

  1. strace
  2. browse manual pages in section 2
  3. use the source

strace

strace will show all the system calls a program makes, along with many of the arguments passed to them.

If I wanted to programmatically find the target of a symbolic link and didn’t know the system call to use, here is how I would use strace to find out.

byron@thinktank:~$ touch foo
byron@thinktank:~$ ln -s foo bar
byron@thinktank:~$ ls -l bar
lrwxrwxrwx 1 byron byron 3 2007-01-17 21:56 bar -> foo
byron@thinktank:~$ strace -o ls.strace ls -l bar
lrwxrwxrwx 1 byron byron 3 2007-01-17 21:56 bar -> foo

I start by creating a symbolic link bar that points to foo. I then find a utility that has the functionality I want, in this case ls finds the target of a symbolic link and prints it. The next step is to run strace, the -o option sends the output to a file instead of stderr. The next step is to examine the ls.strace file created by strace. The file is a little long, 204 lines on my system so I won’t post it all here. The first part of most strace output is a series of calls to access, open, and some form of mmap; this is dynamic linking in action and, unless this is the part of the trace you cared about, can be skipped. Because we told ls to only list file bar we can search for that filename to see if it is ever used; it is, and only on the following lines:

lstat64("bar", {st_mode=S_IFLNK|0777, st_size=3, ...}) = 0
readlink("bar", "foo", 4) = 3

Checking the man pages, it would appear that readlink(2) is the system call we need to use to find the target of a symbolic link.

That’s a simple example, but the same principles apply for any application, just be prepared to wade through a lot of system calls.

Manual pages in section 2

You can greatly reduce the time spent reading strace dumps if you are familiar with the system calls in manual page section 2. All it takes is ‘ls /usr/share/man/man2‘ and some reading. Of particular interest is the ioctl_list(2) manual page. Operations that don’t map cleanly to a read or write are often implemented using ioctl(2). While ioctl_list(2) doesn’t document how to use all of the ioctls it does at least list the codes and the arguments they expect. For real documentation your best bet is to grab the Linux kernel source and search for the ioctl you want to use. Of special note are the network ioctls, they are always performed on a socket and are of the form SIOCG.* for getting information and SIOCS.* for setting information.

Use the source

If the other methods fail and you have the source to the application, don’t be afraid to use it. I list this method last because I can usually find what I need with a quick strace and sometimes it takes quite a bit longer to get into the source for an application. Still, the source is the ultimate reference and isn’t hard to read.

A better example

If you have a better example for me to strace and dissect, let me know.

January 1, 2007

Byron Clark
byronc
byronc bits
» My Favorite Wireless Card

I recently found myself in the market for a new wireless card for my linux laptop. Getting a card that worked well with a minimum of hassle was not as obvious as I had hoped, so I thought I should share.

Here’s what I wanted:

  • PCMCIA or CardBus (the laptop doesn’t have a mini PCI port)
  • Supports WPA/WPA2 (mostly depends on the driver)
  • Working driver, not named ndiswrapper, in the mainline kernel

These requirements limited my choices significantly. The only real options for drivers in the mainline kernel that support WPA are the Intel cards and Prism 2/2.5/3 cards. I’ve never seen one of the Intel cards except as mini PCI so I decided to get a Prism based card. The downside is that they only do 802.11b, but the upside is that they use the hostap driver which works beautifully. It even allows using hostapd to turn your laptop into an access point if needed. I consulted the somewhat out of date chipset list at http://www.linux-wlan.org/docs/wlan_adapters.html.gz and eBay and decided on the Linksys WPC11 v2.5.

Once the card arrived, I immediately updated the primary firmware to version 1.1.1 and the station firmware to version 1.8.2. I later tried station firmware version 1.8.4 and experienced serious packet loss that went away on reverting to version 1.8.2.

The card works perfectly and I don’t think I’ve ever been this happy with wireless on linux before.

December 18, 2006

Byron Clark
byronc
byronc bits
» aspell and LaTeX

I write a lot of things in LaTeX and always get annoyed when aspell complains about my LaTeX tags being mispelled. Imagine my surprise when I discovered that aspell has a TeX mode so that it will ignore the tags. 'aspell -c -t <myfile.tex>' invokes the proper magic.

December 16, 2006

Byron Clark
byronc
byronc bits
» orpie

Chances are that if you ever used an HP-48 series calculator you’ve never wanted to use anything else. Well now you can save space in your laptop bag by replacing the calculator with orpie. orpie is a terminal based RPN calculator that will make you curse all the time you wasted trying to use bc, dc, and calc.exe.

ps - The cygwin version works just fine if you’re stuck on Windows.