Sunday, July 4, 2010

Self-Signed SSL Certificates

So you'd think there are enough blog posts about this already. Well, think again, since this particular summary is what actually ended up working for me. Obviously your mileage may vary.

  1. openssl genrsa 1024 > host.key
  2. openssl req -new -key host.key -out host.csr
  3. openssl x509 -req -days 730 -in host.csr -signkey host.key -out host.crt

Of course that's what everybody has, so why write about this? Three reasons:

  • Make sure you chmod 400 host.key since you don't want anybody to see that.
  • Using lighttpd? Do a cat host.key host.crt > host.pem and chmod 400 that as well.
  • The "Common Name" you have to enter in step 2. If you have various subdomains like www.example.com and mail.example.com and so on, you don't want to enter "example.com" here. Instead you'd enter something globtastic like "*.example.com". But wait, that doesn't match just plain example.com anymore! Better use "*example.com" and wow, that actually works.

An Internet. Wow! It's so pretty... Who would've thunk? :-D

Program like it's 1975?

Looking through various proxies and caches (don't ask why) I ran across Varnish and was struck by a short piece one of their developers wrote in 2006. Let me quote a line or two (emphasis mine):

Take Squid for instance, a 1975 program if I ever saw one: You tell it how much RAM it can use and how much disk it can use. It will then spend inordinate amounts of time keeping track of what HTTP objects are in RAM and which are on disk and it will move them forth and back depending on traffic patterns. Well, today computers really only have one kind of storage, and it is usually some sort of disk, the operating system and the virtual memory management hardware has converted the RAM to a cache for the disk storage.

You should read the whole thing, it's a nice summary of technological changes that still haven't made it into everyone's head. I feel guilty myself: I recently taught our OS course, but I don't think I ever made this sufficiently clear when we talked about virtual memory. I'll try to add a relevant assignment to the Unix course next semester... :-D

Wednesday, June 30, 2010

Pocco: Another Take on Documentation

I just discovered a cute tool called pocco on github. Apparently pocco is the Python version of what is also known as docco, rocco, and (gasp) shocco out there. Quite the zoo really! :-D So what does it do? It parses Python source and separates comments from code. It then dumps everything into HTML with a little CSS, making the comments appear on the left lined up with the corresponding code on the right. Neato.

Or it is? What could this possibly be useful for? Comments in Python are not usually used for documentation: we have docstrings after all! But docstrings are not perfect, for example you can only (by "natural" means anyway) attach a docstring to a module or class or function: What about those globals over there? Do I really have to document them in the module docstring?

But I realized that something like pocco is actually useful in Python. After all, the documentation you put into a docstring should be concise and clean: it should say exactly what it needs to say for someone else to use your stuff, nothing else. Boring! What about all those humorous anecdotes you accumulate while you hack? What about false starts, things that others should be told about before they head down the same wrong way. And so on, and so forth. With pocco, you can use comments for commentary and docstrings for documentation yet extract and (nicely?) format both. How cool is that? :-D Let's just hope that pocco will leave docstrings alone for good...

The other use I could come up with is code handouts in programming courses. Often the comments I write in this context have more of a "let me take you by the hand and work this through with you" feeling. Reading them in a nicely formatted and syntax-highlighted way may be nicer for everyone involved. True, since all comments are extracted it's hard to "comment on comments" that way... But that's okay, at least for me. Now all I need for this second application is Java, C, and C++ support! :-D

Friday, June 25, 2010

Know one editor well...

For years I've been telling people new to Unix that it doesn't matter what editor they pick. "Just pick one and learn it well!" I still believe that's true, but I've recently come to realize that I may not have followed my own advice in this regard.

I've been using vi (well vim) for years, yet apparently I have not even come close to exploiting it like I should have. Here are a few links to get you started. Take a look even if you think you know vim well, you may be surprised what it has to offer these days.

Efficient Editing with vim
Automatic Word Completion
vimsh
Indenting Python with vim
Python and vim: Make your own IDE
Vim as Development Environment
Code Navigation and Completion
Vim as Python IDE

Obviously I am focused on Python here because that's what I hack the most for my personal projects, but much of the information is applicable regardless of what language (programming or otherwise) you have to work with every day. I still can't believe that I missed out on many of these options for years. Don't make the same mistake! :-D

Tuesday, June 22, 2010

su, sudo, and /dev/pts/*

I have a few separate accounts even on my own local machine just to organize things slightly differently for different projects I am working on. Let's call my standard account "s" and one of the other accounts "q". When my machine starts up, I log in as "s", then when I need to work as "q" I use su - q to switch. Seemed like a good idea at the time.

The problem is that /dev/pts/* is owned by "s" since apparently it gets created when "s" first logs in. Now as "q" I can't use things like /dev/stdin or run screen because the permissions on /dev/pts/* are not "permissive" enough. I could probably find a way to open up the permissions, but that doesn't seem quite right. What I really want is to have "q" create it's own /dev/pts/* owned by "q".

For the longest time I couldn't find a way to get this done. Then yesterday it occurred to me to try sudo login instead of su - q and that actually works! You can't do login by itself, it'll complain, but sudo login seems fine. So my problem is apparently fixed, although now I do wonder if there are any security problems with my new approach to switching users. Anyone?

Sunday, June 13, 2010

POSSE Worcester, Day 5

With a small delay, here the summary of Day 5. First we moved to another building since the Science and Technology Center was undergoing some kind of loud demolition. :-( We hacked for a little while and then Walter talked about what to do over the next few days and how to push when we're done and do the merge request. Since I had not done much on the Measure activity but on Physics instead, I wasn't very affected by this.

Then we had our huge teaching chat, which started with Garry demonstrating what he's doing at WPI with his Software Engineering course. After that "semi-formal" part it was just open discussion. Mel wanted to make things more concrete, so she started a transcript on Pirate Pad that we all edited furiously for about 40 minutes or so. Then we went over the transcript with more discussion. And then we were done. :-D

Some people left at this point, but some of us gathered around and went to Karl's favorite Hot Dog place which was quite the treat. I had three Cony Island Dogs (trust me, they are kinda small :-D), a Chilli Cheese burger, and two "dry" Orange sodas. The only drawback was that they didn't have a booth for five, so I was a bit lonely. :-( But on one of my breaks I found a sticker outside that had the picture of a guy on it and said "Pickels, 5' 10", 160 lbs. has a posse" and that made us smile. :-D

I went back to my hotel and made the mistake (or was it one?) of youtubing around. Ended up watching "The Last Lecture" again, wow. So I showed up for the final dinner with Mel and Peter a little teary-eyed, but I don't think they noticed. We went to the Brazilian Steak House I wanted to check out the first night, and guess what? It was absolutely delicious (and none of us "smelled like meat" afterwards, Mihaela :-D)!

In summary, I had a great week at POSSE in Worcester, and I'd like to thank everybody who was there for making it such a very, very cool event. Oh, and Mihaela posted some photos, thank you so much for that too!

Friday, June 11, 2010

POSSE Worcester, Day 4

Day 4 started badly because I couldn't wake up on time. While I got on IRC to tell people not to wait for me, Mel is just too nice and waited anyway. So I held everybody up for about an hour. :-(

We did some more specialized discussions in smaller groups before lunch. Mihaela and I were walked through the details of the translation process as used in the Sugar project by Walter. I had used the web interface to this before to do some translations, but it was good to hear it all in context. (Future students beware: Walter convinced me that I can actually add this to a C course as well, given that gettext is completely pervasive on GNU systems. :-D)

I didn't have too much success with code, so I just did some more translation work before lunch. Lunch was at the WSC cafeteria again, I am still amazed at how good the food is there (for a university outfit). I just wish JHU would get their stuff together in this regard.

After lunch we were supposed to have a few more "split into groups" things but we actually got "distracted" (in a good sense) by Heidi, a guest from another local college. At first we just wanted to do a round of introductions, but this quickly diverged into a long discussion of how to put FOSS to use in the classroom (which is also the topic for the last day I think).

Mel then went into an overview/review of the various pieces of infrastructure for FOSS projects. I mentioned doodle.com but I held back on recommending github.com (I still think they have the best "basic" setup right now, but I might be wrong). I think I'll start using IRC more in the future, Mel pointed out that "being overheard" in a public chat is a Good Thing (tm) and I believe that's true.

Since it was "dinner night" many of us stayed on campus late. I went back to the Physics activity, desperately looking for something to fix in my favorite piece of Sugar. And I found something: The "grab and move" feature only worked with the simulation running, but not when the simulation was paused. Walter agreed that it should work, so I started hacking on that but didn't get far by myself. Luckily Mihaela stopped by and we started working on it together, and after a few hours we actually figured some of the pieces out. I started reading some of the library source code which promptly helped unravel the last mystery, and we got basic grabbing working before dinner.

The restaurant was somewhat hard to find, but it was certainly worth it as it seems to be somewhat of an "institution" in Worcester. The food was great, and we met "Michael" who works at Akamai and hacks on Sugar every now and then, our "special guest" for the night. Good food, good conversations, good beer, it was a fun evening.

After dinner I finished the patch for Physics and sent it off to the maintainer. I wasn't quite happy with it, but at least I had something to contribute. Gary emailed back pretty quickly that they were looking for that feature for a while, which provided additional motivation to make it better. The problem with my solution thus far was that you didn't get to move an object directly. Instead you clicked on it and then dragged a line to the future position you wanted; when you released the mouse button, the object would "pop" into its new place. It was actually quite straightforward (well, except for one synchronization issue :-D) to get a real "direct manipulation" drag to work, so I sent off another patch to Gary an hour later. I went to bed quite happy with myself for a change. :-D