Handy Tools for the Bourne Again Shell

If you’re a Unix geek, you’ve probably used bash, the Bourne-Again Shell. If you’ve been around a while, you’ve probably spent a lot of time customizing bash.

Back when I worked for Yahoo!, my friend Bryan gave me a great directory stack for bash. I loved it, so I rewrote it and have been hacking on it and using it ever since. Observe.

[user@host:~]$ cd /tmp
[user@host:/tmp]$ cd /var/log
[user@host:/var/log]$ dl
1   ~
2   /tmp
3 * /var/log
[user@host:/var/log]$ go 1
1   /home/user
[user@host:~]$ go log
3   /var/log

In addition to the handy new go command, it also includes b and f for moving backwards and forwards on the stack. It was inspired by pushd and popd, but it’s so much more.

If you’d like to check it out, take a look at my bashtools repository on GitHub or just download version 1.0. I don’t change it very often, but I’m thinking of hammering out a long-standing bug in the directory stack code.

N.B. If you use all of my scripts, you’ll get some great prompts for your xterms. You’re welcome!

Not this kind of shell.
Not this kind of shell.

Website: Bruno San Rafael’s Home for Former Trapeze

Back in 2012, I had the pleasure of working with my good friend Joel Barker on his amazing project, Bruno San Rafael’s Home for Former Trapeze. This project is a collaboration between Joel, a bunch of musicians, a photographer, and a web developer (me!). My contribution was probably the smallest of the bunch, but it was a lot of fun.

Please check out the website by clicking on the screenshot below. If you use “View Source” in your browser, you can see every line of code I used to finish the site. It’s one simple, medium-length monolithic HTML file with JavaScript and CSS thrown in.

Bruno San RafaelI now work with Joel regularly at Word Lions, where I write and do a little more website development.


Prime Number Library for OCaml

A couple of weeks ago, I cleaned up my prime number library for OCaml. This library has a number of primality-testing methods in it, but my favorite is the Miller-Rabin primality test. It’s fast and rather accurate.

If you’d like to take a look at the library, please check out the camlprime GitHub page. The library is pretty easy to use. If you download and compile the library, you’ll end up with a toplevel that you can play with.

The test.ml file has some examples of how to use the primality tests. However, my favorite thing about this library is that it includes a lazy list implementation of prime numbers. The following example shows how to set up a lazy list of prime numbers proved using the MR algorithm in the toplevel.

# open Num ;;
# let prime_list = Prime.make (Prime.miller_rabin 500) (num_of_int 500) ;;
val prime_list : Num.num LazyList.t = LazyList.Node (Int 503, <lazy>)
# Prime.nth prime_list 500 ;;
- : Num.num = Int 4363

The library is pretty fast, even for really large numbers. I’ve tested it on 300-digit prime numbers, and I’m sure it will scale to sizes much larger than that.

Any thoughts or improvements? Let me know in the comments.