Archive for the 'untagged' Category

Generating Documentation With Dehydra

Tuesday, September 30th, 2008

One of the common complaints about the Mozilla string code is that it’s very difficult to know what methods are available on a given class. Reading the code is very difficult because it’s hidden behind a complex set of #defines, it’s parameterized for both narrow and wide strings, and because we have a deep and complex string hierarchy. The Mozilla Developer Center has a string guide, but not any useful reference documentation.

With a little hand-holding, static analysis tools can produce very useful reference documentation, which other tools simply cannot make. For example, because a static analysis tool knows the accessibility of methods, you can create a reference document that contains only the public API of a class. I spent parts of yesterday and today tweaking a Dehydra script to produce a string reference. I’m working with Eric Shepherd to figure out the best way to automatically upload the data to the Mozilla Developer Center, but I wanted to post a sample for comment. This is the public API of nsACString:

I am trying to keep the format of this document similar to the format we use for interfaces on MDC. It’s a bit challenging, because C++ classes have overloaded method names and frequently have many methods. In the method summary, I have grouped together all the methods with the same name.

Once the output and format are tweaked, I can actually hook the entire generation and upload process to a makefile target, and either run it on my local machine or hook it up to a buildbot. I used E4X to do the actual XML generation. It was a learning experience… I don’t think I’m a fan. I want Genshi for JavaScript. Making conditional constructs in E4X is slightly ugly, and making looping constructs is really painful: my kingdom for an XML generator so that I don’t have to loop and append to an XMLList.

Salmon Cakes

Friday, September 26th, 2008

I love crab cakes. But at least here in Johnstown, refrigerated crab meat is expensive enough that making crab cakes on a regular basis is impractical. But there is an affordable alternative that tastes almost as good: Salmon cakes. Canned salmon is inexpensive and is a great substitute; you can find it near the canned tuna at pretty much any decent supermarket.

Ingredients

  • 2 cans salmon (15.75oz each)
  • 1 cup breadcrumbs
  • lots of pepper
  • Spices:
    • 1 teaspoon ground mustard
    • 1 teaspoon paprika
    • 1/2 teaspoon cumin
    • 1/2 teaspoon red pepper flakes
    • Or whatever else strikes your fancy
  • 1 large onion, diced fine
  • 2 eggs, lightly beaten
  • bacon fat or frying oil (peanut, canola, sunflower, or soy oil)

Hardware

  • mixing bowl
  • can opener
  • fine strainer
  • griddle or large skillet (cast iron is best, but any heavy pan will do)
  • Metal spatula-like device: an offset spatula is best
  • Wire rack for draining: for best results, turn the rack upside-down in contact with newspaper.

Preparation

  1. Drain the salmon into a strainer. Pick through the fish and remove any backbone or other large bones, if present
  2. In a mixing bowl, combine the breadcrumbs and spices and toss
  3. Add the salmon, eggs, and onion to the bowl. Combine the ingredients with your hands. The mixture should be somewhat sticky. If it is dry, add another egg.
  4. Form the cakes with your hands:
    • The cakes can be any size from half-fist to fist sized. The cake should be a disc about twice as wide as it is thick… I can typically make 10 large-ish cakes from this recipe.
    • Squeeze in both hands to compact into roughly the correct shape.
    • While holding in the palm of one hand, cup your other hand around the outside of the cake to form it into a round.
  5. Heat the griddle on medium heat and add the frying fat.
  6. When water gently sizzles in the fat (3-4 minutes), add the cakes. It’s ok to place them close together.
  7. Turn when the first side is brown… I prefer a dark mahogany (~7 minutes), but many people prefer a more golden color (~5 minutes)
  8. When the second side is done, remove to the wire rack for draining and cover with foil. Serve immediately.

Service Suggestions

  • For a dipping sauce prepare sour cream with chives, or tartar sauce if you’re feeling very traditional.
  • Salmon cakes work well as a main dish, but you could also make smaller ones as hors d’œuvre or in a surf-n-turf combo.
  • On a cold day, pair with a warm vegetable soup.
  • On a warm day, pair with a cucumber salad.
  • Serve with Sauvignon Blanc or Corona.

Notes

Canned Salmon typically has a lot of added salt. You don’t need to add any salt, and I’d avoid salted seasoning blends (Old Bay) as well. Because the salmon is fully cooked, feel free to check for seasoning before frying.

I’ve seen recipes where the cakes are breaded before frying, typically with crushed saltine crackers. I can’t for the life of me figure out why.

If you are like me and instinctively add garlic to any dish calling for diced onions, please resist the temptation.

When linking, the order of your command-line can be important

Monday, September 22nd, 2008

Occasionally, people will come on the #xulrunner or #extdev channel with a question about compiling XPCOM components. The question often goes something like this:

<IRCGuy> I’m following a tutorial on making XPCOM components, but I can’t seem to get them to compile. Can anyone tell me what my problem is?

Hint for asking a good question: IRCGuy needs to tell us some combination of 1) what tutorial he’s following, 2) what the failing command is or 3) what the error message is.

This time, IRCGuy’s compile command and error message are:

IRCGuy@IRCGuy-france:/mnt/data/IRCGuy/public/project/xpcom-test$ make
g++  -I/usr/local/include/xulrunner-1.9/unstable -I/usr/local/include/xulrunner-1.9/stable -L/usr/local/lib/xulrunner-devel-1.9/lib -Wl,-rpath-link,/usr/local/bin  -lxpcomglue_s -lxpcom -lnspr4 -fno-rtti -fno-exceptions -shared -Wl,-z,defs  france2.cpp -o france2.so
/tmp/cceFg2dD.o: In function `NSGetModule':
france2.cpp:(.text+0x38c): undefined reference to `NS_NewGenericModule2(nsModuleInfo const*, nsIModule**)'

IRCGuy’s problem is a problem of link ordering: with most unix-like linkers, it is very important to list object files and libraries in the correct order. The general order you want to follow is as follows:

  1. Object files
  2. Static libraries – specific to general
  3. Dynamic libraries

If an object file needs a symbol, the linker will only resolve that symbol in static libraries that are later in the link line.

The corrected command:

g++  -I/usr/local/include/xulrunner-1.9/unstable -I/usr/local/include/xulrunner-1.9/stable -fno-rtti -fno-exceptions -shared -Wl,-z,defs  france2.cpp -L/usr/local/lib/xulrunner-devel-1.9/lib -Wl,-rpath-link,/usr/local/bin  -lxpcomglue_s -lxpcom -lnspr4 -o france2.so

Bonus tip: correct linker flags for linking XPCOM components can be found on the Mozilla Developer Center article on the XPCOM Glue. As noted in the article, xpcom components want to use the “Dependent Glue” linker strategy.

hgweb viewer, canvas version

Monday, April 14th, 2008

If you want to go drawing complex graphics on the web, you have two basic options: SVG and the HTML canvas element.

My first attempt at the hgweb graphical browser used SVG. Actually, it used an unholy hybrid of SVG and HTML: the revisions themselves were drawn using absolutely positioned HTML. The arrows between the boxes were drawn using SVG. I did this for several reasons:

  • only Firefox supports drawing text into canvas elements
  • I could use DOM events to do hit-testing and navigation
  • you can select/copy/paste text in HTML

Unfortunately, the performance of the first version was not very good, and the code was very complex. I was maintaining several parallel data structures: a JS object graph, and the DOM objects for revisions and arrows. The bookkeeping code to keep data in sync was dwarfing the actual layout logic.

Instead I decided to try using canvas. Sucking out the bookkeeping code and replacing it with a custom drawing code turned out to be much easier than I expected. Now all of the data is kept in a single tree, and layout, rendering, and hit-testing are all blazingly fast.

After getting it basically working, I was able to add additional features in a matter of minutes:

  • Collision detection
  • Animation when navigating between revisions
  • Switched to a vertical layout which provides more information
  • Made arrows into curves
  • Highlight the “center” node

The disadvantages of this approach are unfortunate:

  • Only works in Firefox 3+ (needs the experimental mozDrawText API)
  • Impossible to select or copy text

check it out (my development machine, so it may go down at any time) or get the source.

Now I really promise I don’t have any more time to spend on this project. Contributions welcome!

Mozilla Build System: Now Requiring Python, and new Windows build package

Friday, March 2nd, 2007

Starting next week the Mozilla build system is going to require python on all platforms. This will allow us to gradually convert various build scripts which are currently written in perl, and start hacking on an autoconf replacement written in python. Any python 2.3 or higher will be acceptable.

In addition, I have made a production release of MozillaBuild, version 1.0. The MozillaBuild package is now the recommended build environment for all Mozilla developers on Windows. There were a few bugs with the 1.0 releases that have now been corrected in a MozillaBuild 1.1 release candidate.

After the Tinderboxes have been upgraded to use the MozillaBuild package on trunk, I am going to be discontinuing support for the cygwin build environment.

Please post questions and followups to the mozilla.dev.builds newsgroup.

New release repackager and about:config fixer

Tuesday, October 10th, 2006

I’ve prepared a couple new software releases this week:

Firefox Release Repackager (1.2)

Adds support for repacking the NSIS installers used by Firefox 2.

about:config fixer

Fix about:config to display the chrome URI of localized prefs, instead of the localized value.

Usury

Monday, August 29th, 2005

Friday, I received in the mail a check for $5,000 from a bank I had never heard of before. My wife went through the mail, and when she read the fine print on this check, she discovered that it was actually a five-year loan, at 27.199% interest. In case you don’t have a financial calculator, the total cost of the loan would be $9,176.

Leaving aside the deceptive practice of disguising a contract in the form of an unsolicited check, this loan offer is a truly despicable form of usury. For some reason I don’t understand, it is no longer fashionable to call anything usury. But usury is not only immoral, it is still a crime in most states. Unfortunately, the U.S. congress gutted state laws against usury in 1980 by exempting federal banks from state usury laws. The did this under the guise of protecting banks against inflation, but it was actually a neoconservative triumph of laissez-faire economics over decency and justice.

It is amazing that Beneficial has posted a document on responsible lending practices which seems to be so much at odds with their actual practices. Just because this bank is probably not doing anything illegal does not mean that we should tolerate deceptive and usurious practices that prey on the poor, mentally retarded, and elderly. I encourage you to write to the bank and tell them what you think:

HSBC – North America
Corporate Headquarters
2700 Sanders Road
Prospect Heights, IL 60070

I also encourage you to write to your congressman and ask them to add them to toughen U.S. usury law so that state laws apply, or at least a reasonable interest limit is applied.

Nothing, in the Pursuit of Perfection

Saturday, July 9th, 2005

I have fallen into the most dangerous trap of a computer programmer: doing nothing in the pursuit of perfection. When I left my job at Saint Patrick’s I promised that I would have my new weblog running very soon, and promised an exciting new development to boot… which was silly of me, because I had great plans but no working code to go with those plans. So I have not had a weblog for almost six months, because I kept telling myself that I would get up one day and my new weblog software would magically write itself.

I have given up those silly perfectionist dreams and returned to WordPress on my new website, and found a nice surprise: WordPress is a lot better than it was, and it has solved a lot of the complaints I originally had with it. I will be looking into WordPress extensions to make this blog even easier for you (my readers) to use: please let me know if you have suggestions.

It is good to be blogging again, because I have lots of ideas and decisions that I need to talk about. I have a backlog of ideas that I’ve wanted to blog about for the past six months, so expect some serious blog output in the next few days while I get caught up with myself.

Most importantly, the Mozilla Foundation has hired me (working remotely from Pennsylvania) to take XULRunner and libxul by the horns and wrestle them into a workable software solution. I am also spending a significant amount of time on the build system and such for localizations.

I’m aware that my website has broken links here and there, and that the import of the old blog database has left some dangling links. I’ll fixup what I can when I can, but it’s a low-priority task ;-) .

Moving On

Friday, January 28th, 2005

Dear readers,

As some of you may already know, I am leaving Washington D.C. and my job at St. Patrick’s, effective this Sunday 30-January. I will be joining the expanding biosphere of hackers who are paid to work on the Mozilla products and platform. I will be working full-time for the mozdev group, inc., a consulting company that specializes in software solutions based on mozilla technologies.

I am saddened to be leaving St. Patrick’s; I have made many good friends here, and learned a tremendous amount about music, worship, and life in general. I could not have asked for a better job coming right out of college, or a more beautiful church or organ.

I am excited to be moving on to the new challenges of software development. As most of you are aware, I have been significantly involved with the development of Mozilla Firefox, serving as the volunteer coordinator of localizations for the 1.0 release, and writing a decent amount of the backend code that makes loading extensions possible. My work with mozdev group is full of exciting challenges. And I intend to continue development of the XULrunner, the next-generation runtime for XUL applications, or applications which wish to embed the gecko rendering engine.

Suzanne and I will be moving to Johnstown, PA on 3-Februrary, and so I will probably be out of touch for most of next week. Our new mailing adress will be

221 Hemlock St.
Windber, PA 15963

I also have a new email address, effective immediately: benjamin@smedbergs.us. Please update your address book accordingly.

Also, the location of my weblog will be moving soon to http://benjamin.smedbergs.us/. I will try to set up a decent number of redirects so that this current location continues to get you somewhere useful. However, old blog post links will not continue to work, because I do not intend to use WordPress for the new blog. Stay tuned for some exciting developments there.

Holidy Party Eating Tips

Tuesday, December 7th, 2004
  • Avoid carrot sticks. Anyone who puts carrots on a holiday buffet table knows nothing of the Christmas spirit. In fact, if you see carrots, leave immediately. Go next door, where they’re serving rum balls.
  • Drink as much eggnog as you can. And quickly. Like fine single-malt scotch, it’s rare. In face, it’s even rarer than single-malt scotch. You can’t find it any other time of year but now. So drink up! Who cares that it has 10,000 calories in every sip? It’s not as if you’re going to turn into an eggnog-aholic or something. It’s a treat. Enjoy it. Have one for me. Have two. It’s later than you think. It’s Christmas.
  • If something comes with gravy, use it. That’s the whole point of gravy. Gravy does not stand alone. Pour it on. Make a volcano out of your mashed potatoes. Fill it with gravy. Eat the volcano. Repeat.
  • As for mashed potatoes, always ask if they’re made with skim milk or whole milk. If it’s skim, pass. Why bother? It’s like buying a sports car with an automatic transmission.
  • Do not have a snack before going to a party in an effort to control your eating. The whole point of going to a Christmas party is to eat other people’s food for free. Lots of it. Hello?
  • Under no circumstances should you exercise between now and New Year’s. You can do that in January when you have nothing else to do. This is the time for long naps, which you’ll need after circling the buffet table while carrying a 10-pound plate of food and that vat of eggnog.
  • If you come across something really good at a buffet table, like frosted Christmas cookies in the shape and size of Santa, position yourself near them and don’t budge. Have as smany as you can before becoming the center of attention. They’re like a beautiful pair of shoes. If you leave them behind, you’re never going to see them again.
  • Same for pies. Apple, Pumpkin, Mincemeat. Have a slice of each. Or, if you don’t like mincemeat, have two apples and one pumpkin. Always have three. When else do you get to have more than one dessert? Labor Day?
  • Did someone mention fruitcake? Granted, it’s loaded with the mandatory celebratory calories, but avoid it at all cost. I mean, have some standards.
  • One final tip: If you don’t feel terrible when you leave the party or get up from the table, you haven’t been paying attention. Reread tips, start over, but hurry, January is just around the corner.

Remember this motto to live by:

“Life should NOT be a journey to the grave with the intention of arriving safely in an attractive and well preserved body, but rather to skid in sideways, chocolate in one hand, martini in the other, body thoroughly used up, totally worn out and screaming “WOO HOO what a ride!”