Building a Clojure project on Travis CI that’s in a sub-directory of the repository

This wasn’t entirely obvious to me, so here goes.

First some very quick background. Travis CI is a wonderful, hosted continuous integration service, that is free and very easy to use for open source projects on Github.

I have a Clojure project on github that I want to build, but it’s in a sub-directory of its parent repository. It took me a few attempts to have Travis handle this correctly, but in the end it was simply a matter of doing the following in the .travis.yml file:


before_install: cd clojurenote

view raw

gistfile1.yml

hosted with ❤ by GitHub

What doesn’t work (and which I tried before realizing what’s going on) is using before_script, or putting the ‘cd‘ call within a script line itself. This doesn’t work because Travis runs ‘lein deps’ after before_install, but before before_script (and therefore before script) and thus fails if you haven’t already changed to the directory where your project.clj is by this point.

My full .travis.yml at time of writing is as follows:


language: clojure
lein: lein2
before_install: cd clojurenote
script: lein2 expectations
jdk:
– openjdk7
– oraclejdk7

view raw

gistfile1.yml

hosted with ❤ by GitHub

Clojurenote – A Clojure library to access the Evernote API

Recently I’ve been having a lot of fun using the Evernote API from Clojure, especially as part of developing Orinoco. I’ve now open-sourced my lowest-level Evernote code as Clojurenote.

Evernote already provides a thorough Java SDK and Clojurenote doesn’t aim to completely replace it. Clojurenote does, however, implement the following:

  • OAuth authentication (using the fantastic Scribe Java library)
  • Basic read/write capabilities, using an OAuth access token, or developer token
  • ENML to HTML translation (ENML is the XHTML derivative that is used for the content of Evernote notes)

You’ll still need to be happy mucking in with the Java SDK but Clojurenote will make a few things cleaner and easier for you in your Evernote-accessing Clojure code.

Why Evernote?

I’ve been using Evernote a lot recently. In fact, I’ve gone a little bit overboard. Being an every-day human user wasn’t enough so I started writing applications that use Evernote. And I went to their conference. And I’m even in the analysis stages of starting a business based on Evernote. But why? Here I give a few reasons that hopefully give some method to my Evernote madness.

Firstly a quick introduction for those who don’t know what Evernote is. It’s a tool for easily capturing pretty much any thought or content that can be put into an electronic document, tracking it however you like, from any device, on-line or off-line, with the ability to share with other people and applications.

Urrk, that’s not as quick as I’d like. I wanted to the description smaller but it’s precisely the combination of all these things that make Evernote so compelling to me. I’ll try to break them down a little.

I use Evernote for storing (at least) to-do items, reminders, emails I want to read later, web pages I want to save, travel plans, project ideas, a journal, restaurants I might want to go to with my wife, workout history, and a whole lot more. Evernote themselves like to use the phrase ‘outsource your memory’ – that describes my usage well.

One of the things I particularly like about Evernote is that it lets you organize things how you want, not how it wants. Evernote gives you a blank slate, a few cataloguing criteria, and then gets out of the way. The genius is that there’s enough to be powerful, but also little enough for you to organize, and change your organization process, as you see fit. This feature of Evernote is actually what causes a lot of people to struggle with it at first (and it took me a while to get used to), but frequent Evernote users are often of the type that once they get momentum then they find more opportunities to increase the efficiency of their lives through even further usage of Evernote.

I use Evernote wherever I am. I primarily use the Mac Desktop app, but I also use the iPhone / iPad app, the web clipper, the email bridge, etc. The off-line capability of the iPhone app is great – I can check my important to-dos from the subway and then read some articles I’ve saved.

Sharing is useful too. As a premium user I setup notebooks with my wife that we can both edit. We typically use this for restaurants and bars that we want to try out, but shopping lists are another common usage for other people. And that’s before you even start considering the business usages of shared notebooks.

Also of huge value is Evernote’s API. It means than many apps beyond Evernote’s own can integrate with my Evernote data. I’m a big fan of using Drafts on the iPhone to create content on the go. My own app, Orinoco, lets me see my journal in a more natural way and lets me capture my tweets, foursquare checkins, etc., automatically into Evernote.

Finally, I like Evernote the company and trust them with my data. Evernote rejects all indirect revenue – they only make money from premium and business subscriptions. This means they don’t have ads, and don’t do data mining on my content. They also want to be around a long time and not just ‘exit’ at the earliest possible moment.

These are all just reasons why I value Evernote as a user. There are other reasons I value Evernote as a developer and I’ll write those up another time.

(cross-posted at http://mikeroberts.postach.io/why-evernote)

Connecting to a remote PostgreSQL Database on Heroku from Clojure

Sometimes it’s useful to be able to debug a local application running against a remote production (or staging) database. The app I’m currently working on is a Clojure app, running on Heroku, using PostgreSQL as a database. It wasn’t entirely obvious (to me) how to do this, but here’s how I did it in the end.

  1. First, this assumes you’re using at least [org.clojure/java.jdbc “0.2.3”] . I thought at first it required later, but 0.2.3 seems to work.
  2. Get your regular Heroku DB URL. This will be of the form ‘postgres://[user]:[password]@[host]:[port]/[database]’
  3. Form a new DB URL as follows (substituting in the tokens from above) : ‘jdbc:postgresql://[host]:[port]/[database]?user=[user]&password=[password]&ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory’.
  4. Then for your db connection, use the map ‘{:connection-uri “[new-url]”}’

If I was going to do this frequently it would be easy to create a function to map the original Heroku URL to this remote debugging URL. Assuming you’ve parsed out the server, port, etc., the following gist will work as a basis for this.


(defn remote-heroku-db-spec [host port database username password]
{:connection-uri (str "jdbc:postgresql://" host ":" port "/" database "?user=" username "&password=" password
"&ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory")})

view raw

gistfile1.clj

hosted with ❤ by GitHub