Suppose you want to chose between several values randomly with uniform probability. That is, you might have 5 options, A, B, C, D, E. You want to chose among them with equal probability. You generate a random number from [0-1),…
Some years ago I posted an article about how to compress unit vectors, or normals, efficiently into 16 bits. The original article is getting harder to find, so I’m reposting a version of it here. Since the original article this…
How do you close a network socket such that the cost is lowest for the server and highest for the client? Specifically when a server open to the public receives thousands of DDOS hits, how can I close the connection…
In an earlier article I described how to write a read/write lock. This type of lock can lock a shared resource to allow multiple reader thread or a single writer thread and no readers. But sometimes you want to be…
In multi-threaded programs you often find a usage pattern where many more threads need to read a shared resource than write to it, and where reading the resource would be thread-safe without mutexes if it is not being written. (…
Detecting crashes in multi-threaded systems can be difficult. Often the crashes are difficult to reproduce, and when they happen the faulty operation could have happened many calls ago and so the you don’t get a stack trace at the time…
I’ve been learning how to make widgets with JQueryUI. We’ll work through a real world example. The Problem Let’s start with the problem. I have a web app that has tons of dialogs that need to be validated. So lets…
Powerful languages make it easy to overuse resources – especially memory. static_assert is a good way to detect these problems early. In a recent project, I created a hash table with 256 buckets where I needed to add a random…
We installed a widget that displays our instagram photos on our blog sidebar at blog.mimoco.com . Its a nice widget called “BadgePlz”. But sadly this widget is definitely malware. It will periodically redirect your users to porn sites. It appears…
Getting the serial number for a USB Serial drive on Os X is tricky just like it is to get a USB serial number on Windows. We want to get the serial number of a USB Flash disk that is…