jlm-blog
~jlm

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.

Powered by WordPress