Category: Reference

Transcoding JPEG optimizer from Mozilla

The people at Mozilla have produced a transcoding JPEG optimizer. https://github.com/mozilla/mozjpeg/releases This thing is sweet: it takes ordinary JPEG files and recompresses them much more efficiently without making the images deteriorate. It uses the long-standing and well-tested Independent JPEG Group reference implementation, and adds a bunch of optimizations. It’s not built for GUI users; it’s a command-line utility. For those… Read more →

Filling in missing data with sequences of cardinal integers

When you’re extracting summaries of information from a database, sometimes rows are missing.  For example, if you are keeping track of number of customers by day, you might use a query like this: View the code on Gist. You might get a result set like this: 2014-03-07 122 2014-03-08 355 2014-03-10 234 2014-03-11 119 Notice that the row for 2014-03-09… Read more →

The Vincenty great-circle distance formula

This Vincenty formula is a more numerically stable version of the spherical cosine law formula (commonly and wrongly known as the Haversine formula) for computing great circle distances. The question of numerical stability comes up specifically when the distances between points are small. In those cases the cosine is very close to 1, so the inverse cosine function is not… Read more →

SQL Reporting by time intervals

A version of this article specific to the Oracle DBMS is here. It’s often helpful to use SQL to group information by periods of time. For example, we might like to examine sales data. For example, we might have a table of individual sales transactions like so. Sales: sales_id int sales_time datetime net decimal(7,2) tax decimal(7,2) gross decimal(7,2) Each time… Read more →

Using MySQL’s geospatial extension for a location finder

It’s possible to use the geospatial extension in MySQL for an efficient location finder.  For this to be worth the trouble, the following conditions must hold. You must use a MyISAM table for your geospatial data, or use version 5.7.5 or later of MySQL. A NOT NULL qualification on your geometry column is required A spatial index is needed:  ALTER… Read more →

Stored function for haversine distance computation

In another article I described the process of using MySQL to compute great-circle distances between various points on the earth then their latitudes and longitudes are known.  To do this requires the formula commonly called the haversine formula. It’s actually the spherical cosine law formula, and is shown here. There’s a more numerically stable formula — better when points are near… Read more →