find: files only with scm directory pruning

The version of find I’m discussing here is
find (GNU findutils) 4.7.0-git
I use this pattern frequently—
$ find . <conditions> |xargs grep <pattern>
to find files containing, say, a regular expression.  If the search tree contains mercurial or git directories, I usually want to exclude their contents from the search.

Continue reading “find: files only with scm directory pruning”

tikadiff: graphical diff for text from “binary” files

Code

The code is from the Downloads area of my Atlassian Bitbucket repository; see the README online.

Version Control Systems (VCSs)

VCSs like mercurial, git and bazaar (to mention only a few) are great for keeping track of changes to source files, but their utility doesn’t stop there.  If you’re working on documents in applications like Word, OpenOffice or LibreOffice, especially when you are asking others to review those documents, a VCS program can save you a lot of anguish.

However, people who work not with source code, but with research papers, academic assignments and the like, are not inclined to make themselves familiar with the tools that geeks have grown used to.  Considering how long it took for software developers to embrace those tools, it’s hardly surprising. Continue reading “tikadiff: graphical diff for text from “binary” files”

Help for digest checking

Updated 2018-02-14

It’s pretty important to check the digests of software you download.  When a downloaded file is accompanied by a signature file, for example a gnupg .asc file, you can verify the signature with various tools.  Often though, a download site will include the MD5 or SHA1 digest hash of the file, which allows a quick check on the file’s integrity.  OS X has an /sbin/md5 command, and includes the openssl distribution.  Within openssl, the digest subcommand allows for the generation of digests for an array of digest algorithms, including MD5 and SHA1.  So it’s simple enough to generate the appropriate digest for that file you just downloaded.

Comparing them is a bit tedious, though.  If you’re like me, you skim across the two digests – the one you generated and the one that the authors published – and look for eye-catching patterns near the beginning, middle and end.  That works pretty well in practice, but its hardly rigorous.

Continue reading “Help for digest checking”

Monad; that’s a wrap!

Just like everybody else who starts to look at monads, I found it was like coming to the face of a sheer cliff.  Let me qualify that: just like every other programmer who is not a mathematician (and that’s most of us).  I am looking at monads in the context of clojure, so code snippets will generally be written in clojure-like syntax.

I have found these resources the most helpful:

Continue reading “Monad; that’s a wrap!”

zargrep: grep files in a zip archive

How do you search for strings within a zip archive?

I’m tinkering with EPUB3 files, and I wanted to be able to find certain strings within .epub files, so I had a look around, and I immediately found zgrep and family. The trouble was that zgrep assumes a single zipped file, not an archive.

So, without further ado, I wrote the following script, which I called, naturally, zipgrep. It uses grep and unzip, which it assumes to be available on the PATH.  Not wanting to have to pick through the argument list, I decided to mark the end of arguments to grep with the traditional ‘‘, after which I could stack up as many zip file names as I liked.

Continue reading “zargrep: grep files in a zip archive”

Setting environment variables in MacOS Big Sur

This method uses launchctl to manage environment variables for programs invoked directly from Finder.  See the launchctl man page, especially the section LEGACY SUBCOMMANDS.  It’s not entirely accurate, but that’s not unusual.  The critical subcommands are getenv, setenv, and unsetenv. The man page indicates that the export subcommand is available; it is not.

Continue reading “Setting environment variables in MacOS Big Sur”

Ant: process elements in a list

I was looking for a way to process a list of items in an ant build file, similar to what you would do in Java with a construct like:

for ( Element element : elements ) {
    // do stuff with element
}

The approach of XSLT, using recursive calls with local variables, looked promising. In the ant-user mailing list, I found a posting on the topic Implementing a loop in ANT with something like what I was looking for. Ben Stringer’s example gave me the critical information—that I could make indirecly recursive calls to antcall. He also used an external file, updated with the buildnumber task, to maintain state through the recursive calls. Bingo!

Continue reading “Ant: process elements in a list”

Ant: edit property values

One of the frustrations of using ant was the difficulty of deriving one property value performing some sort of editing operation on an existing property value. The mapper task does a lot of grunt work for file names, but not for property values as such.

A common requirement is to map a Java package name to a corresponding directory structure. I have a property containing the package name, and I want to create another property with the directories. Here’s one way to do that. Continue reading “Ant: edit property values”

Setting Environment Variables in OS X Lion

If you want to set environment variables in OS X in such a way as to be recognised in applications run from Finder, it is not enough to set the env var in .profile.  You must also ensure that the variables are set in the file ~/.MacOSX/environment.plist. Setting values in that file is most conveniently done using the executable PlistBuddy.

On my system, the command
$ which PlistBuddy
yields
/usr/sbin/PlistBuddy

Continue reading “Setting Environment Variables in OS X Lion”