jlm-blog
~jlm

11-Mar-2018

DST is for losers, not Floridians

Filed under: politics, time — jlm @ 14:54

Today most of the United States switches from Standard Time to Daylight Savings Time. But it looks like in the fall Florida won’t be switching back to Standard Time like the rest of us. And good on them! As I’ve said before, staying with this tradition of changing our clocks twice a year is ridiculous in this age.

20-Nov-2017

Winning makes you Western because “Western” is the winners

Filed under: news — jlm @ 13:48

CNN spends some digital ink talking about a world-wide survey of countries’ reputations in this article here. It’s an interesting read, even though (or partly because?) it’s a short article.

But look at the final three sentences:

Canada and Japan tied for fourth place. The rest of the Top 10 is Italy at No. 7, Switzerland at No. 8, Australia at No. 9 and Sweden at No. 10. No non-Western countries managed to crack the Top 10.

“No non-Western countries”, eh? Australia is #9 on the list, and they’re in the eastern hemisphere. But Australia, while geographically closer to Asia than Europe, is culturally closer to Europe than Asia, so maybe that’s what they mean. But look at who’s #4 on the list: Japan. The Land of the Rising Sun is as east as Eastern gets. What they mean is that no developing nations are on the list, only those with advanced economies. But nobody wants to be part of an undeveloped economy, so of course the list is going to be exclusively advanced economies.

The “non-Western country” observation is either simply wrong (geographically or culturally “Western”) or meaningless (“Western” as a synonym for advanced economy). It’s not that Asia is undeveloped, it’s that undeveloped economies are undeveloped. The non-Western country quip is meaningless except to the extent that Western ≡ advanced is a racist presentation of the banal equivalence advanced ≡ advanced.

5-Oct-2017

Tutorial for building .so files

Filed under: linux, programming — jlm @ 18:34

Exactly how one goes about building .so files* isn’t widely understood, and the documentation on it is overcomplicated IMHO. So, I figure the web needs a tutorial demonstrating how to build an extremely simple .so file. Et voilà, here’s a step by step guide for building a .so file on Linux or a similarly flavored Unix using a GNU-compatible toolchain.

We’re going to make two .o files, “call_me.o” and “die.o”, and combine them into a single “call_me_and_die” shared library. Making a library is very much like making an executable, just with some tweaks to the build commands and some extra steps at the end. To make our “call_me_and_die” library, we start the way we would with a “call_me_and_die” executable: writing a .h file for the common function signatures. File so_tut.h:

extern void call_me(void);
extern void die_die_die(void);

(more…)

11-Sep-2017

EBUSY: Another decade, and still sucking

Filed under: general, linux, programming — jlm @ 12:40

Today’s xkcd riffs a common frustration about busy files: programs that can’t do their intended operations on them rarely (if ever) specify the file that’s busy or tell the user which programs are using the file — and without that knowledge, the user can’t fix the problem.

There are tools that can help you discover those things, as I describe using ten years ago, but I’d already been running into EBUSY problems for ten years by then, and the old guard before me for another ten years beyond that. Why haven’t things improved?

Sometimes file_operation(filename) fails — hey, this happens, busy files are a thing, ain’t nothing your program can do about that. But report to the user that file_operation on filename failed for reason strerror(errno)! Not reporting the filename is just sloppy programming.

It’s not like the tools have gotten any better. What, you think it’s acceptable to make the user trace your program, looking through a haystack of every system call to find the needle which is the program’s critical failure? Is that work you’re putting on the user’s shoulders less than sticking the filename in the error message? This has sucked for two generations now. Please help making it suck less.

13-May-2017

Be careful what you wish for…

Filed under: politics — jlm @ 18:12

… because you might get it.

Look at things right now: James Comey deserved to be fired. Specifically, he deserved to be fired because of his interference in the election. Wish granted! He’s been sacked for (so writes the Sacker in Chief) that reason in particular. But now, seemingly nearly everybody (yours truly included) thinks the act of terminating Comey was wrong. We live in interesting times. May you not come to the attention of important people.

4-Mar-2017

twitcode #4: reverse diff — using the right tool for the job

Filed under: programming — jlm @ 20:29

Mercurial’s  hg diff  command supports a  --reverse  option which shows the regular diff output except it reverses the sense of the comparison — i.e., it goes from the “destination” to the “source” (git diff  supports this action too, but as the flag “-R”). Most of the time you want the ordinary “forward” sense, but occasionally the reverse sense comes in handy, and that’s why that option’s there. On rare occasion, I’ll even want to do this to files not under version control, but the regular system diff doesn’t support this feature.

So, after hitting this deficiency again recently, I decided to write up my own reverse-diff command which would swap its last two arguments and call diff. I started with the shell, as dealing with command arguments and calling programs is its forte. But it turned out to be surprisingly difficult to do stuff like copy the argument list or mess around with the end and near-end of the argument list, which I thought would be dead-simple operations. After futzing around with shell variables and parameters and the various options for variable/parameter expansion for something like 25 minutes, I came to my senses and did it in something like two minutes using C, where nothing’s going to interpret any kind of data as anything unless you explicitly request it to, and array manipulation is built in with clean syntax. All I had to do was swap argv[argc-1] and argv[argc-2] then execvp("diff", argv), easy peasy.

And if I golf argc and argv into c and v, then it fits in 130 chars [source]:
#include <unistd.h>
int main(int c, char**v) {
 if (c>2) { char*t=v[c-2]; v[c-2]=v[c-1]; v[c-1]=t; }
 return execvp("diff", v);
}

I could probably omit the check for ≥2 arguments, as the system diff doesn’t support the convention that a missing file argument means to use stdin (instead, it treats a filename of - (single hyphen) as representing stdin), but perhaps it’ll be used by somebody who’s installed an enhanced diff program.

I’m also amused that each of my “twitcodes” has been in a different language: shell, perl, python, and now C.

29-Dec-2016

A puzzle about C’s stdio

Filed under: programming — jlm @ 18:06

I found the C puzzles webpage by Gowri Kumar to be a very interesting collection of oddities of the C language and some of its basic libraries. If you work with C for fun or profit, I encourage you to go and give them a try. I found very few of them to produce behavior I hadn’t expected, which could be a symptom of overfamiliarity with C. I did find a few surprises though, which I felt warranted further investigation. (more…)

9-Nov-2016

I do not understand my own country

Filed under: politics — jlm @ 07:57

Donald Trump has just won the election. I am more baffled by this election result than I’ve ever been, by far. I might disagree with the people who voted for Reagan or W., but I understood plausible rationales for those decisions. I don’t in this case. I spent my entire childhood in Oregon (HRC 51½%) and my entire adult life in California (HRC 61½%), and I don’t even understand how these two states didn’t end up in Hillary Clinton’s camp by much larger margins. I must be in a bubble inside a bubble, and I don’t know how to communicate with those outside.

2-Aug-2016

Solving the quartic using “obvious” steps

Filed under: math — jlm @ 21:40

Looking over the derivations of solutions to quartics (fourth-degree polynomials), I was a little disturbed at how, except for René Descartes’s, the derivations all have steps where “magic” occurs, by which I mean that a step does something mathematically valid but very unintuitive, which just happens to make stuff later on work out just right.

So I wondered whether one could take an approach like Lodovico Ferrari’s, but do it without his “magic”. The basic idea to Ferrari’s approach is to convert the depressed* quartic equation f(x) = x⁴ + αx² + βx + γ = 0 into (x²+p)² = m(x+q)², because taking the square root of both sides produces the quadratic equation x²+p = ±(x+q)√m.

(x²+p)² = m(x+q)² expands into x⁴ + 2px² + p² = m(x²+2xq+q²), which is x⁴ + (2p−m)x² − 2mqx + p² − mq² = 0. We can name that polynomial g(x). From above, we know that the roots of g are the same as the roots of x² ± (x+q)√m + p, and the quadratic formula easily gives us those roots in terms of m, p, & q.

g ≡ f iff α = 2p−m and β = −2mq and γ = p²−mq². Thus our task is to get values for p, q, & m which satisfy these three equations.
m = −β/2q and p = ½(α+m), so p = ½(α − β/2q).
γ = p² − q²m = p² + q²β/2q = p² + ½βq = [½(α − β/2q)]² + ½βq = ¼[α² − αβ/q + β ²/4q² + 2βq].
4γq² = α²q² − αβq + ¼β ² + 2βq³.
2βq³ + (α² − 4γ)q² − αβq + ¼β ² = 0, which is just a cubic in q, which is something we’re presumed to know how to solve. Using q we get m and p from m=−β/2q and p=½(α+m).

With these values of m, p, & q, f ≡ g. So the roots of g(x) from above are the roots of f(x), et voilà, we’re done, no magic needed.

 

*A depressed nth degree polynomial is one in which the (n−1)th term has a coefficient of zero, so a depressed quartic is a quartic equation with no cubic term. For any nth degree polynomial F(x) = xn + an−1xn−1 + an−2xn−2 + …, there is a depressed nth degree polynomial f(x) = xn + bn−2xn−2 + … such that F(x+s) = f(x), because the coefficient of the (n−1)th term of F(x+s) is ns+an−1, which can always be made zero by selecting s to be –an−1/n.

6-Jul-2016

Would the HMS Boaty McBoatface have been an EU vessel?

Filed under: econ, politics — jlm @ 19:45

Not long before the referendum on whether Britain should leave the EU, there was a plebiscite about what to name its newest oceanographic research vessel. To the amusement of the rest of the world, the winning name was ‘Boaty McBoatface’. However, that election result was not enacted, whereas the UK government is treating the Brexit election result as binding. The rest of the world, at least as judged by its various stock markets, was not amused.

On the news there’s been a lot of talk about the so-called ‘regrexit’ theory that many Britons who voted ‘Leave’ were casting ‘protest votes’: expecting that ‘Remain’ would win by a significant margin (despite the polls), they felt their votes wouldn’t affect the election’s result, so even though they wanted ‘Remain’ to win, they voted ‘Leave’ as a signal of their dissatisfaction of the status quo. So, what if the UK government had enacted the earlier vote? If the British had had to put up with having their premier oceanographic ship being named Boaty McBoatface to the derision of the rest of the oceanographic community, that would have been a lesson that votes do matter. If the regrexit theory is correct, then the English are learning that lesson with the very consequential Brexit vote, and it’d have been much better if they’d have learned it from the vote about the boat.

However, it’s worth considering the possibility that the regrexit theory is wrong and the English aren’t as dumb as they look. Sure, the finance sector is going to see a lot of its jobs move to Paris, Dublin, Brussels, etc., but most Britons don’t work in finance, and I’m betting that majority thought they would like the consequences of a weaker pound: British goods now appear cheaper to the rest of the world, so British manufacturing will see a boost, and that’s enough reason to vote ‘aye’ on the Exit. This argument doesn’t get much traction from economists, but those who believe it are sincere in their ‘Leave’ votes — even if you can easily counter it, it’s by no means a frivolous argument.

OK, the economic ramifications of the Brexit can (and surely will) fill a book, but what about the political ramifications? I find it stunning that one of the most powerful positions in the world, the prime minister of the UK, is now one which seemingly no-one wants! David Cameron has announced that he’s going to resign. Boris Johnson, Brexit’s most prominent cheerleader and Cameron’s expected successor, has said he’s not going to run. I expected him to be waltzing his way to 10 Downing St. on rhetoric of how Brexit was the first step to Britain’s upcoming new golden age. Nigel Farage, head of the UKIP, who has just led that party to the achievement of its primary raison d’etre (huge success!), is resigning his post. Regrexit appears to strike these politicians hard. Why aren’t Johnson and Farage, the ostensible winners here, riding their chariot in a victory lap? Instead they’re slinking off as if they lost. I do not understand this.

Powered by WordPress