Awesome suggestions

27.05.2010 22:28

Every once in a while we have a hack day at Zemanta. It's supposed to be a day when you use the office hours to explore any interesting ideas that are always pushed back by more important work. At least in my case, the most interesting ideas usually pop up just after the hack day.

This is also how this little hack came to life. My thinking went into this direction:

Zemanta's in-text link suggestions appear fine and fancy at first, but over time two problems became apparent. First, I myself rarely find the suggested explanatory links useful. It is reasonable to presume that the readers of my posts are also familiar enough with the topic that they find links to such basic explanations as Wikipedia redundant. And secondly, I often manually include in-text links that are much more related to the topic (previous posts on this topic, tickets in bug trackers, other blogs, etc.) Zemanta uses the "Related articles" list on the bottom of the post for such links, but I prefer to include them in-line. This means they can easily get overlooked if the text is flooded with Zemanta's automatic explanatory in-text links.

Now what if there was a way to automatically suggest those in-text links that I currently include manually and save me some copy-and-paste between the browser's location bar and the text editor? Destination URLs of all those links are already in the browser, because I either have them bookmarked or I recently read them when researching the topic of the blog post.

And the best thing is the Firefox browser already has a wonderful suggestion engine out of the box. It's just hard to recognize because by default it's limited to the location text entry field.

Yes, I'm talking about the so-called AwesomeBar.

So I made a tiny Firefox extension that exports the nsIAutoCompleteSearch interface of the Places system through a socket, so that any program on the same computer can access it. Then I wrote a client in the form of a Vim plug-in that throws at it pieces of text you're writing and displays the suggested links for you to choose. Yes, I know Vim was perhaps a bad choice, but this is what I use for blogging and I know how to use its scripting interface.

The plug-in adds a new keybinding (F10 by default). It invokes a function that takes the last typed phrase and runs it through the AwesomeBar magic. Here's how it looks in practice:

Awesomeggest demonstration, pressing F10

Press F10...

Awesomeggest demonstration, choose a web page from the list

choose a web page from the list...

Awesomeggest demonstration, HTML link is inserted

and a HTML link is inserted into the text.

Javascript isn't exactly my cup of tea, so the code is a bit clunky and sometimes the extension just refuses to work for no apparent reason. In any case, see the source for more technical details. There's really not much of it.

The code is available in a git repository under the GPLv2 for your enjoyment. All the usual warnings apply - this might eat your cookies and it certainly exposes your browsing history to every process on the host and possibly the entire internet.

$ git clone

I've been using this for a while now and it's useful to some degree. For one it's pretty good in practice at finding the correct web page, if only the anchor phase appears in the page URL or title (which seems to most of the times). The slowness of the search function in Firefox makes it a little less convenient to use and the Vim interface is pretty bad. An asynchronous search (like in the Firefox URL bar) would make performance problems much less noticeable, but is as far as I see beyond the capability of Vim scripting. Perhaps there is some brave soul out there that will prove how much better some other editor can be at this?

As always, any comments or patches are most welcome.

Posted by Tomaž | Categories: Code | Comments »

Samsung i5700 follow up

25.05.2010 21:39

Here's the follow up post about Samsung i5700 I've bought two weeks ago.

Factory reset solved the random reset problems I complained about last time. But reliability is still way lower than in my previous "dumb" Ericsson phone (when it was in its best years, of course). Every two days or so a box appears on the screen saying "Sorry, but process stopped responding.". Sometimes this doesn't affect anything apparent, but sometimes this means no more wireless LAN connectivity or GPS until the next reboot.

On a related note I also discovered that the phone will repeatably crash on a specific location in Ljubljana. Perhaps it's because of a particular wireless LAN or a GSM cell. Certainly something that would be interesting to explore in more detail.

To move on to more positive things, I like the messaging feature, automatic threading and conversion to MMS when you attach an image to a short message. Certainly the most sensible application of MMS to mobile messaging I've seen in a phone.

The contact management is nice when it works. I like how they solved the problem of merging equivalent contacts from different databases. Not that it isn't flawless: when I imported my contacts after the factory reset I ended up with each contact in three copies each of which I had to manually unmerge and delete.

Another thing I like is the calendar. It's actually starting to compete with the paper one.

It's easier to type text on the on-screen QWERTY keyboard than using the numeric one. However the phone doesn't support Slovenian characters in a useful way out of the box - you can only type them in if the whole interface is in Slovenian and the horrible translation makes that a pain to use.

The AnySoftkeyboard application provides an usable replacement, but has other issues. I only manage to make the swipe gesture for switching layouts on the second or third try. The failed tries are equal to bashing your head on a laptop keyboard (i.e. insert several random characters), which is a big problem when entering passwords (how many dots do I need to delete now?). Why does the mighty smiley deserve its own button (which replaces the original layout switch button)?

A few words on the touch screen. It's light years ahead of a LG touch-phone I tried before buying i5700, but it can still be annoying as hell. After two weeks of practice I still happen to click on a menu entry or a link on a web page instead of scrolling.

Interestingly, it appears to work much better when there is something conductive on the other side of the phone. For instance a hand or an anti-ESD mat. It's practically unusable when the phone lies on a wooden table and you're dabbing at it with a single finger.

The phone doesn't support the pinch-zoom feature. Instead it has a touch-hold-drag gesture for zooming. However: every zoomable window always has visible zoom buttons, which take precious screen real-estate, making the zoom gesture redundant. Even worse, the gesture makes it impossible to slowly scroll text (say in the web browser) while reading, because it will start zooming instead! It's one of those "features" that compete with Microsoft Office assistants in user irritation.

An finally, the actual phone application. It's surprisingly good, considering how many years it took Ericsson to get it right on their phones. However one thing is unforgivable. It takes ages (OK, like 5 seconds) for the dialing interface to come up. What is it doing? The web browser takes less time to start up!

In retrospect I probably wouldn't buy this phone again. All the thousand little paper cuts just don't overweight the benefits. This is no longer a phone. It's a full-blown computer. And that brings all the issues with software versions, applications, application upgrades and crashes. All of the things I don't want to deal with on yet another device. I would somehow excuse this if I wouldn't need to jump through hoops (i.e. root the phone and risk bricking a phone I'm stuck with for the 2 year contract) to actually do some interesting stuff on it. It's all the problems of the computer with very little of the freedom.

Posted by Tomaž | Categories: Life | Comments »

On the universality of duct tape

22.05.2010 16:36

Duct tape. You know, the type you use to tape together the laptop you just dropped. Its use is usually a sign of a quick hack job and the highest concentration of its users are in my experience at sites like Kiberpipa or the CCC congress in Berlin.

Well, it appears that it also sees some use in more serious fields. Here it's holding a flap trim tab on a little sport aircraft I've seen today at the local meeting of model and light aircraft pilots.

Flap trim tab held in place by duct tape

It really does seem there's nothing that can't be fixed with a piece of duct tape.

Posted by Tomaž | Categories: Life | Comments »

My Book power supply

13.05.2010 17:17

My external USB disk stopped working a while ago. It turned out the culprit was the little 12 V power brick which appeared completely dead.

Disassembled WD My Book power supply

I took it apart and poked around it with the multimeter. It's a pretty simple 30 W switcher using a PWM chip in a tiny 6-lead SMD package (marked 63813 - I'm guessing it's a 6-lead version of the 3813). Nothing was obviously bad, so the next suspect was the power MOSFET. I desoldered it and did a couple of tests and it worked as expected. I soldered it back and, surprise, everything worked perfectly.

Interesting. I recently see a lot of power supplies that fail because of bad soldered joints. Is the use of RoHS materials (i.e. lead-less solders) to blame? On a high-powered ones this usually have spectacular effects because the heating and arcing will make a big black spot on the board. But in this case the pins of the MOSFET looked perfectly OK.

Posted by Tomaž | Categories: Analog | Comments »

Regulator stability and capacitive load

10.05.2010 21:58

A lab power supply should work reliably under a wide range of loads. Capacitive loads are common - most circuits include at least one blocking capacitor on the power rail and this capacitor often defines the characteristics of the device as seen by the power supply. However capacitive loads are also the most problematic for the final linear regulator stage, because they affect the open-loop transfer function of the feedback.

Here's a simplified schematic diagram of a linear regulator:

Schematic diagram of a voltage regulator.

The differential amplifier block usually includes an op-amp, compensation circuit, driver and power transistors. Only its output resistance is shown here. The feedback comes from a voltage divider R1 R2 which is connected to the negative terminal. To calculate the open-loop transfer function Uout/Uin, the divider has been disconnected from the amplifier.

Amplitude Bode plot of a voltage regulator.

The solid line here shows the amplitude Bode open-loop plot for a typical setup. The op-amp has 100 dB of gain and has been compensated with a dominant pole at 10 Hz resulting in 100 kHz of bandwidth. Divider has 20 dB of attenuation. Say Rout is about 100 mΩ.

What happens when you connect a capacitor to the output terminal of the regulator? Together with Rout it forms a new pole (for instance at fp, shown approximately on the picture for a 4700 μF capacitor).

This creates a stability problem, because the plot passes 0 dB gain at a phase shift greater than 135°. If you look carefully, the loop is stable only if the new pole is created in two regions: at far left (less than 1 mHz) or far right (more than 100 kHz). This translates to capacitances between 1600 F and 16 μF.

The far left region obviously isn't interesting because it would require unrealistically large capacitors. However there is a range of capacitances greater than 16 μF that is occupied by common electrolytic capacitors that will put the feedback loop into instability.

This might appear as a grave problem at first. But it turns out there's nothing like a naked capacitor out there. Electrolytic capacitors actually have quite large effective series resistances. These will create a zero on the amplitude plot at around 1 kHz (for aluminum capacitors, somewhat higher for tantalum). The position of this zero depends solely on the tan δ (dissipation factor).

This changes the picture somewhat. Zero at fz (again shown approximately for a realistic 4700 μF aluminum capacitor) causes the plot to cross 0 dB at 20 dB/decade and makes the loop stable again.

So, such a regulator is actually stable for a much wider range of realistic loads than is apparent at the first glance. Long connection cables will further improve the situation. However, low ESR solid-state tantalum capacitors can still cause problems. These can be solved by increasing the bandwidth or with more complicated compensation networks, but these are left as an exercise for the reader.

Posted by Tomaž | Categories: Analog | Comments »

Android and secure mail

08.05.2010 21:31

Here's another gripe about my new Android-running Galaxy Spica. It appears that there's a lot of hacking involved if I want to have a secure way of reading my email.

First, the bundled mail app doesn't support CRAM-MD5 authentication for SMTP (bug 5901). This means that the password for the mail server account gets sent in clear, which is obviously a bad thing.

However, the app does support SMTP over SSL and TLS, which means the connection can be encrypted and the clear-text password that passes through it made safe from eavesdropping.

But you can't install third party root CA certificates (bug 6207). This means that the phone is basically stuck with trusting only those particular certificate authorities that Google wants you to trust. If I want to connect to a SSL service (like secure IMAP and SMTP, and also secure web pages) that has a certificate signed by a different authority I'm left with the "accept any certificate" option, which makes the connection vulnerable to man-in-the-middle attacks, thus eliminating most of the benefits of encryption (just remember how scary-looking the warning about an untrusted certificate looks in Firefox if you don't believe me).

I did find a couple of guides (1, 2) on how to add a custom CA certificate to the phone, but they look a bit outdated (one is for the Android Cupcake version) and the procedure appears to be pretty delicate.

My 5 year old "dumb" Sony Ericsson phone had support for both CRAM-MD5 and custom certificates out of the box! I would happily trade all the bundled Facebook, MySpace applications and whatnot for basic things like this.

Posted by Tomaž | Categories: Life | Comments »

Samsung i5700

07.05.2010 19:44

A few days ago I finally made the decision to replace my old Sony Ericsson phone, which was really starting to show its age. I wonder what causes a once perfectly reliable phone to start locking up and grow all sorts of weird new quirks? Hairline fractures in solder joints, increasing ESR of the battery, firmware bit rot?

Anyway (and regardless of what used to be my idea of the ideal mobile phone some years back) I opted for a smart phone. For a while I considered Nokia N900, but quite a few reviews said that it's a good pocket computer but not a good phone. Plus, at 430 € it was a bit on the expensive side. So I opted for an Android phone.

In the end I chose Samsung i5700 Galaxy Spica (160 € and a two year contract at Mobitel), with the Android 2.1 upgrade.

These two days I've been using it are way too short for any kind of conclusions about the quality and usefulness of the phone, however I can't help but mention that I'm growing increasingly disappointed at the reliability (after all, I bought this to replace an unreliable phone!)

It started right at the boot: you're offered some kind of a tour when the phone first powers up. That's great, but what good is it, when the "Start" button doesn't work and you can't actually start the tour?

Then, when transferring my phone book via Bluetooth, Android proudly reported that it finished transferring -1.0 kB of data. Right. I should also add that as long as Bluetooth is enabled the phone will happily accept any and all files, even phone book entries, without any kind of authorization or confirmation. Security-wise that's like shooting yourself in the foot. If there's an option to turn this off, I haven't found it.

And, worst of all, in these two days the phone spontaneously rebooted 5 times (meaning that it was waiting at the PIN entry screen when I took it out of the pocket). All of these times I was on the move, so this may have something to do with hopping from one cell to the other. Or perhaps the reason is much more trivial and it was just that the power button was accidentally pressed. I'll be a bit more careful next week and if keylock isn't the issue this phone will be on the fast track back to the shop.

Posted by Tomaž | Categories: Life | Comments »

Magic trace

02.05.2010 12:48

A while ago I wrote about an old SMC barricade wireless router that's been acting up. It's still having weird issues with both wired and wireless interfaces, which magically disappear when I open the box. It's probably time to invest in some new hardware, but I gave it one last shot at finding the problem. It's most likely something trivial, like a bad soldered point somewhere.

Anyway, when closely inspecting the circuit board I found this interesting feature:

Detail of the SMC Barricade G circuit board

What is the purpose of the long U-shaped trace at the bottom of this photograph (click on the image for a larger version)? The via at one end doesn't appear to be connected anywhere (although it is possible I missed a connection on some inner layer).

It looks like an antenna, but is surrounded by the ground fill and doesn't have any obvious connections to the RF front-end above (plus this router uses two external antennas).

My guesses are some test feature for measuring the parameters of the circuit board (unlikely in a production version) or a small capacitance needed by some part of the circuit (provided it's actually connected. But really, why use this instead of one more SMD capacitor? The circuit already has a hundred of them).

Maybe it's just a modern integrated version of the magic/more magic switch.

Posted by Tomaž | Categories: Analog | Comments »