Thoughts on Elegant Computing

Machinae Elegantiam is Russ Harmon’s blog on technology, computing, programming, and anything else computer related he cares to post.

Recent Posts

15 Jun 2014

The MIN Challenge View Comments

It’s surprisingly difficult to make a proper function-like macro.

19 May 2014

String to Number Conversion in C Takes its Toll View Comments

Converting a string to a number in C is no simple affair.

18 May 2012

Designing Robust Build Systems View Comments

A correct build system must be able to solve the problem of traversal-time dependency detection.

13 Dec 2011

Getting Public Information From Latitude View Comments

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.

24 Jun 2011

Determining Mount Status View Comments

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.

01 Oct 2010

Object Oriented C View Comments

So, thanks to blocks, Apple’s new extension to C, you can now do basic object-orientation. Have a look over at GitHub for a short example on how to do it.

05 Jul 2010

Bash Scripters: Stop using subshells to call functions. View Comments

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:

24 May 2010

Reclaimable Userspace Cache Memory View Comments

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.

28 May 2009

Pure Bash Cat View Comments

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.

14 Aug 2008

Negative Indexed Arrays View Comments

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!