Suppose you are given the coordinates for two places on the globe and you want to know how far they are from each other. If you want to be precise this is actually quite hard because of the Earth’s irregular shape. If we model the Earth as a sphere the shortest path between two points is on a “large circle,” and you can compute the distance using the haversine formula or the spherical law of cosines. But these formulas are quite complicated and slow to compute, and the world is pretty flat over distances of a few kilometers. Surely there’s a fast approximation that’s good enough?
Continue reading “Geographic distance can be simple and fast”Can Java be faster than C?
Every now and then people get into silly arguments about which programming language is “faster.” I always ask, faster for what? Faster compile-run-test cycle, faster to write correct programs, faster to run…? Besides, each language is tuned for certain usage patterns, making like to like comparisons impossible.
Continue reading “Can Java be faster than C?”Setting X11 window properties with xprop
xprop is a program that can list and set X11 window properties. Listing properties is really simple: just run xprop and click on the window that you are interested in, or use the -root or -id command line parameters to choose the “root” window or a window by ID. What’s not so clear is how the properties can be set; the manual does not give any examples.
In order to set a property you have to define the data format. This consists of the bit-width and data type: for example a string of 8-bit characters is 8s. A 32-bit hexadecimal integer is 32x, these are useful for example for window IDs. The widths and data types that can be used are documented in the manual page.
Here’s a simple example: PulseAudio uses a property called PULSE_SERVER on the root window to know which audio server is used in the desktop session. To redirect the audio to a PulseAudio server on another host over TCP/IP you can use:
xprop -root -f PULSE_SERVER 8s -set PULSE_SERVER tcp:otherhost:4713
Let’s draw the Mandelbrot set!
When I was 12 or 13 I saw a science program about fractals and chaos theory. I was intrigued by the intricate organic shapes and bright colors, especially of the Mandelbrot set, and decided I wanted to learn how to make them. This is how I got interested in mathematics and programming in the first place. Drawing the Mandelbrot set makes a rewarding exercise for a beginning programmer, covering many important topics like loops and conditional statements.

Welford’s method for computing variance
The standard deviation is a measure of how much a dataset differs from its mean; it tells us how dispersed the data are. A dataset that’s pretty much clumped around a single point would have a small standard deviation, while a dataset that’s all over the map would have a large standard deviation.
Given a sample \(x_1, \ldots, x_N\), the standard deviation is defined as the square root of the variance:
Continue reading “Welford’s method for computing variance”