Some Bits: Nelson's log

4 posts in April 2019

Hosting your own Dropbox clone

I decided to set up my own private file syncing service. Dropbox recently degraded their free level, limiting you to three devices. Fair enough but ugh. Also I’ve been doing a funky hack with FreeFileSync where I keep personal files on two Windows boxes in sync via an external hard drive I carry back and forth. That works and solves the bandwidth problem, but is kludgy.

So.. what’s out there for free Dropbox alternatives? A quick search turns up ownCloud, NextCloud, and Seafile as popular choices. NextCloud is a fork of ownCloud and seems to be doing well so I picked that one.

NextCloud requires you’re running a server on an always-on Linux box somewhere. Installing the server is either a complex mess or as simple as could be. If you go the old school manual route it’s a mess; the server requires MySQL and a web server and a bunch of PHP stuff. They have detailed docs on how to install it on Ubuntu, but ugh.

Happily they also have a containerized server, Nextcloud Snap. And I’ll be damned but it really is as easy as a couple of lines of shell to install and get running. The only wrinkle I ran into is they really want to be running a visible web server under the / URL, and I already have a web server. So I had to change the ports the web server uses

sudo snap set nextcloud ports.http=81 ports.https=444

So far it seems to be working, we’ll see how it does in a month. The product is probably overkill for personal use, it’s really set up for a whole small office with many users, fancy integrations with apps, etc. I just want a better rsync!

The one thing I didn’t evaluate is SyncThing, the outcome of the old BitTorrent company that is in fact a better rsync. I’d like to try that and see if it’s a lightweight alternative.

Update: a second wrinkle; all my user files are being stored in the Snap directory, which is on the small / fast SSD. I wanted to replace that data directory with a symlink to a slow hard drive, but of course the symlink goes outside the Snap container’s boundaries and doesn’t work. There’s various workarounds for this but for now I’ll just live with it.

Custom web fonts in 2019

I finally updating my old somebits.com CSS to use a wider text box and a modern font. Goodbye, Arial 400px wide! I’ve not paid much attention the development of CSS3 font technology so this is all new to me. I’m using free fonts.

Which font?

Free, not ugly, and with decent Unicode range. I looked through this Wikipedia page and hit on several likely options: Bitstream Vera, Liberation fonts, Noto fonts, and Source Serif Pro. I decided I liked how Source Serif Pro looked best. I don’t know how great its Unicode coverage is; from what I’ve read it’s mostly western scripts. Fine for normal use, and hopefully the browser fallbacks will suffice for the occasional CJK or obscure other stuff.

Update: I just realized that Feedly uses ITC Charter, which is free. There’s also a Unicode-enhanced version from SIL called Charis. I converted their WOFF to WOFF2 using an online tool and tried it on my blog. It’s stylistically very similar to Source Serif Pro but not quite as good looking and significantly larger files, so I won’t use it.

Hosted fonts

The easiest way to use a custom font is use a hosted solution like Google Fonts or Adobe Fonts (nee Typekit). They have you include a single CSS stylesheet and then you can refer to the fonts by name in normal CSS. The problem with this is they then get tracking info on every page that uses the font, which is bad for privacy. So I’d prefer to self host.

Self hosting

First you have to download the font in the right format. Choices are EOT, TTF, OTF, WOFF, WOFF2, and SVG. This website says EOT and SVG are obsolete, and TTF and OTF are unnecessary, and that WOFF is basically a wrapper for TTF/OTF and WOFF2 is just an improvement on WOFF. Confusingly, Adobe’s distribution of Source Serif includes both “TTF WOFF” and “OTF WOFF” versions. This page says OTF is better. WOFF2 seems to be nearly universally supported so I’m going to go with that with the OTF variant. (A lot of sites still serve WOFF as well, but I think that mostly only matters to MSIE 11 at this point.)

You can get a clue how to self-host fonts by just copying what Google or Adobe serves as CSS. See Adobe, Google. You can get pretty far just by copying what they do but changing the URL. But starting from first principles...

The simplest thing that work is this little bit of CSS

@font-face {
  font-family: "source-serif-pro";
  src:url("SourceSerifPro-Regular.otf.woff2");
}
body { font-family: source-serif-pro }

This says “I’m declaring a new font-face named source-serif-pro and you can find it at this URL”. Then tell the body of the document to use that font. And it all works, done! It also does reasonable Unicode fallbacks for things that aren’t in the font. But not quite done; this font only is normal font; the browser will fake italic and bold versions (ie, ugly). This is better:

@font-face {
  font-family: "source-serif-pro";
  font-style: normal;
  font-weight: 400;
  src:url("SourceSerifPro-Regular.otf.woff2");
}
@font-face {
  font-family: "source-serif-pro";
  font-style: italic;
  font-weight: 400;
  src:url("SourceSerifPro-It.otf.woff2");
}
... versions for Bold and BoldItalic as well ...

That will let the browser use a properly designed italic font when necessary instead of just slanting the letters to the right. That really matters for bold, bold is used a lot in CSS (like headers). The key thing here is you’re expanding the options available on the source-serif-pro family, with the cost of now the browser has to download more files (100k each). In theory you can bundle all 4 variants into one file using variable fonts but I think that’s still a little bleedingedge.

There’s some advanced options too. You can tell the browser you only care about certain Unicode ranges, which may help with download sizes. You can tell the browser to preload the fonts or use local copies if the exit. You can fine tune whether it will use a system font until the real font is loaded. You can also tweak font rendering settings and kerning.

Anyway, now I know how to self host a font. You can see a bunch of test cases, etc in this dev test directory. The selfhosted variation is what I will end up using.

Working on a regional map for Papua New Guinea

A friend of mine is an anthropologist expert on Papua New Guinea, particularly Enga Province. There are precious few good maps of PNG (famously) so he’s asked me if I could help prepare a schematic map of the region he can use in a publication. If it goes well maybe we can submit the map to Wikipedia or something too.

For inspiration I pulled a bunch of sample maps from Bing / Google / Openstreetmap, also from the Rumsey archive and various online sources. I particularly liked this map (from this paper) and the SIL map. Openstreetmap’s default map style isn’t bad, either, and I’m encouraged by how much data OSM has. (I don’t need detailed roads, just a single image at large scale.)

It’s interesting how some of the custom maps emphasize roads, others emphasize rivers. Really terrain is a pretty key element of understanding the area too, it’s quite rugged, but most of the maps I see are constrained by print restrictions to not including terrain.

I’m also starting to read up on Wikipedia’s guidance for maps. WikiProject Maps is a good place to start. I really like their exemplar of The Big Island of Hawai’i; the combination of coloured elevation contours and subtle hill shading is great as a base for the map symbols. They also have an SVG template for icons and such. A lot of these principles only work in color though, and I think for print I have to go greyscale.

As for implementing this, my plan is to start with Natural Earth and OSM data and rough something up in QGIS. And then start working in earnest with a tool to extract the data I need and export it to SVG format. Mapnik maybe? Then use Inkscape to further style and deliver the SVG, also allow non-map experts to add text annotations. Or maybe I can lean on QGIS more than that and not write custom code to emit the SVG I need. Looking forward to learning more.

Facebook’s population density data

A group over at Facebook has released a valuable new dataset, High Resolution Population Density Maps. They used machine learning to look at aerial imagery and figure out where people live, then put dots on a map (one per arcsecond) with estimated density. Their post goes into detail; the data now is most of Africa with the whole world planned. There’s not a great browser for the data but the files are easy to work with and smaller than you’d think; a few megabytes per country.

I took a quick pass at the Liberia data in QGIS, here it is plotted by quantiles on top of Stamen Toner Light:


It’s immediately apparent that the density data is banded. Each red dot in Monrovia, for instance, has the (exact) value 23.255445274781373. Half the dots have no value, even in the middle of the city, maybe because no single building was reliably detected in them? The orange dots north of there are about 9.3. Some small villages out in the hinterlands show very high densities, like 45. I don’t know if that’s at all like reality or rather an artifact of detecting relatively few buildings in a big rural area.

By contrast Johannesburg has much more variation in densities. Maybe South Africa has better data on population-by-region than other places

Nigeria’s data is somewhere inbetween. Lagos has big regions of uniform density but there is at least some variation. I can’t figure out what the building detection did in the rural areas. Their system did correctly figure out there are people in this general area, but the dots and the buildings don’t particularly line up.

I’m no expert in this kind of data and have no idea what the state of the art is. But this looks to me like two separate datasets mushed together. One is new and fine grained, a binary yes/no building per arcsecond based on image analysis. And then there’s some larger granularity numerical “X people per building” that they’ve taken from some other data source, maybe government census data. The combined data is them just applying that number X to the binary thing about whether there’s a building or not.

It’s not bad! But I had initially thought they were doing something more subtle, where they were estimating building size or height or density. If I’d read their description more closely I would have already realized they were not doing that:

we redistributed all the census counts equally over all the buildings found within that census area. This method assumes equal population distribution per building within a census area, which we felt was the least error-prone method of obtaining population densities since it doesn’t make any assumptions on the number of people per building and constrains systematic errors to within one census area.

For an alternate take at the data, @Mikel took a shot at a slippy map using MapBox, you can see the result here. I had trouble getting it to load new points past the initial view. But see the screenshot below