Latest articles

Those who rely on Moore's Law...

Those who rely on Moore's Law inevitably ignore and fall prey to Wirth's Law.

(See also Jevons paradox.)

Read more


gen-package-version v0.9.0: New tool: Auto-generate version/timestamp info

Automatically generate a D module with version and timestamp information (detected from git) every time your program or library is built.

Even better, all your in-between builds will automatically have their own git-generated version number, including the git commit hash (for example: v1.2.0-1-g78f5cf9). So there's never any confusion as to which "version" of v1.2.0 you're running!

The gen-package-version Homepage

Full usage and instructions are at the link above, but here's a brief primer for those using it with dub:

To use:

Add this to your project's dub.json file:

"dependencies": { "gen-package-version": "~>0.9.0" }, "preGenerateCommands": ["dub run gen-package-version -- package.name --src=path/to/src"]

Now, when you build your project with dub, it'll automatically download, install and run gen-package-version, which will generate the file path/to/src/package/name/packageVersion.d

Then just import that and use it:

module package.name.main; import std.stdio; import package.name.packageVersion; void main() { writeln("My Cool Program ", packageVersion); writeln("Built on ", packageTimestamp); }

Read more


Scriptlike v0.8.0

A bunch of new updates to Scriptlike: A library to aid in writing script-like programs in D.

Scriptlike links: [Home] [Dub] [Full changelog]

Highlights (more info at full changelog):

  • Change: Minimum officially supported DMD increased from v2.064.2 to v2.066.0.
  • Change: API reference now built using ddox and uses much improved styling (actually uses a stylesheet now).
  • Change: Misc changes to reduce symbol conflict issues with std.file/std.path.
  • Change: Eliminate remnants of the "planned but never enabled" wstring/dstring versions of Path/Ext/Args. There turned out not to be much need for them.
  • Enhancement: Add module scriptlike.only to import all of scriptlike, but omit the helper Phobos imports in scriptlike.std.
  • Enhancement: fail now accepts an arbitrary list of args
  • Enhancement: Added failEnforce.
  • Enhancement: Added runCollect and tryRunCollect, to capture a command's output instead of displaying it.
  • Enhancement: Added pause to pause and prompt the user to press Enter.
  • Enhancement: Added Path-based wrappers for std.file's getcwd, thisExePath and tempDir.
  • Fixed: No longer uses the deprecated std.process.system().

Read more


Ahh, Irony

You'd think a sudden stop to the flood of spam in the comment moderation queue would be a nice relief. Instead, I find it makes me paranoid that "The comment system didn't just suddenly break, did it?!?".

Go figure.

Oh well, I'm sure the spam traffic will pick back up again!

Read more


Bash: Multiline Eval

Maybe this is obvious to all the linux and bash-fu experts out there, but I just discovered it, thought it was pretty cool and worth sharing for anyone else who isn't quite a bash expert.

Background

Ok, so bash has a feature which takes the output of a command and runs it (no, this isn't the part that's new to me ;), I'll get to that part in a bit). Let's use the print working directory command as an example:

$ cd ~ $ pwd /home/my-user-name

Now let's get a command that just simply outputs the command we want:

$ echo pwd pwd

And then bash's basic feature to execute that result (two different ways to do it):

$ `echo pwd` /home/my-user-name $ eval $(echo pwd) /home/my-user-name

Alright, neat, but basic stuff.

The Problem

Unfortunately, that trick only works when you're evaluating a single line. Try to evaluate multiple lines and it won't work. (The newlines get converted to spaces and it all gets interpreted as one command.)

To demonstrate, let's make a basic script:

$ touch display-a-command $ my-favorite-editor display-a-command

Copy-paste, save and exit:

#!/bin/bash echo pwd echo pwd

Then:

$ chmod +x display-a-command $ ./display-a-command pwd pwd

Ok. So we have a basic command that outputs two lines of commands. Try to evaluate (You get the same result using either eval method):

$ `./display-a-command` /home/my-user-name

Fucknuggets. It only ran "pwd" once. The two lines got mashed together into one line and bash really executed the single command pwd pwd. The second "pwd" was ignored as an unused argument to the first "pwd". That's not at all what we wanted.

The Cool Part

Turns out there's an easy way to do a multi-line eval:

$ eval "`./display-a-command`" /home/my-user-name /home/my-user-name

Yup. That's it. The internal `./display-a-command` evaluates to our two-line command, and the double-quotes ensure the newline gets preserved when passed to eval.

It even works when display-a-command's output includes backticks and quotes:

$ cat display-a-command2 #!/bin/bash echo \`echo pwd\` echo eval \"pwd\" $ chmod +x display-a-command2 $ ./display-a-command2 `echo pwd` eval "pwd" $ eval "`./display-a-command2`" /home/my-user-name /home/my-user-name

Nice. Cool, huh? At least I think it is, anyway.

Read more


Tagged Scriptlike release: v0.7.0

Scriptlike is a utility library to aid in writing script-like programs in D (available through DUB):

Two things in this release:

  • Easy input-prompting module "scriptlike.interact", by Jesse Phillips. This has actually been in master for quite some time, but now it's part of a tagged release.
  • Fixed: The unittests failed to compile on DMD 2.067.0

Early heads-up warning: While scriptlike currently supports DMDs as early as 2.064.2, I will likely be increasing the minimum supported DMD up to 2.066.0 between now and the next release, due to increasing reliance on the newer parts of std.process (which prior to 2.066.0 had "paths with spaces" problems on Windows, which I was previously able to work around using the outdated system() function).

Read more