So Many HTML Parsers Suck

Published at 11:42 on 24 December 2019

Why? They ram a document tree down your throat, that’s why. So you’re stuck writing code that:

  • Consumes more memory, since you must load the entire document in memory at once, and
  • Makes modifying the content tricky, since traversing a document tree you are modifying is a potential minefield. (The alternative is to create an entire new document tree from the old one, which doubles the already sometimes obscene memory footprint.), and
  • Consumes more processor time, because multiple tree traversals are typically necessary.

Slow, bloated, error-prone: In a word, document trees just plain suck. Yes, sometimes they are necessary. That just means they should be a necessary alternative. They should never be the only way you can parse HTML.

Yet, with all too many HTML parsers, they are the only way. And that’s why so many HTML parsers suck.

The Shoes Start Dropping

Published at 22:09 on 16 December 2019

Today, Boeing announced that they will “temporarily” stop production of the 737 Max.

Note that I put “temporarily” in quotes. I predicted last April that the only lasting fix for the 737 Max will involve the scrap aluminum recycling industry, and I am sticking by that prediction. It may take an ill-considered recertification of that aircraft, followed by the loss of more lives, to seal its fate, however.

Why Do My Pictures Show up Sideways (And How Do I Fix Them)?

Published at 11:09 on 12 December 2019

The Root Cause

The root cause of the problem is that there’s a (relatively) new feature in image files from digital cameras which not all software supports. So an image can look just fine when you preview it (because that program supports the feature), yet when you upload it to the Web, suddenly it appears sideways (because many web browsers don’t)!

The Details

Modern cameras contain sensors that tell their on-board computers which way the camera is being held. When it captures an image, the camera records which way it was oriented (portrait or landscape) in the resulting file, but it always writes the image data itself in landscape (larger dimension horizontal) format.

It is considered the responsibility of any program that displays images to read the orientation information and use it to display the image properly, by rotating things if needed. Unfortunately, many web browsers in particular don’t read the orientation information; they simply assume that the horizontal dimension will always be horizontal (because, prior to the new feature, it was).

The Workaround

The workaround is to rotate the file if needed, so that the horizontal dimension of the image data is always the dimension that should display horizontally.

To do this, I use the free image-manipulation program GIMP. It can read the orientation information, and if it encounters a portrait-mode file, will always ask on reading it if it should be automatically rotated. Always answer no to this question! (This automatic rotation is the feature you want to get the image to display properly with without, after all.)

The result will, of course, be a file that displays sideways. Use the rotation options under the Image… Transform menu to fix the orientation. Then use File… Export As to re-save the result as a new file. The result will be a file that always displays correctly.

Corbyn is Toast

Published at 13:18 on 11 December 2019

I may be wrong (and I hope I am), but I see absolutely no evidence that Labour will prevail in the coming general election in the UK. The polls show that Labour has lost ground compared to how they polled prior to the previous election.

Yes, the pollsters botched the prediction of that one, and badly. It is, however, reasonable to assume that they have learned from their mistakes and adjusted their techniques. Remember, Labour is polling slightly worse than in the previous election, and Labour still lost that previous election. (The surprise in 2017 was that Labour barely lost an election that it was expected to lose by a landslide.)

All in all, it really doesn’t look like Jeremy Corbyn will manage to pull a rabbit out of his hat this time.

A Belated Post-Thanksgiving Check-In

Published at 11:00 on 8 December 2019

Not much to report recently save the somewhat frustrating experience I had on Thanksgiving. I was visiting some old friends in Seattle, and one of them, who works as a hydrologist, was having no end of trouble analyzing a batch of huge data files. The root of her troubles was that the software she was using was attempting to load the entire file in memory before operating on it.

That was highly frustrating for me to observe, because:

  1. All indications are that it was probably unnecessary to load the entire file into memory (i.e. it was possible to process it on a record-by-record basis).
  2. If so, I could easily correct the above problem.
  3. That their lack of computer expertise is causing this one project to be adversely impacted indicates that it’s unlikely to be the only such project; odds are this is merely the tip of an iceberg.
  4. I don’t work there, therefore I am not allowed to address such problems.
  5. I’ve been unable to convince anyone who does work there and who has the authority to hire me (either as a contractor, or as an employee) to so much as meet with me.

The Coup in Bolivia

Published at 15:50 on 17 November 2019

Mind you, the original ouster of Evo Morales was a popular uprising, not a coup. The problem is, what’s happened since then is sounding more and more coup-like with each passing day. Particularly this (source here):

The IACHR decried as “grave” a decree from the Anez government exempting the armed forces from criminal responsibility as they preserve public order.

The rights group, an autonomous arm of the Organization of American States, said the effect of the decree could be to “stimulate violent repression.”

Just like I can think of no plausible excuse for Morales (or anyone else) to cling to power for term after term, I can think of no plausible excuse for a government placing parts of itself above the law when it comes to committing acts of violence against the people.

In fact, it’s even harder to think of any excuse for the latter. Clinging to power is merely the sort of egoism on the part of a leader that smooths the way to becoming a tyrant in the future. Giving the military a blank check to kill and maim basically is tyranny.

An Impractical Fantasy

Published at 13:06 on 15 November 2019

This is an amusing liberal fantasy, but is it really practical? Probably not.

If Bloomberg or Steyer (or Bloomberg and Steyer as a partnership) buy Fox News, and tell their employees to run a real news outlet instead of a right-wing propaganda mill, what will Fox News’ talent do? Some of them might comply with the new boss’s orders, but many wouldn’t.

Murdoch would be flush with cash thanks to the transaction, and use it to start a brand new right-wing propaganda mill. (The market viability of such things has already been proven by today’s Fox News, of course.) The disgruntled talent from the old Fox News would jump ship to the new network, as would the audience for that talent.

It would all amount to nothing more than a very expensive game of Whack-a-Mole.

Mind you, there is a problem with Steyer and Bloomberg using their money to run as primary candidates, and there are much better ways that both could be spending their money, but buying Fox News is not one of those ways.

Pelosi Hits One out of the Park

Published at 16:25 on 14 November 2019

Her use of the term “bribery” was an excellent piece of messaging.

First, it’s accurate. What Trump did to Ukraine is by any common meaning of the term “bribery.”

Second, it’s damning. “Bribery” is explicitly mentioned in the Constitution about grounds for impeachment. There is no distinction made between being on the giving or receiving end of a bribe; as such, either is forbidden.

Third, it’s simple and direct. Not everyone knows what “quid pro quo” means, but the meaning of “bribery” is understood by nearly all.

A shockingly high fraction (and probably a decisive majority) of the electorate is either lazy, stupid, or ignorant. To admit this is electoral suicide, so no even marginally competent politician is ever going to say it out loud. (Just revisit where Hillary Clinton’s “deplorables” comment helped to get her.) But it’s still true. As such, keeping it as simple as possible is generally the best strategy.

Democrats often drop the ball when playing politics. Not this time.

Morales is Out — Good Riddance

Published at 08:39 on 12 November 2019

When he took office, he represented much-needed change, and Bolivia has gotten less unequal and more prosperous since then. Now, however, he represents most of all how the seats of power corrupt whomever happens to sit in them.

He initially promised to serve only the single five-year term the constitution he was elected under allowed. Then he argued that the new constitution his government passed in that first term (which allowed for two terms to be served) meant that only terms under the new constitution counted, and ran for re-election, twice.

That gave him three terms: one under the old constitution, and two under the new. That wasn’t enough for Morales, so he tried to amend the new constitution to allow him to serve a fourth term. Amending the Bolivian constitution requires a popular referendum, and that amendment went down to defeat. So Morales turned to the Supreme Court. Thanks to having now served in office for well over a decade, his appointees controlled the court, and dutifully ruled that the Constitution didn’t actually mean what it said, and that Morales could run for a fourth term.

Initial election returns showed him losing that election, then returns mysteriously stopped being reported for about a day. When they began to be reported again, they showed (surprise, surprise) that Morales had secured just enough votes to be elected to a fourth term.

It was in that context that the popular uprising against Morales commenced.  It is critically important to note that the army and police revolted against Morales only after weeks of popular unrest; what has happened in Bolivia is not a coup d’etat. In a coup, the army leads the process. In Bolivia, the army followed the lead of the masses. In fact, Morales himself took power as a result of a similar uprising against his predecessor, Gonzalo Sánchez de Lozada.

As popular uprisings give, so should they take away. Political revolutions often get to the point where they become corrupt and require a new revolution. They only seldom get this needed second revolution; in this respect, what has just happened in Bolivia is as much a miracle as the revolution that unseated the old guard and installed Morales in the first place.

Of course, the new president is a member of that very same old guard, so there is absolutely no reason to think he won’t be a disaster of a different sort. At least he’ll be a weak disaster, and vulnerable to being unseated by yet another popular uprising. (And if he is, he will probably whine about being the victim of a “coup,” too.)

So be it. Morales had lived well past his period of usefulness, and his shenanigans with the Supreme Court conclusively demonstrated that things had gotten the point where he deserved to be the target of a revolution himself.

Bolivia’s public finances, which in the first decade of Morales’ administration did very well, have been getting undermined by corruption-fueled unsustainable spending in recent years. Bolivia’s part of the Amazonian jungle is on fire as much as Brazil’s; just like Bolsonaro, Morales had decided to de-emphasize enforcement of environmental laws there.

Had Morales stayed, all evidence indicates that Bolivia would have gone down the same path Venezuela did. Good riddance.