Automatic git backup
Make a backup repository like

mkdir backup
cd backup
git init --bare

In the repository you want to back up

cat > .git/hooks/post-commit <<fin

git push --force --all --quiet ~/develop/git/backup &
chmod u+x .git/hooks/post-commit

The reflog isn’t kept but you can still find old heads with git fsck --unreachable

It might work differently with remote backups (which obviously make more sense).

Compiling a KDE plasma applet
I spent a lot of time compiling a hacked version of KDE’s binary clock. I’ll try to describe the process here in case it helps somebody out there.

The initial problem’s that the documentation isn’t coherent. There are pages on scripting, voluminous pages on the niceties of accessing the repositories, the repositories themselves that have all the source code but no instructions on compiling it, and instructions on building this or that without links to the source code. There’s also a tendency to provide simple instructions with no hints as to what to do when it goes wrong.

I ended up following this:

I made a src folder inside my project folder and did this in it:

git clone git://

Then I went down two folders an dran the kde-devel-env script that was recommended. I’m not sure it worked.

I ran the cmake and that failed, which was already not promising.

Then I tried to get the source dependencies. First there was a problem with me not having a source repository set, so I added it in synaptic. Then I ran this stuff:

% sudo apt-get update
% dpkg-query -S plasma-applet-binaryclock.desktop
plasma-widgets-addons: /usr/share/kde4/services/plasma-applet-binaryclock.desktop
% sudo apt-get build-dep plasma-widgets-addons
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Picking ‘kdeplasma-addons’ as source package instead of ‘plasma-widgets-addons’
E: Ignore unavailable version ‘4:4.8.4-1’ of package ‘plasma-widgets-addons’
E: Unable to find a source package for kdeplasma-addons

It’s a shame this didn’t work. I spent the rest of the weekend building this package.

So, the next step was to go into the folder for my applet and try to build it directly. That went reasonably well. I fixed some things in the source because it didn’t seem to have been intended to be built like this.

This was important:

find_package(KDE4 REQUIRED)

and I did a sudo apt-get install kde-workspace-dev
that seemed to help, so at this point I could run cmake successfully.

At this point, I found a package called kdesrc-build that does everything automatically. I reckoned that the modules weren’t intended to be built independently and I should let this do all the work.

% sudo apt-get install kdesrc-build
% kdersc-build-setup
% kdesrc-build

That worked for 6 of the 18 packages I selected.

So I decided to pull the changes I’d made from the folder I made them to the source folder this script had created, and try to build from there. I went back to building in the applet’s folder. I discovered it couldn’t find some include files that I could find, so I started adding them to flags.make (one of the files with warnings in telling you not to edit it). This included adding the path to a file cmake had created because cmake didn’t appear to know about it when it wrote the file I was editing. I also changed an include file in the source code, and managed to get the applet to compile but not link.

The problem seemed to be that the applet was compiled against plasmaclock but as I hadn’t compiled that I didn’t have the library files it needed. Then I went back to the kdesrc-build script because plasmaclock is in the kde-workspace package, and that had failed to build, and probably had dependencies that only kdesrc-build was going to sort out.

I resolved one dependency after another as cmake presented them to me in its log files. I’ll try to record all the packages I installed:

libsm-dev libglib2.0-dev libpolkit-qt-1-dev libpolkit-agent-1-dev libxml2-dev libxml2-dev libgstreamer-plugins-base0.10-dev libvlc-dev libbz2-dev libdbus-1-dev libdbusmenu-qt-dev libxslt1-dev libgif-dev libpng12-dev libjpeg8-dev kdepimlibs5-dev libqimageblitz-dev libx11-xcb-dev libxcb-composite0-dev libxcb-damage0-dev libxcb-render0-dev libxcb-randr0-dev libxcb-shape0-dev libxcb-shm0-dev libxcb-sync0-dev libxcb-image0-dev libxcb-render-util0-dev libxcb-keysyms1-dev libxkbfile-dev libxcomposite-dev libxdamage-dev libxrender-dev libxrandr-dev libxcursor-dev libraw1394-dev libpci-dev libxi-dev libboost1.49-all-dev libxtst-dev

Along the way, kdesrc-build made the startling observation that “There is probably a local error causing this kind of consistent failure, it is recommended to verify no issues on the system.”

Anyway, after all this, I managed to get a clean build. Not all features are eanbled, because they depend on libraries that couldn’t be found, but that doesn’t really matter because I only want a clock. And I do have a .so file. I’ll work out what to do with it another day.

Oh, yes, and along the way I noted that the 48 KB of source files I was trying to compile required 316 KB of generated configuration files. That’s not configuration files for the kdeplasma-addons package but configuration files for this applet. There’s something deeply wrong with this system.

Easter in the Chinese Calendar
Today is, I’m told, the birthday of the Bodhisattva Guanyin in the Chinese calendar: the 19th day of the second month. It’s also the middle of Easter weekend. How often does this happen? It’s a reasonable question because both dates are taken from lunisolar calendars. The Chinese new year is, roughly, the second new moon after the winter solstice. Easter is something like the first Sunday after the first full moon after the vernal equinox.

Here’s a Python module with the Chinese calendar:

Here’s code to find the date of Easter (take out the “self”):

>>> for year in range(1900, 2050):
... easter = LunarDate.fromSolarDate(*calc_easter(year).timetuple()[:3])
... print easter.year, easter.month,
1900 3 16
1901 2 19
1902 2 21
1903 3 15
1904 2 18
1905 3 19

2010 2 20
2011 3 22
2012 3 18
2013 2 20
2014 3 21
2015 2 17
2016 2 19
2017 3 20
2018 2 16
2019 3 17
2020 3 20

2043 2 19
2044 3 20
2045 2 22
2046 2 18
2047 3 20
2048 2 23
2049 3 17

So, there are two different patterns here. One is where the Easter falls after the middle of the second lunar month. (The middle of the month is the full moon.) The other is where an extra month occurs between the Chinese new year and Easter. Easter is in the second lunar month for 79 of these 150 years, so a little more than half of the time.

Easter Sunday and Guanyin’s birthday match in 1901, 1918, 1945, 1972, 1989, 2016, 2023, and 2043.

Good Friday and Guanyin’s birthday match in 1902, 1909, 1929, 1932, 1956, 1959, 1980, 1986, 2007, 2027, and 2034.

Easter Saturday and Guanyin’s birthday match in 1912, 1915, 1939, 1942, 1969, 1983, 1996, 2010, 2013, 2037, and 2040.

Guanyin’s birthday falls somewhere in Holy Week in 1901, 1902, 1909, 1912, 1915, 1918, 1926, 1929, 1932, 1939, 1942, 1945, 1950, 1953, 1956, 1959, 1969, 1970, 1972, 1977, 1980, 1983, 1986, 1989, 1994, 1996, 1997, 2004, 2007, 2010, 2013, 2016, 2021, 2023, 2024, 2027, 2034, 2037, 2040, 2043, 2045, and 2048.

Easter Monday and Guanyin’s birthday match in 1904, 1907, 1921, 1928, 1931, 1934, 1948, 1951, 1958, 1975, 1978, 1985, 1999, 2002, 2005, 2026, 2029, and 2046.

The dates don’t repeat over the 19 year metonic cycle. The months nearly do, though. Over this range, the months that don’t match 19 years apart are 1917/1936, 1947/1966, and 1966/1985.

Is 19 a coincidence? Count the number of times the month matches for different offsets of years. The best matches below 100 are then: 0, 95, 76, 19, 38, 57, 87, 68, 84, 65, …

0 is trivial. 95, 76, 38, and 57 are all multiples of 19. The next best match is 87, which is quite a large number, and large numbers do better because there are fewer possible collisions. There is something to the metonic cycle.

How to create a Subversion repository

  1. Install Subversion.

  2. Run svn init.

  3. That tells you to run svn help, so do that.

  4. Nothing promising, but it suggests, so try that.

  5. The project moved to, so go there.

  6. Go to the FAQ.

  7. Choose “How do I create a repository? How do I import data into it?”

  8. That says read the README.

  9. The README doesn’t answer the question, but links to the book,

  10. Go to the book.

  11. Choose the multiple page HTML edition.

  12. Go to Chapter 2, Basic Usage.

  13. The first page is called Help! but doesn’t give help, only says how to use help, which I knew.

  14. The next page, “Getting Data into Your Repository” assumes you already have a repository.

  15. Okay, the next page is “Creating a Working Copy”. That’s what I want. But it assumes I have a remote copy somewhere else (because I managed to set that up despite not knowing how to initialize it) so that’s no use.

  16. The next page, “Basic Work Cycle” assumes you have a repository.

  17. Go back to the “Basic Usage” contents page and try to work out what page explains initializing a repository. Apparently none of them. Maybe basic usage doesn’t require a repository after all.

  18. Go to the full contents page and have a good look.

  19. Advanced Topics? Well, no, it isn’t advanced, is it?

  20. Branching and Merging? No.

  21. Aha! Chapter 5, “Repository Administration”, includes a page on “Creating and Configuring Your Repository”

  22. That says svnadmin create.
  23. Run svn help | grep svnadmin to confirm that I didn’t miss the reference the first time.

  24. Run svnadmin create .

  25. Add a file.

  26. Apparently I can’t add a file because “‘.’ is not a working copy”.

  27. Run svn co . and observe the unhelpful error.

  28. Run svn co $PWD and observe the unhelpful error.

  29. Run svn help co and fail to find a mention of local paths, but observe that it wants a URL.

  30. Run svn co file://$PWD

  31. Thank you, Subversion!


svnadmin create && svn co file://$PWD

Tripod-12 tuning
I’ve been thinking about the 7 note subset of the tripod scale that can be written as

E F G# A B C D# E

Read about it here:

To implement it, I’ve got the 9 note tripod scale (Gypsy plus a Db and Gb) plus 3 other notes to give a 12 note scale. Here are the scala files:

! tripod12.scl
Tripod scale plus 3 pitches

! tripod12oe.scl
Tripod scale plus 3 pitches

It sounds fine to me, looks like a way of adding septimal harmony to traditional melody. As well as the E gypsy there’s some support for C and F major but no G major triad.

Another thing I thought about is that E-A-Db-Gb-B-E probably works as a quartal chord. The Db-Gb isn’t an approximate 4:3 in the tripod scale, though. More like a 7:5 in fact (leading to meantone with Fx instead of Gb) or 11:8 (apollo). Other steps approximate either 4:3 or 9:7. It might do as the open string tuning of a tripod guitar.

The Consistency of Cangwu Badness
One of the desirable features about cangwu badness is that there’s a strong relationship between the best temperaments of different ranks. There are geometric reasons for this, but to see it take a look at the standard search the temperament finder does, 11-limit 5-cent target:

The best equal temperaments are 31, 22, and 12.

The optimal rank 2 temperament is Orwell. It includes the two best equal temperaments: 31 and 22. The second best rank 2 class is Meantone. It includes the first and third best equal temperaments: 31 and 12. So the best three equal temperaments lead to the best two rank 2 classes. Also, the best four rank 2 classes all have the best equal temperament in common: 31.

The three best equal temperaments lead to the best rank 3 temperament: Minerva. The next best rank 3 class, Thrush, includes the first, second, and fourth best equal temperaments: 15, 31, and 12. The intersection between these two rank 3 classes is Meantone — only the second best rank 2 class, so the relationship isn’t perfect. Four of the top 3 rank 3 classes do include Orwell: Minerva, Marvel, and Zeus. The top 4 rank 3 classes include Orwell, Meantone, and Valentine as intersections -- the best three rank 2 classes. The next rank 3 class, Prodigy, also gives Miracle (with Marvel). So if you had been searching for rank 2 classes as intersections of the best rank 3 classes, the search would also have been efficient.

The top 6 rank 3 classes — and all but one of the top nine — include 31-equal, the best equal temperament.

All of this doesn’t mean the rank 3 badness is correct in terms of musical utility. All it shows is that the badness of the rank 3 classes is tied to that of the lower ranks. So, if the rank 2 badness makes sense, at least the rank 3 classes will represent unions that may allow for hyper-modulations from one rank 2 class to another.

11-limit rank 4 temperament classes are simple unison vectors. The best four here — 176:175, 441:440, 225:224, and 540:549 — define 31-equal. The subsets define:

176:175, 441:440, 225:224 — Meantone

176:175, 441:440, 540:539 — Myna

176:175, 225:224, 540:539 — Orwell

441:440, 225:224, 540:539 — Miracle

Not a perfect match for the rank 2 ordering but the best two still come out.

Add 100:99 to the mix and the equal temperaments 31, 12, 22, 27e, and 41 come out as subsets. These include the best three from the full search, and only 15 is missing from the top six (385:384) would give it.

I seed my searches with equal temperaments because that’s generally the most efficient way of doing it. Lower ranks are more interesting and you only need pairs of equal temperaments to find rank 2 classes. The number of unison vectors you need goes up as the number of primes rises. Also, equal temperaments are easy to find because you can iterate through octave divisions and the number of plausible mappings for each is low — especially when the badness criterion is strict. Cangwu badness guarantees that you can find the best n equal temperaments.

Cangwu badness makes higher rank searches more efficient by allowing you to discard poor looking intermediate results. The same trick would work if you started with unison vectors. In this case, the best six ratios would get you a long way. For rank 2 combinations, you’d be taking 4 combinations of 6 to give 15 options. But you needn’t look at all of those because some rank 3 results would have been discarded. The unison vectors should have been easy to find, as well, as they all correspond to ratios of two or three digit numbers. The best 10 are still this simple, and give you a larger search space: 210 possible rank 2 cases, but you wouldn’t need to look at all of them.

Then 3025:3024 comes in, so you do have to check fairly high, so I still think equal temperaments are better.

Cangwu badness provides an efficient way of finding good temperaments (by its own assessment). It’s most efficient at finding the best (all but one of the top twelve ratios in this search are unison vectors of 31) and less so for the mediocre ones (if you keep finding 31, it stops you finding other things).

The Single Tiny Manager

A management book arrived at work, with a promising title. Unfortunately, it turned out not to be as exciting as I thought. So, I decided to write the book I wanted to read. I changed the title to avoid copyright problems. (It’s an alternative translation from the original chinese.) Here’s the first draft of the first chapter:

The Single Tiny Manager Meets the Monkey

Chapter 1

It was raining. That made the heat more bearable, but still the monkey demon was not happy. He didn’t like the rain. He didn’t like much at all. After the first hundred years of imprisonment, he had concluded that he hated all the weather. He hated the heat, he hated the cold, he hated the rain, and most of all he hated the Buddha for trapping him here after he’d defeated all the Heavenly armies. If he had a little less pride, he might have hated himself for causing all this trouble, but pride was something he had a great deal of.

"Excuse me!"

The monkey demon looked down. Then he looked further down. Standing before him was the smallest man he had ever seen.

"Are you the former Keeper of Horses to the Jade Emperor?" the minute individual asked.

"I am the Great Sage Equalling Heaven!" bellowed the Keeper of Horses. "If you were in reach of my cudgel I’d teach you some respect!"

"Yes" said the small man. "You do have well known problems with anger management, don’t you?"

"Who are you to talk to the Great Sage Equalling Heaven about problems?"

"Of course, I haven’t introduced myself. I am the Single Tiny Manager."

"You certainly are tiny. I’ve never seen anybody so small."

"You should judge me by results, not my physical appearance. In this case, you should be happy, because my goals coincide with yours. I have been sent by the Jade Emperor to supervise your release."

"Ah, so the time of my freedom is at hand!"

"Yes, I think we can manage it very soon. You were only supposed to be kept here for five hundred years. But you know how the time passes in heaven. And the Jade Emperor’s organization really was in a mess. That’s where I came in, of course. A simple application of the latest management techniques and it’s amazing how much more efficient the whole operation is. Back in the Tang Dynasty, which you will not know about — they really were well organized. But that’s not what I came here to talk to you about. Back then, it seems that nobody in Heaven had the slightest idea about time management. From what I can make out, you were scheduled to serve as a bodyguard of a monk who had had some books to collect in India. Well, got them all right, but only because the Bodhisattva Guanyin cleared the path of various demons that he would have had no idea how to deal with. The Bodhisattva registered a complaint about your services not being supplied as promised, but nobody did anything about it. After the Jade Emperor brought me in as a consultant, I instituted a policy of tackling the backlog of unactioned tickets, and I discovered that you had been left here far beyond the term of your sentence."

The Single Tiny Manager stopped, and checked his watch. He didn’t have time to explain the whole situation, and would an ancient demon with no recent experience of management learn the correct lessons from the appraisal anyway?

"But now the Great Sage Equalling Heaven will be given his freedom?" the monkey demon asked hopefully.

"I have to tell you, there are certain aspects of your behaviour that I’m not at all happy about" the diminutive executive resumed. Your attempt to overthrow Heaven shows a failure to set achievable goals. And when the Buddha became involved, you should have given up, quite frankly. Those Eastern deities had difficulty repelling your strong but poorly organized attack. The Buddha, though, he transcends the illusion of material existence, and a physical attack was unlikely to defeat him, don’t you think? Well, of course you have first hand experience of it. And you’ve had plenty of time to think about it, haven’t you?"

"The Buddha tricked me!" blustered the monkey demon. "If he stood and fought me, I’d have given him a beating he wouldn’t have forgotten in a hurry."

The Single Tiny Manager sighed. "You still have a poor idea of risk management, then" he said. "But don’t let me spend all my time on negatives. Your achievement of immortality was a true example of focused project management. And for a self made monkey demon to give the Jade Emperor a run for his money, well, that shows real management potential. I have confidence that, if you learn a few simple rules of management, you can achieve great things. That’s why I took on your case, you know."

The Great Sage Equalling Heaven looked at the small person before him in a new light. Maybe he wasn’t such a bad judge of character after all. "So, you’re going to set me free?" he asked.

"That’s what you want, I suppose. We’ll discuss your goals next time, you might like to prepare a list. It doesn’t have to be too long. Ideally we will be able to go through it in one minute. That’s it for now. I won’t take up any more of your valuable time."

"You mean you’re going to leave me here?"

"I think you have enough to do now. Be ready to discuss your goals for when I get back. If you had a telephone, you could call me any time except for Wednesday morning, because I’m never busy. Unfortunately you haven’t been kept up to date with advances in technology, have you? I’ll speak to the Jade Emperor and see what I can get for you. Well, good bye!"

And so the Single Tiny Manager left, and left the monkey demon to the rain, the heat, the misery of imprisonment, and the first task of a new management career.

Aperiodic keybards
There’s a general assumption with keyboard and scale design that you choose a set of pitches, and repeat them every octave. When I was playing with hobbits, before I got the octave equivalence working, I found an octave-specific set of pitches came out, most of them around the middle. This makes a lot of sense. Put all the intricate intervals in the peak sensitivity range and extend the core scale to the extremes.

Short octaves are an old idea. I don’t think octave specifity has been embraced in 2-D keyboards yet, though. So I’ve had some thoughts about it.

Let’s start with just intonation. You can choose a 1/1, and take every pitch with an interval within a Tenney limit relative to it. That is, every ratio m/n where m*n is below a given cutoff.

The human hearing range is around 1000:1 (16Hz to 16Khz). Call it 1024:1 (10 octaves) because that makes the arithmetic easier. The extremes will be 1/32 and 32/1 relative to a 1/1 of around 512 Hz (treble clef). This gives a Tenney limit of 32. That’s not very big. It’s roughly 5-limit within the octave. 5/4 and 6/5 get in, but 7/6 and 8/5 are out.

A Farey limit gives more variety in the middle. You take every m:n where both m and n are no greater than 32. This gives


as the top octave. In the middle, you get the full 31-limit. Maybe that’s too much. Drop it to 8 octaves (same as a piano) and it becomes the 16-limit. Top octave:


First octave up:

1/1 16/15 15/14 14/13 13/12 12/11 11/10 10/9 9/8 8/7 15/13 7/6 13/11 6/5 11/9 16/13 5/4 14/11 9/7 13/10 4/3 15/11 11/8 7/5 10/7 13/9 16/11 3/2 14/9 11/7 8/5 13/8 5/3 12/7 7/4 16/9 9/5 11/6 13/7 15/8 2/1

I count 40 pitches compared to 8 at the top. There’s a noticeable bulge in the middle.

Tenney-Euclidian cutoffs are interesting. You can calculate it as the square of each part of a sum of products of prime logs. So, the complexity of 32:1 is simply (5*log(2))**2 or 25*log(2)**2 or 25 square octaves. 31:1 is log(31)**2 or [log(31)/log(2)]**2 = 24.5 square octaves. 35:1, however, is log(5)**2 + log(7)**2 which comes out as 13.3 square octaves. So a cutoff that excluded 35:1 would also remove everything between it and 30:1, but still let 60:1 and 120:1 through.

The Euclidean behavior looks bizarre, but it has a rationale. What it’s doing is favoring ratios with the maximal number of distinct prime factors. These are more likely to form simple intervals with other pitches in the system than ratios of one or two primes. Prime powers like 16 are unduly punished, however.

It happens that the metrics for the RMS over a Tenney limit give more weight to simple primes than Tenney-Euclidean weighting, and so do a more sensible job of penalizing high primes -- doubly because they’re large and are less likely to occur with lots of other primes.

The best Euclidean metrics or inner products might be those for the RMS error over a Farey limit. They’ll favour composites, and small intervals, and small primes. An inner product on JI can be applied to tempered intervals according to Gene Smith’s interval complexity.

Say G is the metric for JI and [M> is the unweighted mapping. The inverse of <M|G|M> (with <M] as the transpose of [M>) is the metric for interval complexity in the temperament class defined by [M>.

All these metrics are dualistic in that they consider otonalities and utonalities equally. In practice, it might be better to favor otonalities. Then, for meantone, flats would tend to be at the bottom of the keyboard and sharps at the top. I’m not sure how to systematize this, though.

Note: the pseudoinverse of [M> might be Inv(<M|M>)<M]. Then [M>+[M> = Inv(<M|M>)<M|M> = and [M> [M>+ is [M>Inv(<M|M>)<M]. This is a metric for interval complexity in JI intervals as the [M> and <M] transform to the temperament. The thing is, replace [M> with the weighted mapping W|M> and you get a metric of W|M>Inv(<M|WW|M>)<M|W. This is the equivalent to the interval complexity metric above where G=WW. But it applies to weighted JI intervals. I'm not sure if Gene defined it like that. It looks like the straight inverse definition is simpler than the pseudoinverse one when you take account of the weighting.

Bytebeat with feedback
I've got the bytebeat bug!

The standard method is to use an expression and drive it with a ramp, so that losing the upper bits gives oscillation. I decided to use the inaudible bits to add some feedback to stop the repetition. This tends not to give an infinitely changing signal, but it does make the period longer. Here's an example, where the expression's simplified from the example at

 * A simpler crowd expression with shorter lines
    int a,b,c;
    a = t*2;
    b = t>>7;
    c = a+b&t>>7;
    return a^c;

 * Feedback timebase
    int i,x;
    for(i=0;;i++) {
        x = company(i);
        i += (x>>10)&7;

You can put any bytebeat expression in the called function. There are two new parameters: the amount of shift and the mask. An &1 is the least destructive way of adding variation to a piece you like.

For even more variety, have the shift keep changing:
 * A simpler crowd expression with shorter lines
    int a,b,c;
    a = t*2;
    b = t>>7;
    c = a+b&t>>7;
    return a^c;

 * Feedback timebase
    unsigned i,x;
    for(i=0;;i++) {
        x = company(i);
        i += (x>>(i>>16))&5;

It can still get stuck for a bit but it gets kicked out of cycles. Travel down this path and you'll end up with one bytebeat expression feeding into another.

Ngram debugging
Interesting search here. Shows, among other things, that Google’s Chinese(simplified) corpus doesn’t only contain simplified Chinese, and it clearly isn’t picking up on phrases that it should.


Log in