Monday, November 30, 2009

C++ typename keyword

I used the "typename" keyword in a C++ program for the first time today. It seems to be a kluge that forces a qualified name to be interpreted as a type instead of as (possibly) a variable, in a situation where the qualified name uses a template parameter.

Friday, November 20, 2009

Meagles

Meagles. 'To be coming in Society which that I do; and going; albeit,
too!' As he last perfectly there Mr F. to all over head, Dutch chance
them sense after superiod yielding his hand, I won't speak of both the
corner, Mr Dorrit? Yes, yes.' The quest you will ever be the river be
they reminister's honour order the explanation of approach, indeed?' 'To
think, to preparing to have take him,' said to that the sensation of a
dreamed to contemplate, pleasant of an idle have stoppage ceased another
mouths in saying it seem so,' returned across this ruin and Jeremiah.
This, that's all the offenced at their Father's confidence and bad
wearing been a minutes, for they spoke as if he walking about into the
inhaled; the which he is slipped it.

Monday, November 9, 2009

OK, I am dumb

This is the correct JUnit assertion:

assertEquals("-1/4", oneFourth.subtract(oneHalf).toString());

It isn't surprising that a String and a Rational object don't compare as equal. Duh.

When is -1/4 not equal to -1/4?

Got this today as the first line of an assertion failure trace in
JUnit:

junit.framework.AssertionFailedError: expected:<-1/4> but was:<-1/4>

This was produced by the following assertion:

assertEquals("-1/4", oneFourth.subtract(oneHalf));

The fields oneFourth and oneHalf are instances of a Rational class I'm working on.

I must be missing something obvious.

Thursday, October 22, 2009

Pandora rules!

I continue to be amazed by how great Pandora is. (There was an article about Pandora in last weekend's NYT magazine - interesting read.)

As evidence of its awesomeness:



I've always suspected that there was a lot of great music out there that I didn't know about, and Pandora has confirmed this theory in spades.

Wednesday, October 21, 2009

Gus Hamilton Hovemeyer

Born Friday, Oct 9th at 11:21 AM, 7 lbs, 15.7 oz.


This is why I haven't posted anything recently :-)

Monday, September 28, 2009

Eclipse galileo software update is ****ing slow!

Why does the latest version of Eclipse (Galileo) take so long to install software updates?

It seriously takes 5-6 minutes to install a package that has already been downloaded! There is no disk I/O, and only about 10% CPU utilization! What the **** is it doing?

OK, it's not actually 5-6 minutes, but it sure ain't fast.

TortoiseSVN weirdness

I had tremendous difficulties today trying to connect to a svn+ssh repository on a Solaris server using TortoiseSVN on a Windows client. I kept getting error messages of the form "network connection closed unexpectedly" with no explanation. Fortunately, I was able to find a workaround (see below).

I think the problem was bash on the server: every non-interactive ssh login was printing error messages to stderr, and for whatever reason TortoisePlink (the ssh client included with Tortoise) could not deal with these. I am not absolutely certain that this explanation is correct, but here is my reasoning, based on trying various combinations of svn and ssh clients on Windows:
  1. cygwin svn / cygwin ssh: worked fine (the error messages were visible, but ignored, and the svn operation worked)
  2. collabnet svn / TortoisePlink: "network connection closed unexpectedly"
  3. collabnet svn / cygwin ssh: worked fine!
I worked around the problem by changing my login shell to /bin/tcsh on the Solaris machine: that made the error messages go away, I guess because bash is installed incorrectly on that machine.

Once I changed my login shell to eliminate the error messages, the latest version of Tortoise (1.6.5) was able to connect to a remote svn+ssh repository.

Now, if I could somehow get back the hours I spent figuring this out... :-)

Wednesday, September 16, 2009

Dick Morris on YCP

There is an interesting post on Dick Morris's blog about York College of Pennsylvania, and how YCP has kept costs down while maintaining educational quality:

http://www.dickmorris.com/blog/why-is-college-so-expensive/

I think his general point---that most colleges and universities spend huge amounts of $$$ on things that contribute nothing to the education that students receive, and that these costs are ultimately borne by students---is well taken.

Sunday, September 6, 2009

74hc163 symbol/device for Eagle CAD

The 74xx-us library for Eagle CAD does not include support for the 74xx163 counter IC. I made a small library which includes it. The library is here:

http://faculty.ycp.edu/~dhovemey/DHH-74hc163.lbr

Only the DIL16 package (a.k.a. DIP or PDIP) is supported. I have not tried creating a board using the library, so caveat emptor.

Monday, August 31, 2009

74hc163 problem - solved

My colleague Greg figured out why my 74hc163 counter IC wasn't working. The problem was not the counter - it was the 74hc04 IC I was using as an ersatz logic probe. With the 150 Ohm resistors I was using, the LEDs were consuming more current than the 74hc04 could supply.

Greg gave me a ULN2803A peripheral driver IC which is capable of sinking 500 mA per pin, which is more than ample for lighting an LED. I modified my "logic probe" circuit, and now everything is working nicely. As a side-benefit, I now have 8 inputs rather than just 6.

A picture:


Now the 74hc163 properly rolls over from 1111 (15) to 0 (0000). Next experiment - cascading two 74hc163's to make an 8-bit counter.

Friday, August 28, 2009

Hmm...now I'm confused

I replaced the 74HC163 which was behaving strangely with a 74LS163. I also changed my "logic probe" circuit to use a 74HCT04 instead of a 74HC04 for the inputs, in order to cope with the LS-TTL output levels.

Well, strangely enough, the modified circuit also jumps from a count of 1111 to a count of 0001. Obviously, there is something I don't understand about the '163.

Feh.

74hc163 counter has a bug?

I have been playing around with some 74hc163 chips that I have. These are 4-bit synchronous counters with a parallel load capability. When both counter-enable inputs are logic high, and a positive clock edge arrives, the counter value increases by 1.

Oddly, the 74hc163 chips that I have seem to have a bug! When the counter value is at 1111 (i.e., 15, the highest possible count), and a positive clock edge arrives, the count changes to 0001 rather than 0000. From all of the 74hc163 datasheets I have seen, the count should wrap-around back to 0.

I'm pretty sure I have wired the circuit correctly. There are no floating inputs, for example.

The chips are labeled "SP74HC163N", and the manufacturer seems to be "SPI".

Here's a picture of the circuit with the 74hc163:


The following two pictures show LEDs which follow the '163 output. The 4 LEDs to the left are bits 0 through 3 of the count. The two LEDs on the right are showing the values at the -LOAD and enable inputs. (Note that they are both high, meaning that the counter is in counting mode.)

Here's how things look when the count is at 1111:


And here's how things look after one positive clock edge:


That's clearly not zero!

Saturday, August 22, 2009

Neat logic synthesis freeware

I was trying to minimize a boolean circuit for a project I'm working on, and I found a really nice program called Simple Solver:

http://home.roadrunner.com/~ssolver/index.html

You type in a truth table, and it spits out a boolean equation and/or circuit that generates the correct output. You can constrain the part types, which of course is very useful if you're using discrete parts (e.g., 74HC gates).

For the problem I gave it, Simple Solver found a solution using 4 NAND gates, which exactly fits in a single 74HC00. Sweet.

Simple Solver can also generate circuits using flip-flops based on user-specified timing diagrams, which is a feature I'm planning to investigate at some point.

Friday, August 21, 2009

Electronics stuff

I've been having a lot of fun playing with electronics this summer. I completed my AVR microcontroller project, which involved designing a custom circuit board and having it manufactured. More details soon.

Since I feel like I have a reasonable handle on working with AVRs, I'm currently taking a step back, and learning about low-level digital circuits - gates, flip-flops, etc.

Several important issues arise when building digital circuits:
  1. You need to have a power-on reset to get all of the stateful circuit elements into a well-defined initial state
  2. You need a clock source
  3. To understand what is going on in the circuit, you need a way of visualizing the logic levels at important points
I solved the first two problems by constructing a small circuit with six pushbuttons, using a switch debouncing circuit I found in the Microcontroller Idea Book. Each button controls a single output pin. A button press causes the output pin to go low, and a button release causes the output pin to return high. Since a 74HC14 Schmitt-trigger hex inverter IC is used, there are six buttons/outputs. A picture:


The thing at the lower-right with the two wires sticking out of it is a single-row header socket, which is very handy for allowing wires to be plugged into a circuit on the fly. I will spare you a picture of the underside, where you can see how bad I am at soldering things. In any case, the thing works, and is useful for generating both reset and clock signals.

I addressed problem number 3 (visualizing logic levels) using a pair of 74HC04 (hex inverter) ICs to control 6 LEDs. Each input is fed through a pair of inverters, where the output of the second inverter controls the LED. So, the LED is lit if the input is high, and is dark when the input is low. Basically, each input is a really simple logic probe. (I found out by experience that you can't use a 74HC output to both light an LED and also drive an input.) The only minor hassle is that you have to tie the unused inputs to ground, but that's not a big deal. A picture:


Here, the LEDs are showing the output of (one half of) a 74HC139 2-to-4 decoder driven by a 74HC74 dual D-type flip-flop used as a 2-bit counter. When the clock button is pressed, the dark LED (the '139 decoder has active-low outputs) cycles through positions 0 (left) through 3 (third LED from the right). The last two LEDs are unused.

Monday, July 13, 2009

AS1106/AS1107 LED display drivers

I've been using the max7219 to control 7-segment LED displays. They're nice, and easy to use, but they're expensive (around $10).

I discovered today that there is a cheap alternative: the AS1106 and AS1107 from Austria Micro Systems. They appear to be functionally identical to the max7219 and max7221, respectively. And, you can buy them from Newark for $4 in qty 1. Sweet.

I've ordered some samples, so we'll see how they work out...

Friday, June 26, 2009

Super-nifty perl script for cropping pdf files

I often need to include a PDF file in a LaTeX document. This works great if the PDF file has a reasonable bounding box, but most software exports PDFs as full-page.

I found a really great perl script that will crop a PDF by settings its bounding box to precisely enclose the PDF file's contents:

http://ctan.org/pkg/pdfcrop

I used it on a couple PDF tables produced by (gag) Microsoft Word 2007, and it worked great.

Thursday, June 25, 2009

Fun with 7-segment LED displays

Here's a circuit with an atmega8 hooked up to a max7219 7-segment display driver chip, with six 7-segment LED displays:


The max7219 is the chip hidden in the rats nest of wires :-)

There's a ds1305 RTC chip on the breadboard, but it's not connected to anything yet.

Cheap USB AVR programmer

I have been using a serial-port AVR programmer (the Olimex one you can buy from Sparkfun) to do AVR development, but my laptop doesn't have a serial port.

There are a number of USB-based AVR programmers, and they're not particularly expensive (e.g., the Atmel AVR-ISP mkII is $34 from Digikey), but being the cheapskate that I am I was looking for something really inexpensive.

I'm happy to report that I've found one that works very well, and is only $10:

http://alldav.com/index.php?main_page=product_info&cPath=5&products_id=24

I'm using it with Sparkfun's AVR breakout board to bring the programming signals onto a breadboard using a single-row 6-pin cable from Digilent. Here's a picture of the whole setup:


The programmer is the small green board on the left. The breakout board is the even smaller red board connected to the programmer at a right angle.

In the host OS, the programmer appears as a serial port (/dev/ttyUSB0 on my Debian laptop). The programmer type for avrdude is "stk500v2".

As an additional bonus, the programmer supplies 5V to your circuit, using the host USB port as the power source. I don't think it will source a lot of current, but it's certainly fine for a few ICs and LEDs. The circuit on the breadboard in the picture has an atmega8 and an LED.

Friday, May 15, 2009

The Xfce challenge

Every Linux (and BSD) user who is currently using Gnome or KDE4 should try Xfce for a week or two.

I've been using Xfce for a couple weeks now, and I can't get over how much more pleasant it is. It's simple. It's unobtrusive. It does what you want with a minimum of fuss. It starts quickly. It reminds me why I use Linux and not a certain commercial OS from a company in Washington state.

I'm now running Xubuntu 9.04 on my desktop machine at work, and I have to say, it's really nice. I take back some of bad things I said about the beta (which utterly failed to connect to any wireless networks on my laptop). The nice thing about having a wired network connection is not having to deal with the disgraceful gnome network manager.

One interesting note about Xubuntu 9.04 is that I have configured it to use nouveau instead of the proprietary nvidia drivers (because the restricted devices manager could not download the latter.) I installed nouveau from the package repository, which apparently doesn't give you 3D acceleration, but I don't care about that.

I had to learn about and futz with xrandr, but eventually I got it completely working with both of my monitors (which are both 1680x1050 widescreens). Here's my xorg.conf if anyone's interested:
http://faculty.ycp.edu/~dhovemey/linux/nouveau-dualhead-xorg.conf

Thursday, April 23, 2009

More Mandelbrot fun

I modified the viewer so that the coordinates of the region being displayed are shown. I also changed the color scheme to show more variation in points close to the set.

Wednesday, April 22, 2009

C#, Mono/Monodevelop, Mandelbrot set

I am teaching a section of CS 101 here at YCP this semester, and we're finishing up the course with a few weeks of C# using Visual Studio. The current assignment is to write a program to display the Mandelbrot set, so of course I had to write my own implementation, which I did. I can definitely recommend it as an enjoyable way to spend an evening

Being a geek, I decided to use multiple threads to speed up the computation, but VMware player (which I use to run Windows XP within Linux) does not appear to emulate multiple CPUs. So, I decided to see if I could compile and run the program using Monodevelop. Sure enough, Monodevelop had no trouble importing a Visual Studio project. I had to fix a couple bugs that hadn't manifested under Windows, but then it worked perfectly.

Obligatory screenshot:


[Yes, I'm still running KDE on my desktop machine. It will be replaced with Xfce after the semester ends.]

Monday, April 20, 2009

Using ncurses and unicode

Here's a useful post explaining how to output unicode characters in an application linked with the ncursesw library:

http://mail.nl.linux.org/linux-utf8/2004-08/msg00001.html

Xfce under Debian!

After my recent switch from using Ubuntu to Debian on my laptop, I decided to try installing Xfce. The standard Gnome environment that Debian provides is nice enough, and refreshingly free from the various broken and unintuitive add-ons that Ubuntu adds (e.g., compiz). However, I've never exactly loved Gnome, and the philosophy of Xfce --- a simple and easy to use desktop environment --- sounded extremely appealing.

Well, all I can say is that using Xfce was like coming home after years in the wilderness. It's plain, it's simple, people who like all sorts of desktop effects would probably say it's boring, but my god, things just work. It reminds me, in a good way, of using fvwm back in the late 90s, except that modern conveniences (e.g., wicd to manage network connections, xfce4-battery-plugin to monitor the battery) are easily available and integrate unobtrusively.

When I started using Ubuntu, I can remember reading articles that expressed the opinion that Ubuntu was trying to turn Linux into Windows. I thought that view was alarmist at the time, but given the recent efforts of both the Ubuntu and Kubuntu projects to drastically reduce functionality and usability in the name of "modernizing" the user experience, I'm forced to conclude that the alarmists were right. There's a quote from Marge Simpson that I think summarizes the situation nicely: in an episode taking place in the near future, she says "Fox turned into a hard-core pornography network so gradually, I didn't even notice."

Friday, April 17, 2009

Debian!

I got fed up trying to figure out why Xubuntu 9.04 beta couldn't connect to the wireless network at work, so I installed Debian 5.0.1 (which is the latest stable release).

The installation went smoothly. (I had to put the firmware blob for the wireless adapter on a USB drive at one point, but that was no big deal.) The default desktop environment is a very plain and boring version of Gnome (2.22.3 according to the "About Gnome" menu item.) I love it! No fancy effects, no stretchy or wobbly windows, no plasmoids, just plain vanilla buttons, menus, and windows. Ahhhhh.... :-)

After a few minutes of fiddling with /etc/apt/sources.list, I was able to install the wicd network connection manager (over ethernet), and a few minutes after that, I was back on the wireless network!

So, Ubuntu, thanks for the memories, and fare thee well. I salute your attempt to become both feature- and bug-compatible with Windows. In the meantime, I'll be getting some work done.

Ubuntu, the Linux desktop, and the second system effect

I'm depressed.

I've been a Linux user since 1994, and the Unix philosophy is an essential part of my lifestyle. The main reason I've used Linux is that it is simply the most productive way for me to get things done.

Since 2005, I've been an enthusiastic user of Ubuntu. At the time, and for several years thereafter, it was (IMO) the best Linux distribution, combining the careful design and usability of Debian with up-to-date hardware drivers and frequent high-quality releases.

However, for the past two years, using Ubuntu has been an increasingly frustrating experience.

The problem began with Ubuntu 7.10, which added Compiz. The precedent that was established by this release was that the addition of useless "eye candy" was considered an adequate justification for major regressions in functionality and usability.

At this point, I abandoned the default Gnome-based Ubuntu in favor of the KDE-based Kubuntu. Version 8.04, based on KDE 3.5, was outstanding. Yes, there were no fancy desktop effects. But everything worked.

Then came Kubuntu version 8.10, with KDE 4.1 as the default desktop environment. In terms of the sheer number of regressions in functionality and gratuitous interface differences, this release eclipsed even Ubuntu 7.10. The backport of KDE 4.2 helped somewhat. But I still spent considerable effort finding work arounds for software that was simply broken. For example, the very nice kpdf program for viewing PDF files was replaced by something called "Okular", which I suppose works OK unless you want to print, in which case you're pretty much screwed. Drag and drop between Linux and Windows XP (running in VMware player) stopped working. The mechanism for configuring panels changed drastically. I could go on and on.

I'm now pinning my hopes on Xubuntu, the version of Ubuntu based on Xfce. I'm now running the beta version of 9.04 on my laptop, and I'm cautiously optimistic, although I have not had any success connecting to the wireless network I use at work. (There appears to be a bug in scanning for wireless networks, and the dreadful Gnome network manager appears to be as buggy as it was the last time I looked at it.) I'm hoping that the release version of 9.04 will prove to be a stable platform. It's simple and configurable, and seems designed with usability in mind.

The evolution of Gnome and KDE, and hence Ubuntu, recalls the Second System Effect. Somehow maintaining a working, stable system is not sufficient, even though that has been the strength of Linux (and Unix in general) for many years. The developers responsible for creating the Linux desktop experience feel that it is necessary to make lots of crazy, unintuitive changes. To put it another way, both Gnome and KDE are beginning to feel a lot like a certain desktop OS from a corporation in the northwest US. And that's not a good thing.

Monday, March 30, 2009

Using git push

I'm starting to use git for some actual work, and am making tentative steps towards not totally sucking at it.

Right now, I'm trying to get a handle on working with remote repositories. In theory, because git is fully distributed, you don't need a central repository. However, I want to use remote repositories to (1) ensure my data is backed up (I have access to a Solaris server with a RAID and regular disk backups), and (2) allow easy synchronization of my work between the various machines I use (office PC, laptop, etc.)

The main idea with git is that repositories and working directories should be inseparable; all work should be versioned. Being a distributed VCS, git gives you lots of ways to synchronize changes between repositories. All well and good.

However, weirdness ensues when you consider what git should do when you push (commit) changes from a local repository to a remote repository. If you push into a remote repository that has a working directory checked out from the branch that you are pushing into, git does weird things. I won't even attempt to describe what happens, since I don't understand it. Suffice it to say that it's not a useful behavior.

One solution, as helpfully pointed out by the git cvs migration help file, is to create the remote repository as a "bare" repository, meaning that it does not have an associated working directory. So, the series of steps is something like:
server$ cd /some/directory && git --bare init

client$ git clone username@server:/some/directory
[ add some files ]
client$ git add files...
client$ git commit -m"Added some files..."
client$ git push origin
The "origin" in git push origin evidently refers to the remote repository from which the local repository was cloned.

Sunday, March 29, 2009

Good book on git

I found a good book on the git distributed version control system:

Pragmatic Version Control Using Git

This is the first good introduction to git (and to distributed version control in general) that I've seen.

Thursday, March 26, 2009

An addictive game

Beware: this is a potential time sink.
MiniGolf.zip [for Windows systems]
See the included README.txt for details.

Screenshot:

Monday, February 16, 2009

Q&A: How to use the command line to create a new top-level Opera window

When I click the "quick launch" button (or whatever KDE calls them) to open a web browser, I like to have a new top-level window, not a tab of an existing browser window.

Opera, by default, creates a new tab in an existing window.  So, I hunted for a command line option to force it to create a new window.  Here are the command line options:

http://www.opera.com/docs/switches/

Sure enough, there's a -newwindow option to create a new window.  I try it, and what does it do?

It creates a new tab in an existing window.

Thanks, Opera.

Thursday, February 12, 2009

Firefox working again

A reboot seems to have cleared up yesterday's firefox issue. Weird.

I guess I should probably quit out of firefox when a package update is being installed.

Wednesday, February 11, 2009

Firefox broken by update to Kubuntu 8.04

I received an update for firefox today on my main office machine (running Kubuntu 8.04), and firefox is now completely broken.  All it does now is exit immediately with a 0 exit code.

I have temporarily switched to Opera, which seems quite nice.

Tuesday, January 20, 2009

Reset your windows password

I forgot my windows password recently. Fortunately, if you can boot from a CD, the following Linux-based utility will allow you to easily reset passwords:
http://home.eunet.no/pnordahl/ntpasswd/
W00t.

Friday, January 2, 2009

More finds from Pandora

Pandora continues to be an amazing way to discover new music. Two recent finds worth mentioning:

1. The Changes. I'm not quite sure how to classify them. Maybe if you threw Fine Young Cannibals, A-ha, The Smiths, and Wham into a blender, adding a dash of Joe Jackson, you'd end up with something like The Changes. I received their album Today Is Tonight for X-mas, and it's excellent. Plenty of big obvious hooks, with a lot of substance underneath. Sort of like the Killers, but better.

2. Guided By Voices. I received their album Earthquake Glue for X-mas, purely so that I would have a copy of the song The Best of Jill Hives, which would easily be on my list of the best songs ever. I'm actually a bit obsessed by this song at the moment---I think it might be perfect. I'm not quite sure where the rest of the songs on the album fall, but there's certainly some good stuff there.

Static fields and methods are unnecessary

Happy new Year! Right now I'm in Hilton Head, South Carolina on the last day of a family vacation. (Ah, vacation.)

I've been thinking quite a bit lately about how to design a very simple dynamic object-oriented language along the lines of Ruby. Every value should be an instance of an object, etc.

One ugliness that I wanted to avoid was the need for static fields and methods. However, for things like the standard input and output streams, you don't want to have to create new instances of these objects every time they are needed.

Today it occurred to me that all you really need is a language mechanism to define "singleton classes". A singleton class defines a single instance at runtime. Singleton classes are a convenient place to stash things like standard input and output streams.

Example:
module System::IO {
field in;
field out;
field err;

method init() {
self.in = new System::InputStream(:stdin);
self.out = new System::OutputStream(:stdout);
self.err = new System::OutputStream(:stderr);
}
}
Here, the keyword "module" means singleton class.

Now, consider some code where this singleton class (System::IO) is used:
import System::IO;

IO.out.print("Hello, world\n");
The import directive lets the compiler know that in this translation unit, the identifier "IO" will refer to the instance of the singleton class "System::IO". As long as some runtime magic can produce a reference to the instance of a singleton class, all field and method accesses are done through ordinary object references. No static fields or methods needed.