Back of the Envelope: bike locks
Do you drive a bike regularly? And do you have one of those locks that are attached to your frame and put a bolt through your rear wheel? You know, the kind of lock that Wikipedia calls an O-lock? Here in the Netherlands, nearly everyone has one of these. But if you stop to lock your bike, you’ll notice that it has the tendency to hit one of the spokes in your wheel fairly often. So often that I was wondering:
What is the chance that if you randomly stop your wheel, the lock will jam on a spoke?
Now we’ll need some numbers for this, and I’ll use my own bike as an example to calculate this number. Here’s a model of my bike:
The model has the following parameters:
- Radius of the wheel where the lock bolt crosses it (r).
- Width of the bolt (w).
- Number of spokes in the wheel (n).
For my bike, the numbers are:
- r = 277mm
- w = 9mm
- n = 36
To answer the question, I’ll assume that the bolt is infinitely thin, and each of the spokes is twice the width of the bolt, at radius r. Physically, the chances of the bolt catching on the spokes are the same, but the problem now nicely reduces to:
What percentage of the circumference at radius r of the wheel is taken up by the bolt-wide spokes?
Although you can’t tell from the drawing I make, spokes don’t overlap at the radius of the wheel where the bolt crosses it. This is actually a requirement for my reduction of the problem, but one that all bike wheels will satisfy.
The question is now easy to answer. For my bike, it works out to:
As it turns out, the chance is better than 1 in 3 that my lock will catch on a spoke. Suspicion confirmed!
Me so sexy!
(This post is about a joke in Dutch, so feel free to not get it if you don’t speak the language…)

Yes please
I’ve wanted to make this joke for a couple of months… every time my train arrived at platform 7 of Utrecht’s central station, and I passed this Kiosk on my way out. Yesterday was finally the day, with many thanks to Jan Ouwens :). And Berns, who didn’t want to have anything to do with the whole spectacle and was playing on his Nintendo DS a couple of meters away.
Oh, and there’s also a YTMND (warning: probably NSFW
).
A look into prebuffering
The QuickTime playback bar
I’ve been interested for a while in the prebuffering algorithm that QuickTime uses… you know, where it loads a movie clip and automatically starts playing it as soon as the clip can be finished playing without interruptions. I was wondering about the equation they were using for that, especially since a friend told me it was an equation that couldn’t be solved.
So today I tried to drill down and see if I could come up with a solution (and it’s a good opportunity to plug one of my recent applications
).
First off, a few definitions:
The input parameters to the equation:
- Download rate d (in bytes/second)
- Sample rate s (b/s)
- Video clip length n (s)
Output of the equation:
- Prebuffer length b (s)
We pick a time b.
- At that point, the bytes downloaded so far is

- That means that there is still left to download:

- That means we simply have to pick b so that the time needed to download the remaining file size (
, or simply
) is smaller than or equal to the time it takes to play the entire clip.
In short:

Well, what are the solutions to that? (Excuse me if I’m being too verbose here)

Which is, come to think of it, not all that surpising: the buffer b has to accomodate for the difference in download and sample rate (s - d), for the entire length of the clip (times n).
So what’s the final solution, should you ever need to implement such a beast? Here it is:
Equation to find the minimum fill level of the autoplay buffer
I hope you’ve enjoyed my deriving and stating the semi-obvious. Have a nice day
.
I hate the Dell Inspiron 1100
I hate it with a vengeance. Don’t get me wrong, I’m very grateful to my current employer for providing me with a notebook to use since I butchered my last one[1], but that doesn’t change the fact that I hate the guts of the thing. Don’t buy one. Seriously.
It began with the confusion I felt the first time I turned it on: there’s a big, round, invitingly large power button at the top, with an array of LEDs nearby, and I happily pressed the big button to see my new worktoy in action. Except none of the LEDs lit up, and the device didn’t seem to do anything. I press the button again. Nothing. And again. Nothing.
Closer inspection revealed that the three LEDs, at least one of which I had mistaken for a power LED, were actually the keyboard’s NumLock, Caps lock and Scroll lock LEDs. The actual power LEDs are at the front of the device, conveniently located out of sight when you’re interacting with the power button. And yes, I had turned the device on properly at the first press.
I hesitate to think about the design choice that was made to put those LEDs there, because they are confusing and annoying. Annoying, because if you try to watch a movie on the laptop in a darkened room, you’ll constantly see a bright green LED just below the image. And in my case, also a flickering orange light… my battery light is busted and keeps indicating the battery is empty — even if I’m plugged into a wall socket. Oh plus, there’s another button there whose function I haven’t figured out yet. Pressing it does absolutely nothing…
The Inspiron 1100’s LED anatomy:

As long as we are on the subject of hardware design, I think the top lid deserves mention. It feels like it can break off at any moment just by handling it. To say it’s wobbly is just not doing it justice. As my device is second-hand, I don’t know if it has always been this way, but I strongly suspect it has. It’s like the lid is pretty tight if you flip it open or closed, but then has some added wobble room of a few centimeters, just to give you the impression the thing will fall apart if you touch it the wrong way. Which I imagine is probably true…
Ah, and who can rant about a notebook without forgetting the keyboard? Notebook keyboards are horrible by default, so there’s not much that needs to be said. Yes, the keys themselves are fine (although they require at least twice as much pressure as my previous notebook)… it’s just… the layout is simply abysmal. Of course that’s par for the course on notebooks. It seems just about every notebook manufacturer feels the need to reinvent the key layout, merrily moving around commonly required editing keys like Home, PgUp and Down, End and Delete. For me, the biggest annoyances with the Inspiron:
- Who needs the Windows and Context keys on the lower row? We’ll move them to the top right!
- You know the Delete key that used to be there? Now there’s room for that on the lower row, where it never ever ever ought to be!
- And just for good measure, we’ll also move the tilde/backquote (~`) key, traditionally found left of the number keys, to the top right. Will we put another key in its place? Nah, we’ll just leave the space half-empty.
So far I’ve covered the front, but here’s another interesting design desicision for you: we’ll put the air vent on the bottom! That’s right. You can take this lap-top you’ve just bought, but if you go ahead and put it on your lap, you pretty much get the top of them burned. I know my previous laptop was pretty hot to have on my lap, but this one is blowing hot air onto my legs! (We’ll I’m told the hole there is for sucking in cool air, but I really can’t tell the difference, except the effect it is having on my thighs, and it’s not a good one).
On to peripherals: there’s not much I expect from a laptop in that area. Except this: a PS/2 port! Instead of a regular PS/2 port, there’s two USB connectors and that’s it. Yes, I realize that in the year 2000, we will all go to our jobs in flying hovercars and all peripheral devices will use USB, but right now, there’s still a whole lot of PS/2 keyboards and mice lying around. Not offering support for them is just cheap. The keyboards I like best are the cheap, plastic, standard PS/2 keyboards. Forget hooking them up: right now I’m typing on a shitty Trust Slimline keyboard, that also insists a ridicilous key layout (because let’s face facts: who would want any key where they can find them blindly?). And don’t forget: if you’ve hooked up a keyboard and a mouse, you can forget another USB device like a memory stick. Granted, the keyboard problem is more one of my workplace than one of the laptop itself… but it annoys me nonetheless.
But there’s good news! It has a built-in modem, for all your 56k pleasure! I guess it must have slipped by the banish antiquated standards committee. Needless to say, I haven’t used it once.
I guess that pretty much covers the hardware on the outside. On to the juicy center!
The Inspiron 1100 is powered by a 2.4GHz Pentium. Rather than feeling “Holy jeepers Batman!”-fast, it feels okay. I guess being on a notebook will do that to a 2+GHz CPU. On the other hand, there’s the point of diminishing returns: from a certain point, if you’re not doing heavy calculations, you won’t notice the difference in speed from just using Windows.
I do suspect some kind of a bus problem though. Don’t call me on the specifics, because I’m not much of a hardware man, but CPU usage increases extremely when downloading files over a network connection: downloading files from an FTP server with ~500KB/s takes 70% CPU. I haven’t done enough testing to determine whether the CPU usage stems from the network card or the harddisk, but fact remaings that this is extremely annoying. Continuing to work with a download in the background becomes a chore because of sluggish response. However, I seem to recall my old laptop had the same problem, so it may just have something to do with the inherent architecture of a notebook.
And last but not least, there’s the video card, an Intel 82845G. The funny thing is that on Intel’s site, it’s not listed under “Laptop graphics controller”… instead it’s filed under “Desktop graphics controller”. Oh Dell, what have you been up to?
It’s an Intel Extreme Graphics card, who — as you may know — are far from. I’d say it’s decidedly un-Extreme. On the other hand, perhaps they meant to say Extremely Slow. You can pretty much forget playing games on this thing, because although the notebook advertises to have a pretty beefy CPU, the graphics card pretty much cancels out any performance you might have hoped to gain.
Too bad, but that’s not the worst of it. One of the great things about working on a laptop is that it’s a breeze to get multi-monitor setups working. All you need is an spare monitor and *bam*, double the desktop, double the fun! Right? Nope, not on the Inspiron. As per Intel’s site:
Multi-monitor is supported on most Intel® 82845G graphics controller-based systems using PCI video cards to support additional monitors. With the latest Intel® Extreme Graphics Drivers for the Intel 82845G graphics controller, the integrated video can be either the primary or the secondary display adapter. Multi display is not possible with the onboard display and an AGP add-in card (the AGP card will disable the onboard graphics).
That’s right. You’re on a laptop, you could have the easiest dual-head setup possible, just plug in a monitor and go, but you can’t because of a shitty video card. So what is the VGA ext connector good for? Clone display. Excuse me while I go contain my excitement.
Actually, come to think of it: I suppose the above excerpt reads something different than I thought it did. But that doesn’t change the fact that I still can’t use the “extend desktop” feature. So the verdict stands, and the card is still shitty.
But wait, I’m not done yet! Here’s another interesting tidbit about the video card: if you close the lid of the laptop, and reopen it, the video card gets reinitialized! That’s right. I can’t imagine why, but it really does that. It’s only really a problem with mplayer: I guess from the way it works, it depends on some kind of open connection with the video driver. In any case, if mplayer is running, and I close and reopen the lid, mplayer crashes as the video card reinitializes (I make it a point to disable the “on lid close go to standby” option). And it’s not like the video card goes down when the lid closes, and comes back up when the lid is reopened; no, that would have been too logical. In fact, it happens a good second after I’ve opened the lid, and it goes something like this:
- Close lid
- Backlight switches off
- mplayer keeps running
- Open lid
- Backlight comes on
- mplayer still running
- SCREEN GOES BLACK
- Screen comes back on
- mplayer kicks the bucket
Is this something that occurs in daily life? It does for me: see, I have a fairly long commute to work (50 minutes by train, then 20 minutes by bus), and I like to pass the time by watching a movie or TV show. When I have to transfer between train and bus, I like to just close the lid and put the laptop in my bag, go to the bus, take the laptop out and continue watching — saves me the hassle and the time of shutdown/startup, and again startup when I arrive at my workplace. Except each time I do this, my media player crashes and burns because of the stupid behaviour of the video card. I’d really like to see some justification for this behaviour, because it seems completely pointless to me. Just one more factor in my hatred of the Inspiron 1100…
I believe that pretty much covers my beefs with this inane piece of technology. Each one of them may not be a big problem, but they add up and the total picure is that this is just not a well thought-out machine. And news is not all bad on the Dell front. I have some friends claiming to be very satisfied with their Dell laptops. I guess it’s just my luck.
Despite this all, is there nothing good to say about the Dell Inspiron 1100? Oh sure… it performs its job adequately, and judging from the various lids on the bottom, maintenance of the thing will be pretty easy (something I’m not surprised of, coming from Dell).
It’s just, bitching is a lot more fun
…
Peace out y’all!
Footnotes:
[1] A trusty Fujitsu-Siemens Lifebook C. Yeah it was old and slow, but sturdy and reliable! Except it doesn’t survive coffee spills and it certainly doesn’t survive dropping it on the floor from 2 meters…
Oh noes! Teh Microsofts are teh sux0rz!
Some things annoy me to no end. Lots of things actually J. But one of the top-ranking things on those list is the ongoing notion many people seem to have that in Windows, clicking “Start” to shut down your computer, is one of the stupidest things since peeing on electrified fence (which is, admittedly, pretty stupid).
Just now, I was reading an amusing rant about the poor state of graphical user interfaces, when I came across this little gem of sit-down comedy:
Situations like these make me feel sorry for the spacebar. So big and strong… He totally rules over the other keys, and yet all he produces is… nothingness. I hope I never find myself in the situation of having to explain to aliens what the LARGEST KEY ON THE KEYBOARD does. »Well… this key? Right over here? Ah, the chubby one! It.. spaces… kind of… leaps.. a tiny bit. In the text… <demonstrates> See…? Nothingness! Hey, I know how this must sound… Hey! Wait!! No!! Come back!! But we just met!! COME BACK!!«
That’s alright, they would probably have left anyway as soon as they saw me clicking »Start« in order to shut the computer down.
And this is not the only time the world has been exposed to this unimaginable sense of funny. How many times have I not encountered a joke like this: “Typical Microsoft logic: clicking Start to shut down”.
OMIGOD MICROSOFT ARE SUCH IDIOTS I DON’T WANT TO START I WANT TO STOP OMG LOLOL!!1one
Oh come on people. First of all it’s not funny, and second of all — if you want to be serious — it’s not even valid criticism!
Disregard for a moment that the button is labeled “Start”. This is just The Menu. The only one at that. You click on The Menu if you want to perform a task, such as execute an application. After that, The Menu just needs a name. Preferably an evocative one, so that it turns into a easily recognizable concept with the users.
Start Menu is just right for that:
- It does not have pre-existing connotations;
- It’s short and easily remembered;
- It’s kind of appropriate too. If you want to perform a task, you start by clicking this menu. Yes, that means, even when you want to shut down your computer, you start by clicking “Start”.
Why not call it something else, like “Application Menu”? Well, that doesn’t quite fit. For one thing, the Start Menu contains more than just applications. And besides that, “Application Menu” just sounds dull and uninspired.
So “Start Menu” it is. I challenge you to come up with a better name.
And if all else fails… you can’t really be calling for something like this:
Err… can you?
Bluetooth between phone and PC
I’ve spent the last two days pulling out my hair, trying to get an application on my PC talking to my Bluetooth phone. If you have an inbuilt aversion of using Java for PC apps (like I do), there is preciously little documentation about this. Benhui shows how to do this particular thing between two Java applications (one running on the phone, and one on the PC). But if you don’t want to use Java on the PC, you’re pretty much stuck using sockets, and there is little documentation example material out there on the net.
So this is where this blog item comes in. I’m going to tell you how I did it, and share my source code.
This code uses the Microsoft Bluetooth Stack Socket API. You require WinXP SP2 for this, or — reputedly — WinXP SP1 with the Bluetooth stack downloaded and installed separately. Linux uses a completely different stack, obviously, with BlueZ and Affix being the most popular. These stacks also have socket APIs, so you may find the code presented here useful, but remember that this code is specifically for Windows.
On your PC, you will need some constants and structs from the MS Bluetooth SDK. I implemented these in Delphi, but you can use them equally well in any language.
I did this in Delphi so that’s the language these definitions will be in. You should be able to translate them easily into your programming language of choice:
// Bluetooth address family
AF_BTH: Integer = 32;
// Bluetooth SPP protocol
BTHPROTO_RFCOMM: Integer = $0003;
// Bluetooth service namespace
NS_BTH: Integer = 16;
// Bluetooth address struct
PSockAddrBth = ^TSockAddrBth;
_SOCKADDR_BTH = packed
record
addressFamily: U_SHORT;
btAddr: Int64;
serviceClassId: System.TGUID;
port: ULONG;
end;
TSockAddrBth = _SOCKADDR_BTH;
For Delphi, you’ll also need a copy of the winsock2 headers, because we require theWSASetService call, which is not available in the winsock header that is shipped with Delphi. You can find it via Google.
The (simplified) code goes like this:
// ———— Variables ———————–
var
s,t : TSocket;
sa, ta : TSockAddrBth;
sasize, tasize : Integer;
ca : CSAddr_Info;
qs : TWSAQuerySetA;
// ———— Code ————————-
// Create Bluetooth socket
s := socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
if s = INVALID_SOCKET then RaiseLastOsError;
// Bind to listening address
sa.addressFamily := AF_BTH; // Address family
sa.btAddr := 0; // Address not set
sa.serviceClassId := NullGuid; // NullGuid is simply a GUID with all zeroes
sa.port := ULONG(-1); // Let OS select port
if bind(s, PSockAddr(@sa), sizeof(sa)) = SOCKET_ERROR then RaiseLastOsError;
// Get the bound name back, required for WSASetService
sasize := sizeof(sa);
if getsockname(s, @sa, sasize) = SOCKET_ERROR then RaiseLastOsError;
// We need to register this socket with WSASetService, so that it can be
// discovered by other Bluetooth devices. Filling
FillChar(ca, sizeof(ca), 0);
ca.LocalAddr.lpSockaddr := @sa;
ca.LocalAddr.iSockaddrLength := sizeof(sa);
ca.iSocketType := SOCK_STREAM;
ca.iProtocol := BTHPROTO_RFCOMM;
// Set service record
FillChar(qs, sizeof(qs), 0);
qs.dwSize := sizeof(qs);
qs.lpszServiceInstanceName := 'My service';
qs.lpServiceClassId := @MyGuid; // MyGuid is an application-specific GUID
qs.lpszComment := 'This is a test service';
qs.dwNameSpace := NS_BTH;
qs.dwNumberOfCsAddrs := 1;
qs.lpcsaBuffer := @ca;
// Register service
if WSASetService(@qs, RNRSERVICE_REGISTER, 0) = SOCKET_ERROR then RaiseLastOsError;
// Set-up is complete. You can now use the other socket functions,
// listen(), accept(), recv() and send() as usual.
On the mobile phone, you will need to write a J2ME application that uses the JSR-82 API, which is a standardized Java API for Bluetooth. To write the application, you will need to install 250MB’s worth of Java SDK (the J2SE SDK and J2ME SDK). I based my application on the BluetoothDemo application that is included with the J2ME.
Key points:
- Use the same GUID as MyGuid used above, as the only GUID in the UUID list when specifying a device search. You don’t need to use the attribute set used in the example.
- Make sure you are not connected to some other device (such as the Nokia PC Suite) when doing a device discovery — otherwise it won’t work.
If everything goes well, you should be able to discover the socket you just created (provided you have set your computer to discoverable in the Bluetooth settings), and connect to it. After that, you can exchange application-specific data in the same way as a regular socket/stream connection.
This post does not cover using Bluetooth standards, such as the OBEX protocol. I might post something about that when I figure it out, but since it doesn’t interest me very much at the moment, don’t count on it anytime soon.