Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Command Line Tools

Building Command Line Tools

This talk was given to the first cohort of Launch Academy in Boston, MA on June 19, 2013 who at that time had gone through several weeks of training and hands-on experience with web application development since my last visit. This talk was meant to present an alternative approach to tackling problems that do not necessarily need to be solved using the traditional web stack.

Johnny Boursiquot

June 19, 2013
Tweet

More Decks by Johnny Boursiquot

Other Decks in Technology

Transcript

  1. Building Command Line Tools An Example in Applied Unix Philosophy

    for Writing Software Wednesday, June 19, 13
  2. What we’ll talk about A real-world problem Going beyond web

    applications A real-world solution The Unix philosophy Solution code walkthrough Wrap-up & where to go next Q&A Wednesday, June 19, 13
  3. About me Johnny Boursiquot (boar-cee-co) Partner, Technology Director & Software

    Architect at MAARK @jboursiquot | jboursiquot.com Wednesday, June 19, 13
  4. A real-world problem Customer commissions us to build a web

    application. Customer realizes that they need to email a few hundred users, each with custom links to their web app. Traditional email marketing software won’t do (for one reason or another). Customer provides sample data in the form of an Excel document (no surprise there). Wednesday, June 19, 13
  5. A real-world problem Customer provides message that should be sent

    to users. Customer wants a (PDF) report of the recipients that were successfully and unsuccessfully emailed for follow up. Customer says this is a one-time situation (but we know better). Wednesday, June 19, 13
  6. A real-world problem Our requirements: Extract name, email and url

    from Excel doc For each recipient, insert the relevant custom url in the message body Each email must support both rich and plain text alternatives Track successes and failures Generate PDF report of the result Wednesday, June 19, 13
  7. Why Command Line Apps? Precise Usually small Usually quicker to

    build than web apps Usually built with re-use in mind Wednesday, June 19, 13
  8. Back to our real-world problem... We did not want yet

    another custom web app to build and maintain Customer did not want yet another web app to train for and use Wednesday, June 19, 13
  9. Back to our real-world problem... We wanted something relatively small

    and re-usable across multiple customer projects Wednesday, June 19, 13
  10. Write programs that do one thing and do it well.

    Write programs to work together. - Doug McIlroy The Unix Philosophy Wednesday, June 19, 13
  11. Maildis https://github.com/jboursiquot/maildis Met most of the requirements Extract name, email

    and url from Excel doc For each recipient, insert the relevant custom url in the message body Each email must support both rich and plain text alternatives Track successes and failures Still needed PDF report generation Wednesday, June 19, 13
  12. Producing HTML Given our log file has one line for

    each email processed: 2013-01-29 13:05:05 -0500 INFO: Sent: Johnny Boursiquot <[email protected]> The following command yields the desired HTML: sed -e 's/^/- /' ~/.maildis.log > .maildis.md && markup .maildis.md Wednesday, June 19, 13
  13. Sed sed: Stream editor man sed: The sed utility reads

    the specified files, or the standard input if no files are specified, modifying the input as specified by a list of commands. The input is then written to the standard output. Wednesday, June 19, 13
  14. Markup Small gem that converts markdown to HTML markup from

    the Command Line Wednesday, June 19, 13
  15. Combine to Produce PDF sed -e 's/^/- /' ~/.maildis.log >

    .maildis.md && markup .maildis.md && prince .maildis.html - o .maildis.pdf In other words: Use sed to pre-pend each line of log file with a “-” thereby converting it to valid markdown Feed resulting markdown file to markup in order to produce valid HTML Feed resulting HTML into prince to produce PDF Wednesday, June 19, 13
  16. Unix philosophy: http://en.wikipedia.org/wiki/Unix_philosophy Doug McLlroy: http://en.wikipedia.org/wiki/Douglas_McIlroy Maildis: https://github.com/jboursiquot/maildis PrinceXML: http://www.princexml.com/

    MailCatcher: http://mailcatcher.me/ Your Objects, the Unix Way: http://blog.codeclimate.com/blog/2012/11/28/your- objects-the-unix-way/ Wednesday, June 19, 13
  17. Go build some tools of your own. Thanks. @jboursiquot |

    jboursiquot.com Wednesday, June 19, 13