Mon, 07 May 2007
Flushing Firefox Preferences
The Firefox preferences system is quite amazing, but it has a tendency to cache preference settings in memory, and only seems to write to disk (the prefs.js file in the current profile folder) when Firefox exits. This means that if Firefox should crash for some reason after changing preferences, the changes would be lost.
I looked and I looked for some sort of XPCOM call that would flush the preferences cache to disk, but couldn't find anything. The best I could find was the savePrefFile call on nsIPrefService. Unfortunately, this procedure takes a file argument, so it isn't really a flush.
Fortunately, I did some digging around in the code that implements the preferences service. It turns out that SavePrefFile calls SavePrefFileInternal, which includes a special check for a null parameter. If the parameter is null, then it writes to the mCurrentFile member, which I assume is equivalent to doing the flush.
In summary, while Firefox provides no explicit method to flush the preferences cache to disk, calling the savePrefFile method of nsIPrefService with a null parameter should do the trick.
posted at: 15:35 | path: / | permanent link to this entry
Fri, 13 Apr 2007
Why the new Mozilla Addons Site is Better(TM)
As a Firefox extension developer, I probably interact with the Mozilla Addons Site more than most people. There has been a fair amount of commenting on whether the recent upgrades to the Mozilla Addons Site are good or bad (take a look at the Mozilla Webdev Blog for information about the AMO upgrades, which is spread across several posts).
I reserved judgement about the AMO upgrades initially, but have now made my decision: the new Mozilla Addons Site is better than the old one. Well, I'll qualify that: it's better for me. To see why, take a look at the email I just got when version 0.6 of my extension was approved:
The following files of FFClickOnce 0.6 have been made public by a Mozilla Add-ons editor: FFClickOnce 0.6 - Windows Review Information: Reviewer: Olive Tested on WinXP with Fx 2.0.0.3 Comments: Thanks for the update! If you have questions about this review, please e-mail amo-editors@mozilla.org or join #addons on irc.mozilla.org. Mozilla Add-ons http://addons.mozilla.org
Compare that with the message I got from the old AMO site, the last time a version of my extension was approved:
FFClickOnce 0.5 - Approval Granted Your item, FFClickOnce 0.5, has been reviewed by a Mozilla Update editor who took the following action: Approval Granted Please Note: It may take up to 30 minutes for your extension to be available for download. Your item was tested by Olive using Fx 2.0.0.3pre on Win XP. Editor's Comments: Approving update, thanks -olive ---- Mozilla Update: https://addons.mozilla.org/
Notice the difference? It may seem rather subtle, but it makes a huge difference for addon developers. Know what it is yet? The grand answer is: They give me an email address to contact! That's it. That's the one thing they had to do to make the Addon development experience immeasurably better for me. My extension has failed review several times for reasons that were never really that clear to me. Important bug fixes that really needed to get out to my users were delayed due to review failures by reviewers who suddenly found some issue with my extension that wasn't really an issue and had never been pointed out by any previous reviewer. It was so frustrating, because I didn't have any way to contact them. And the fact that it took several weeks to a month to get through the review queue again just made it all the more frustrating.
To the Mozilla people's credit, somewhere in the addons documentation it did say that addons developers could go onto the #addons IRC channel, but as someone who doesn't know how to use IRC and doesn't want to waste his time wading through chatrooms, this was never an option. Email is the de facto standard of communication nowadays, and if I can't reach you through email you might as well not exist. I know it's harsh, but it's (almost) true.
In summary: The Mozilla Addons people can now be contacted via email, the email address is provided to Addons developers when their extension is reviewed, this makes my work as an Addons developer much less frustrating, and makes me really happy =)
Of course, just having an email address isn't enough: hopefully there's someone checking it and responding to it, too...
posted at: 15:06 | path: / | permanent link to this entry
Thu, 12 Apr 2007
Pencil Lead Resistors
My mom wanted me to cut some Styrofoam. I had a nichrome wire that had been crudely attached in place of a blade on a small saw. I think I made this in Grade 6, when my teacher gave me a small length of nichrome (Nickel/Chromium) wire especially for this purpose. Unfortunately, finding a power supply that could power it was another problem.
The nichrome wire has a fairly low resistance, and would draw too much current from a small power cube, even a 5V one. I eventually realized that I could power it off a 12V backup car battery, but when I connected it to the 12V source directly, the approximately 4.5A current caused it to glow red hot within a matter of seconds.
I knew I had to limit the current, so I searched through my resistors for my highest power resistor: a 20ohm, 5W, brick-like thing. Unfortuantely, it limited the current too much: the resulting 0.5A flow didn't warm up the cutting element enough to make a dent in the styrofoam. From fooling around with the nichrome wire, I figured that I'd need about three times that amount, 1.5A, to be able to cut the styrofoam.
My first thought was to add a second 20ohm, 5W resistor in parallel with the first resistor, giving twice the current flow. Unfortunately, our local "The Source" (what Radio Shack got renamed to in Canada) didn't have anything appropriate. So the project was dead.
Until I realized that I could use pencil leads as my resistors. I knew they would have a low resistance, that they would be able to sink a lot of power, and that their resistance would be adjustable (just slide the electrodes along the lead, increasing the distance between the electrodes and therefore also increasing the resistance). I quickly abandoned the idea of taking a perfectly good wood pencil and splitting it open and instead pulled out a tube of 0.9mm diameter mechanical pencil leads that I bought in England when I was 13. (I lost the pencil long ago, and never managed to find a wide-enough replacement pencil at any stores in Canada).
Using my multi-meter, I measured the resistance of one lead to be almost right on 1 ohm. Since I was using a 12V source, I knew that 6 leads (6 ohms) would give me a current flow of about 2A. But I had to take into account the resistance of the nichrome wire itself, so I figured that 5 leads would probably provide enough resistance to limit the current to my desired 1.5A, when also in circuit with the nichrome wire. So I made the following circuit:
I initially had some difficulties, as my multimeter would initially show a small current that very quickly decreased to zero. I thought that perhaps my resistance measurements of the pencil leads had been incorrect, so I moved the alligator clips on a number of the leads closer together, and still had the same result when I applied power. After a few attempts at decreasing the resistance, I noticed a puff of smoke come off of one of the leads! I looked at my multi-meter again and realized that the mode switch was stuck somewhere between DC Amps and AC Amps, and so the meter was in AC Amps mode, and my circuit had been working fine all along.
I moved all my alligator clips back to their original positions at either end of each pencil lead, put the meter into the correct mode, and switched on the power:
As you can see, I got a current flow between 1.5 and 2.0 amps, which is exactly what I wanted. The nichrome wire didn't glow, yet it slid through the styrofoam like a hot knife through butter =). Here's a picture of my pencil lead resistor network:
Sure, it's a bit of a rat's nest of wires, but it got the job done and was easy to set up and tear down. Finally, here's a close-up of one of the pencil lead resistors:
So, the next time you need a high-power, low-resistance conductor, just look around your desk--the solution is probably staring you in your face!
posted at: 20:37 | path: / | permanent link to this entry
Tue, 10 Apr 2007
FFClickOnce v0.6 Uploaded
After a number of bug reports that my Firefox extension wasn't installing properly from the installation page at Mozilla Addons due to download corruption, I've finally tracked down the problem as best I can, and will try to elaborate on it later in this entry. But the real thing I'm writing about is that I just uploaded version 0.6 of the extension to the Addons site.
Though it is pending review by the Mozilla Addons people and likely won't be visible for a month or so, I might as well say what it includes: localization support, and translations into Spanish, Italian, French, Dutch, and both Chinese Traditional and Chinese Simplified. The first four translations are courtesy of the Babelzilla Project, and the latter ones are my feeble attempt at trying to learn and use technical vocabulary in Chinese.
As far as the installation corruption problem goes, it's actually because the hashcode for my extension that is stored in the Mozilla Addons database is wrong. In fact, as I pointed out in Mozilla Bug 345505, this erroneous hash code is the same for several extensions!
posted at: 18:20 | path: / | permanent link to this entry
Tue, 03 Apr 2007
New Blog
Well, I've updated my blog to some new software and am in the process of moving my site from my old web host to my new web host (webfaction.com). I'm also hoping this means that I'll be able to start blogging with a bit more frequency than I have in the past.
posted at: 17:58 | path: / | permanent link to this entry
Sat, 04 Mar 2006
China Pictures
Well, having arrived in Shanghai, China for Mandarin Studies, it's now time for me to start taking pictures and posting them online! I'll be running my China 2006 Pictures album from my regular photo site.
As a teaser, here's a thumbnail picture of the panoramic shot I took from my bedroom window:
posted at: 02:22 | path: / | permanent link to this entry
Fri, 20 Jan 2006
Freestyle Solve Released!
Well, I'm really happy to announce that I have been able to release Freestyle Solve version 0.3. This is the first public release of Freestyle Solve.
Freestyle Solve is a school project that my friends and I did for our final year of Computer Engineering at the University of Waterloo. It is a tablet PC application that recognizes handwritten math and uses 3rd party software to simplify, differentiate, and otherwise manipulate the equations that the user writes. It is released under an open source license, so if you're interested you can see how it works!
posted at: 16:42 | path: / | permanent link to this entry
Mon, 16 Jan 2006
Firefox Extension Finally Approved!
Hoorah! My first Firefox extension ever was approved. It is FFClickOnce, which runs ClickOnce apps from Firefox--I've mentioned it previously in this blog. It is available on the Mozilla addons site at.
The email notifying me of the approval came in on Sunday, January 15, 2006 (yesterday). So it was a bit over a month to get this approved. Ah well, people are busy over the Christmas holidays.
posted at: 00:30 | path: / | permanent link to this entry
Sun, 01 Jan 2006
ClickOnce File Updating (Continued)
My initial observation about how doing a publish in Visual C# 2005 Express always rebuilds all assemblies was flawed: I had a pre-build script in that particular project that puts version numbers into the AssemblyInfo.cs file. Even if the version number did not change, the AssemblyInfo.cs file timestamp was updated, triggering a full rebuild of every project in my solution. My bad. It's a good reminder to always test a behaviour using the simplest possible setup.
The default behaviour of Visual C# 2005 Express (in the absence of any special pre-build scripts) is that, if you click on the "Publish Now" button twice in a row, without making any changes (direct or indirect) to any of the files, only the current project gets rebuilt; all the referenced projects are not rebuilt. This seems pretty reasonable.
Still, the current ClickOnce versioning is problematic. Try this:
- Publish the application.
- Execute the "Rebuild Solution" menu item in the "Build" menu.
- Publish the application. Notice that all assembly hashes have now changed.
So, if the solution gets rebuilt between publishes, then the second publish will do a total update, regardless of whether it is really needed.
This is not the behaviour that I want for my project. I often do a "rebuild all", for example before running FxCop or doing unit tests: I like to point both tools at my release binaries. I want ClickOnce to only update those assemblies whose version number has been bumped. I think that, if I control the publish manually, I should be able to get the desired behaviour.
posted at: 23:28 | path: / | permanent link to this entry
Mon, 19 Dec 2005
ClickOnce Always Updates All Files!
Arrgh!
Microsoft's ClickOnce is supposed to make deployment easy--and one of the things it does is that when the application is updated, it is only supposed to transfer those DLL files that have changed. Unfortunately, this isn't working for me: ClickOnce is always updating the entire application.
I found out from a post on MSDN Forums that ClickOnce doesn't use the assembly version numbers to determine what has changed. Instead, it uses a hash of the assembly file contents.
This seems reasonable, because a developer may screw up and forget to increment assembly version numbers before doing a publish. Reasonable, until you do some poking around and realize that every time you publish the app (in Visual C# 2005 Express Edition, at the very least) all of the assemblies are rebuilt, whether you have changed the code or not, and the rebuild causes the files to change! ARRGH!
You can see this from the following console session:
-bash-2.05b$ hexdump -C Solve_0_3_0_0/Freestyle.Solve.AppConfig.dll.deploy > v0.txt
-bash-2.05b$ hexdump -C Solve_0_3_0_1/Freestyle.Solve.AppConfig.dll.deploy > v1.txt
-bash-2.05b$ diff v0.txt v1.txt
9c9
< 00000080 50 45 00 00 4c 01 03 00 98 61 a7 43 00 00 00 00 |PE..L....a.C....|
---
> 00000080 50 45 00 00 4c 01 03 00 5c 63 a7 43 00 00 00 00 |PE..L...\c.C....|
539,541c539,541
< 00002f90 73 3e 7b 46 44 36 36 43 44 31 38 2d 41 45 45 39 |s>{FD66CD18-AEE9|
< 00002fa0 2d 34 43 38 43 2d 39 33 42 38 2d 38 33 42 33 30 |-4C8C-93B8-83B30|
< 00002fb0 31 44 44 37 32 43 39 7d 00 43 6f 6d 70 69 6c 65 |1DD72C9}.Compile|
---
> 00002f90 73 3e 7b 44 43 33 37 45 36 32 34 2d 44 36 46 31 |s>{DC37E624-D6F1|
> 00002fa0 2d 34 30 36 44 2d 41 32 38 45 2d 35 36 33 46 36 |-406D-A28E-563F6|
> 00002fb0 31 36 30 44 37 32 44 7d 00 43 6f 6d 70 69 6c 65 |160D72D}.Compile|
1130,1131c1130,1131
< 00005480 00 79 00 4e 00 61 00 6d 00 65 00 00 18 cd 66 fd |.y.N.a.m.e....f.|
< 00005490 e9 ae 8c 4c 93 b8 83 b3 01 dd 72 c9 00 08 b7 7a |...L......r....z|
---
> 00005480 00 79 00 4e 00 61 00 6d 00 65 00 00 24 e6 37 dc |.y.N.a.m.e..$.7.|
> 00005490 f1 d6 6d 40 a2 8e 56 3f 61 60 d7 2d 00 08 b7 7a |..m@..V?a`.-...z|
-bash-2.05b$
I used ildasm to look at my assemblies. The first difference is in the "Time-date stamp". Okay, that makes sense enough.
The second difference has to do with some sort of private class that is being created because I'm using a static array initializer. I guess it uses a GUID to guarantee that its custom name won't conflict with anything that gets used in my program.
The third difference is the pure hex representation of the GUID.
So, how can this be fixed? I've looked for an option in Visual C# 2005 Express to only rebuild changed source files when a publish is done, but I haven't found anything. So, I'm left with two possible solutions:
1) Do the publish manually, using the commandline tools.
2) Write a program to fix up a ClickOnce publishing folder after a publish is done, and correct entries in the manifest file. I could compare assembly versions instead of file hashes. The only problem will be ensuring that the ClickOnce manifest files maintain cryptographic integrity (I'll probably have to re-sign them, *bleh*)
posted at: 22:01 | path: / | permanent link to this entry
Sat, 10 Dec 2005
Firefox and ClickOnce
Well, Microsoft's wonderful new ClickOnce technology for installing .NET applications doesn't cooperate with browsers other than IE. :'(
I'm using ClickOnce to deploy my handwritten math recognition software, and I wanted people to be able to use Firefox to download it. So the first thing I did was make a helper application. When you click on a link to a ClickOnce application, the XML file that describes the application gets downloaded to your computer and then my helper application takes over. It reads the URI to the application itself from the XML file and uses rundll to do a call to the appropriate DLL function to get the install started.
Unfortunately, that approach only works for some ClickOnce applications (those applications that are configured to install to the local machine). Other ClickOnce applications don't have the URI in the XML file, and so they fail.
So, I went back and made a Firefox extension that solves this. My first Firefox extension, ever! Extending Firefox is really cool and surprisingly easy--it isn't just an application, but a whole platform for application development! Geez... I wish the applications that I write could be so easily extendable.
Anyway, the extension is available at http://www.softwarepunk.com/ffclickonce/ . I've submitted it to the Firefox addons site, but it has been "pending approval" for about a week now.
posted at: 13:55 | path: / | permanent link to this entry
Tue, 03 May 2005
Laptop Overheating
My laptop has been giving me problems for a while... it would shut off all of a sudden as I was using it and I had no idea why. It is a Dell SmartStep 200N, and I've had it for about 2.5 years.
After a while, I began to realize that it was shutting off because it was getting too hot. The primary indication of this was that these shutdowns only happened when the fan was running at full speed. Secondary indications were that the shutdowns would happen when the machine was under heavy load, and that the shutdowns happened more frequently when my room was hot. But I didn't think I could do anything about it... obviously, Dell had done their best to ensure that my laptop had a good cooling system.
That was until I read http://seb.closs.free.fr/articles/tutoP4_en.php. This site describes a chronic overheating problem in this kind of laptop. The laptop is from the era of "desktop replacements" and embodies the particular idea of using a desktop processor instead of a mobile processor. I bought it knowing full well that this was the case, because I wanted the performance of a desktop processor without having to pay for a mobile processor. From what I've read, it sounds like this design didn't have sufficient cooling. Also, a number of manufacturers used the same internals as Dell used in its SmartStep, so this problem appears in a number of other models from other manufacturers.
However, the problem can be fixed! It turns out that the thermal compound between the CPU and the heatsink was poorly applied, and in some cases missing altogether. After disassembling my computer, I discovered that there was thermal compound in my system, but there was actually a piece of aluminum foild sandwiched between the processor and the heatsink, with thermal compound on either side. Apparently this isn't the best situation, so with a fair amount of effort I managed to remove the thermal compound and clean off the processor and heatsink, apply some fresh thermal compound, and reattach the heatsink.
While it was open, I also dusted off the fins on the heatsink (to increase heat transfer) and dusted off the rest of the computer (because I'm a clean freak). The computer was a bit difficult to open up... Flipping out the keyboard was difficult because there are plastic tabs holding it down, and you just have to pull it up, past those tabs, and hope that nothing breaks. And getting the processor off the heatsink when it is glued on by thermal compound was challenging, also. I used 70% rubbing alcohol to soften some of the compound, and then I slid a razor blade between the processor and the heatsink and managed to pry them apart. I cleaned thermal compound from the heatsink using 99% isopropanol (*strong* rubbing alcohol). To my surprise, the 99%-strength stuff was actually available on the shelf in the drug store--I have never been able to find it this easily in the past.
Now my computer doesn't shut itself off anymore, unless I tell it to.
posted at: 22:23 | path: / | permanent link to this entry