Machinae Elegantiam is Russ Harmon’s blog on technology, computing, programming, and anything else computer related he cares to post.
It’s surprisingly difficult to make a proper function-like macro.
Converting a string to a number in C is no simple affair.
A correct build system must be able to solve the problem of traversal-time dependency detection.
Getting public information about a person from Latitude is no simple task. Google has no public API for retrieving non-authenticated information about a person.
I’ve fairly frequently ran into the issue while scripting a mount action of determining if what I want to mount is already mounted. On Linux, you could parse
/proc/mounts, but that’s neither cross-platform, nor is the format of
/proc/mounts guaranteed not to change. The same problem exists with parsing the output of the
mount command, the format of which not only is not guaranteed to remain the same, it in fact varies greatly between platforms.
When writing shell scripts, it’s almost always better to call a function directly rather than using a subshell to call the function. The usual convention that I’ve seen is to echo the return value of the function and capture that output using a subshell. For example:
Caches are used all over your computer and for a huge variety of purposes. From apache to your physical CPU, cache is everywhere. Normally, when you want to cache something in memory, you
malloc(3) a chunk of memory, and store data in that. This works well in the small scale, but when you and 30+ others want to cache some information, that can quickly turn into a large amount of memory taken up by information which can be (easily, or not so easily) regenerated, and there is no way for the operating system to reclaim that memory when it really needs it.
So just to see if I could, I wrote a version of cat using pure bash. Pure bash is a bash script which uses nothing but bash builtins to accomplish it’s goal. To determine if a particular command is a builtin, you can use the command type -t “command” (the command type, is itself a builtin). Some notable commands which are builtins include echo, read, exec, return. Some notable commands which are not builtins include cat and grep. As follows is my implementation of cat in pure bash.
In first describing how ridiculous C and C++ was to my class when I was in my first C++ programming course, I remember him saying that you can even create negative indexed arrays. Now that I am a bit wiser in the ways of C++ and memory management, I actually know how to do it!