Sunday, September 16, 2018

Regex 101 is a great online regex tester.

Speaking of regular expressions, for the past year, I’ve used an automated process for building Anki flash cards. One of the steps in the process is to download Russian word pronunciations from Wiktionary. When Wiktionary began publishing transcoded mp3 files rather than just ogg files, they broke the URL scheme that I relied on to download content. The new regex for this scheme is: (?:src=.*:)?src=\"(\/\/.*\.mp3)

Edit 2018-09-17: Nope, still not right. This is the new working version:

Gina Loudon a liar and an idiot. She claims in her recent book proclaiming the sanity of Donald Trump that she has a Ph.D. in psychology. In fact, she does not. Her degree is from an online “school.”

Thursday, September 13, 2018

Politico has a piece today about Trump’s outrageous claims in the face of weather disasters. In almost every context, he reveals himself to be an abject fool; but lurking beneath that idiocy is another layer of loathsomeness - the complete lacking in understanding of science. I want a reporter to ask him any of the following questions about hurricanes:

  • “Mr. Trump, can you describe for us your understanding of how hurricanes form?”
  • “What role do Coriolis forces play in the formation of tropical cyclones.”
  • “Given that hurricanes possess massive amounts of energy, what are the sources of that energy?”

An article from the Times on why yelling at children is comparable to physical punishment. Children who are subjected to yelling have lower self-esteem, and more depressive and anxiety symptoms.[1]

  1. The article cites a study that shows a reciprocal amplifying effect of yelling and behavioural problems: "Mothers’ and fathers’ harsh verbal discipline at age 13 predicted an increase in adolescent conduct problems and depressive symptoms between ages 13 and 14. A child effect was also present, with adolescent misconduct at age 13 predicting increases in mothers’ and fathers’ harsh verbal discipline between ages 13 and 14."

How fascism works

A recent piece in The Atlantic by Peter Beinart filled in a cognitive gap in understanding how a large minority of U.S. citizens continue to support an abjectly incompetent, almost certainly criminal, willfully ignorant, and generally hateful man as president. The article Why Trump supporters believe he is not corrupt makes the argument that when Trump defenders concern themselves with the idea of corruption they are not thinking of political corruption so much as corruption of the purity. This is consistent with Jonathan Haight’s research into the determinants of a person’s moral judgments as a function of political affiliation.[1] Conservatives are likelier than liberals to concern themselves with tradition and purity. When Donald Trump uses the word disgusting which he has done scores of times on Twitter, he’s invoking the conservative fear of taint. The Special Prosecutor’s inquiry into possible collusion and other crimes committed during the 2016 elections, in Trump’s view, are not only unlawful, biased, or unfavourable in some other objective way. It is, to Trump, disgusting (“this Rigged and Disgusting Witch Hunt.”)

According to Beinart, the key to understanding the failure of Trump’s supporters to acknowledge his corruption is the result of how they define corruption.

In a forthcoming book titled How Fascism Works, the Yale philosophy professor Jason Stanley makes an intriguing claim. “Corruption, to the fascist politician,” he suggests, “is really about the corruption of purity rather than of the law. Officially, the fascist politician’s denunciations of corruption sound like a denunciation of political corruption. But such talk is intended to evoke corruption in the sense of the usurpation of the traditional order.”

Why were Trump’s supporters so convinced that Clinton was the more corrupt candidate even as reporters uncovered far more damning evidence about Trump’s foundation than they did about Clinton’s? Likely because Clinton’s candidacy threatened traditional gender roles. For many Americans, female ambition—especially in service of a feminist agenda—in and of itself represents a form of corruption. “When female politicians were described as power-seeking,” noted the Yale researchers Victoria Brescoll and Tyler Okimoto in a 2010 study, “participants experienced feelings of moral outrage (i.e., contempt, anger, and/or disgust).”

Fascists, like Trump, pull a sleight of hand. By invoking the risk of corrupting purity, tradition and order, they distract their supporters from the real political corruption.

  1. This has been noted before by Thomas Edsall back in early 2016 writing for The New York Times.

Managing classical music collections in iTunes in 2018

Like many, I use iTunes to manage my music library. Unlike most, I don’t stream music[1]. That means I have a large music collection - one that stretches the limits of iTunes’ organizational system. The overwhelming majority of the music in our collection is classical; and this is the source of the difficulty.

The problem

For background on why classical music is so poorly handled, read Robinson Meyer’s piece in The Atlantic “The Tragedy of iTunes and Classical Music”. Several issues make is difficult to organize classical works:

  • iTunes regards all music as “songs”. Of course, some classical works are songs, but most are not.
  • The mp3 metadata standard as originally released was incomplete and completely ignorant of organizational requirements beyond “song” and “album.”
  • And of course, much is driven by Apple’s focus on profits. For every classical enthusiast, there must be 1000 popular music listeners. There’s simply too little return on any investment in tailoring the software to meet the needs of classical music listeners.

Naming and metadata standards

  1. Use Work/movement designation - This considerably improves the organization of multi-movement works in iTunes.
  2. Use opus and number designations - Both should be abbreviated, op. and no. respectively. That’s lower case abbreviation followed by a period and a space. If the work is in a sequence, then No. is part of the title and should be capitalized as in “Piano Trio No. 1 in C minor" The # symbol is never used. A slash / is never used.
  3. If there is a catalogue number, then it should be used. The catalogue number should be the last element in the name of the work, separated from the remainder by a comma and a single space. Köchel numbers and Deutsch should be abbreviated K. and D. respectively. However Bach-Werke-Verzeichnis catalogue numbers should not use periods.
  4. Add metadata in track comments - Since iTunes does not yet have all of the metadata that I need to organize my music, I add additional metadata in the Comments field. Four elements comprise the metadata that I currently use: a) Musical form (symphony, concerto, sonata, etc.), b) Musical period (e.g. baroque, classical, etc.), c) Ensemble - solo, duet, trio, orchestra, etc. d) Highlighted instruments - a comma-delimited list of instruments that are featured. While iTunes provides a genre designation, I simply use “Classical” and apply my own period classification in my free-text metadata.

Organizational approach

Since classical music isn’t really organized by “song” and an album is much less important than the works it contains, I break down the album structure and reorganize it by work. In addition to using the work/movement designation in the track info, I create playlists for individual works and playlists folders for broader categories of works by the same composer.

The top-level folder is the composer followed by nested folders of category of works (e.g. sonatas, concerti, etc.) then instrument folders under that level. If I have multiple recordings of the same work, the work itself gets its own folder.

What next for iTunes?

The work/movement designation in track info has been transformational; but iTunes still has a long way to go. Please don’t suggest music to me. Don’t show me a bunch of irrelevant album covers on the iTunes Store page; it’s meaningless to me. On mobile devices, find a way of showing the entire track name. Classical track names are often very long. Sometimes on the phone, I can only see “Piano Quartet No. 3 in…” Wait, is that the one in C minor or in G minor? No idea. iTunes still has a long way to go.

  1. Partly because we live in a rural setting with slow and unreliable internet access, partly because I don't trust that artists are getting properly compensated, and partly because I like to organize my music my own way.

This is an interesting essay in The Guardian on the idea of quarantining extremist ideas.

A non-trivial proportion of the population regards the media as having a responsibility to represent all idea with equal validity. So the appearance of extremist ideas in the press, even if they are treated negatively, results in more legitimacy than they are due. The authors in this essay make a case for quarantining these extreme ideas, refusing to cover them. Strategic silence, they call it.

If I were to implement this, anything Trump writes on Twitter would be quarantined because social media is not a platform for deliberate thought and government policy.

A letter to Jerry Brown

Dear Governor Brown,

By now you are aware of Nicholas Kirstof’s piece[1] in The New York Times in which he presents abundant evidence that investigators and prosecutors framed Kevin Cooper for the murder of four people in Chino.

Advanced DNA testing could produce potentially exculpatory evidence. Or not. But the truth must be pursued. You have rejected calls to exercise the authority of your office to order such testing. It beggars belief that you would not use that authority wisely in the search for truth, when the evidence was distorted for malicious purposes is so strong.

You have erroneously asserted that no one on death row is innocent, but this is clearly untrue. A study published in the Proceedings of the National Academy of Sciences[2] suggests that as many as 1 in 25 persons on death row is innocent. While it may not be politically expedient to do so, the search for truth in this case of apparent injustice must be allowed to proceed.

Alan Kendall Duncan.

  1. Was Kevin Cooper Framed for Murder:

  2. "Rate of false conviction of criminal defendants who are sentenced to death", Samuel R. Gross, Barbara O’Brien, Chen Hu, Edward H. Kennedy
    Proceedings of the National Academy of Sciences May 2014, 111 (20) 7230-7235; DOI: 10.1073/pnas.1306417111.

ESP32, DS18B20, TM1637 integration: Displaying temperature data

In a previous post I wrote about displaying arbitrary data on a TM1637-based 4 digit LED display, highlighting an ESP-IDF component that I extended to display positive and negative floating point numbers. Now we’re going to put that component to use and display actual data from a DS18B20 temperature sensor.

The DS18B20 temperature sensor operates on the Dallas Semiconductor 1-Wire bus. In this application, we aren’t powering the devices using parasitic power. Instead we’re powering the device from an external supply.

Since we’re using a 3.3v bus, the pullup resistor on DQ is 2.2KΩ, not 4.7K.

In addition to my modified TM1637 component, the project uses David Antliff’s components for the 1-Wire bus protocol and the DS18B20 digital thermometer. You’ll need to follow the instructions in the project README file to clone the project and recurse the three submodules.


After cloning the project, you’ll need to configure the GPIO pins in use using make menuconfig. One GPIO is used for the 1-Wire bus and two lines are used for each TM1637 display for a total of 5 GPIO pins. Be careful that you do not use pins that are in use for other purposes on your particular board. For example, I initially use GPIO12 for one of the TM1637 displays, but when connected, was unable to flash the ESP32. It appears that GPIO12 is used as a bootstrapping pin. On the particular board I used for this project, I believe that GPIO12 needs to be pulled low at reset but the TM1637 was not permitting it. Moving do another GPIO solved the problem.[1]

After completing the hardware connections and specifying them in make menuconfig, you can then simply make flash to upload the application to the device.

All of the source code is on github.


  1. More about GPIO12 here

  2. I prefer these displays to the 74HC595 because the TM1637 handles all of the multiplexing for you, whereas the shift-register displays require the host controller to take on constant refreshing of the display.