Accessing Nested Config with Viper

I'm writing a Go application that glues together a bunch of other things, so it has a whole bunch of basically unrelated config, dumped in a yaml file. I was struggling a little with this non-standard use of Viper but actually, it does everything I needed. And, presumaby, more besides. I thought I would put some examples here to show how to handle this. Continue reading

Remove Accidental Content from Git Commit

When I teach git I try to show loads of good practice about how to inspect what's staged before commit, etc etc. Good practice is good of course, but knowing how to undo a mess you created is better - and mistakes will happen. For example, accidentally including a node_modules directory in your otherwise excellent and useful commit. This post will walk you through how to fix the problem without losing any of your work. Continue reading

Counting Duplicate Commit Messages

When chatting about source control good practice the other day, I got a question about repeated git commit messages. In general, I would always advise that the same commit messages appearing multiple times in a project's history is a definite red flag - and if I'm responsible for that repository I will probably make fun of you for doing it. Continue reading

Managing Environment Variables in PHP

Now I work with more programming languages, I start to miss features from other languages when I come "home" to PHP. One that I hadn't seen in PHP before I saw it in other languages such as NodeJS (I think Ruby had the original implementation) was: a way to easily control setting your environment variables, particularly in development. In NodeJS the dotenv library is great for this; handily in PHP vlucas has already created phpdotenv so we are all set to apply these tricks to PHP applications! Continue reading

Copying CouchDB Data Between Laptops

I'm a regular and happy user of Apache CouchDB, so much so in fact that I'm writing a library to talk to it from PHP. While working on tweaking a feature, I realised that the laptop I use for development didn't have the right/enough data on it to test this particular thing - but that I had a suitable database on my other laptop. Copying data between CouchDB installations is very easy because it has an HTTP API, but usually when I do this at least one endpoint is web-accessible. Enter one of my favourite tools: ngrok.

Ngrok allows me to make the CouchDB on one machine visible to the world (with all the security caveats that this entails! It's a random URL, never leave the tunnel open longer than you need it, etc) with a command like this:

ngrok http 5984

This opens a tunnel to my local machine on port 5984 which is CouchDB's default port. I'm running a local dev instance that doesn't need a username or password which makes this simpler if not exactly secure. I get a gobbledeegook ngrok URL that will allow anyone, anywhere to talk to my CouchDB.

Then I went ahead and on the other laptop, used the web interface to start replication from the sample products database on the local machine over to the one on the ngrok URL.

As soon as it starts, the first laptop shows that there's traffic coming over the ngrok link - and a few minutes later I had the database I wanted and can go ahead and work on this feature.

HTTP Tools Roundup

At a conference a few days ago, I put up a slide with a few of my favourite tools on it. I got some brilliant additional recommendations in return from twitter so I thought I'd collect them all in one place in case anyone is interested - all these tools are excellent for anyone working APIs (so that's everyone!). First, my original slide:

Continue reading

Deploying OpenWhisk Actions With Dependencies

I mostly use OpenWhisk with NodeJS (which is lucky for me, it's the best supported of the languages and default for the documentation examples!) and while there are a bunch of npm modules already installed on OpenWhisk, sometimes there will be others that you also want to include. Alternatively or additionally, you might also want to deploy your package.json since this can specify the entry point if it's not index.js which is the default.

Continue reading

One OpenWhisk Action Calls Another

Working with openwhisk, it's easy to create many isolated actions and build them up into sequences; the output of one action is passed to the next action in the sequence. In my case, I wanted one action to spawn potentially many other actions. I had to look up how to do it and here it is so I can look it up more quickly next time! Continue reading

Exclude a Directory when Grepping

As a developer-of-another-discipline who is now transitioning into a bunch of NodeJS projects, I grep a LOT. However I am usually only interested in the code in the project at hand, and not the dependencies - of course grep has a switch for that! To grep your project and not the dependencies in the node-modules folder, try this:

grep -R --exclude-dir node_modules [what to search for] * 

If you're using a different tech stack you may want to exclude a different directory (for PHP, the directory would be called vendor), but this is a very handy tip and a bit nicer than the older approach I was using which did the whole search and then used a second grep to eliminate things by using the -v switch.