Brad Lucas

A blog mostly about programming

Learning Ring Next Steps

May 22, 2018

Previously, I wrote about Clojure and Ring in an introductory post where a small debugging application called Echo was developed. If you haven't looked at that post and are looking for an introduction to Ring I suggest you do and then come back here.

For this post, I've created another sample application called ring-next which contains routines to demonstrate a number of concepts in Ring. These are:

Continue reading →

Learning Ring And Building Echo

May 18, 2018

When you come to Clojure and want to build a web app you'll discover Ring almost immediately. Even if you use another library you are likely to find Ring in use.

What is Ring?

As stated in the Ring repository, it is a library that abstracts the details of HTTP into a simple API. It does this by turning HTTP requests into Clojure maps which can be inspected and modified by a handler which returns an HTTP response. The handlers are Clojure functions that you create. You are also responsible for creating the response. Ring connects your handler with the underlying web server and is responsible for taking the requests and calling your handler with the request map.

If you've had experience with Java Servlets you'll notice a pattern here but will quickly see how much simpler this is here.

Continue reading →

Unzip File If Necessary

May 17, 2018

Ran into a situation where an external vendor started sending csv files gzipped. The trouble was they started zipping only larger files. Since the system that ingested the files would break on a gz file I needed a routine to unzip the gz files and leave the non-zipped files alone.

    def unzip_if_necessary(self, filename):
        print "unzip_if_necessary: " + filename
        f = open(filename)

        # Read magic number (the first 2 bytes) and rewind.                                                                                                                                                                               
        magic_number =

        if magic_number == '\x1f\x8b':
            print "gzip file"
            data = ''
            # with  gzip.GzipFile(fileobj=f) as f:                                                                                                                                                                                        
            with, 'rb') as f:
                data =
            print "Writing to " + filename
            with open(filename, "w") as f:
            print "csv file"


Continue reading →

Download All Files From Url

January 12, 2018

Use wget to download a web page and all associated files.

$ wget -r -np -k

If you don't have wget and you are using a Mac use brew.

$ brew install wget

Continue reading →

Advent Of Code

December 5, 2017

After taking a month off from writing blog posts I've just found something interesting to point out. The other day I found this "Advent Calendar" idea for programmers. Each day you solve a puzzle or two to unlock the day. With twenty five days to complete it looks like an interesting activity for the month of December.

If you are curious a bunch of Clojurians are listing their solutions repos here:

Continue reading →

Gpg Signing Failed Inappropriate Ioctl For Device

November 5, 2017


gpg: signing failed: Inappropriate ioctl for device

To fix:

$ GPG_TTY=$(tty)
$ export GPG_TTY

Continue reading →