How to view the raw commit data on GitHub

Today I learned that you can view the raw commit data for any commit on GitHub by appending .patch to the commit's url. For example,

This includes the author's email address. I know you can easily view the git log if you pull a repo down, but I didn't know it was easily visible on GitHub.

Deleting all docker containers and images quickly

For when you really want to blat everything.

docker rm (docker ps -a -q) && docker rmi -f (docker image ls -q)

I'm using fish so the command substitution is a little different to the usual bash syntax. If you're running a more standard shell, you'll probably need some $s in there:

docker rm $(docker ps -a -q) && docker rmi -f $(docker image ls -q)

docker rm removes containers by container Id. docker ps -a -q lists all containers in quiet mode - so just the container Ids.

The logic is the same for removing images - I've thrown in the force flag for good measure, and I've used && to concatenate two commands onto one line.

This will error out if you have no containers.

It's also very destructive. A nuclear option as it were.`

How to install DrRacket on Mac OS and Homebrew

Homebrew is excellent and you can install a minimal racket by running

brew istall racket

Once this finishes, you'll see instructions on how to install DrRacket with raco. Follow the advice:

raco pkg install --auto drracket

This takes a while. You might struggle to actually find the or launch DrRacket.

If you've never used racket before, you probably don't know raco either and you won't know where it has installed all the things.

Run the following to find out where raco has placed the .app:

racket -e '(require setup/dirs) (displayln (path->string (find-gui-bin-dir))) (for-each displayln (directory-list (find-gui-bin-dir)))'

This lists /usr/local/Cellar/minimal-racket/7.5/bin as the directory where sits on my machine. Running /usr/local/Cellar/minimal-racket/7.5/bin/ from the command line will launch DrRacket.

I symlinked it so it was a little easier:

ln -s /usr/local/Cellar/minimal-racket/7.5/bin/ /usr/local/bin/drracket

Weeknote 20200216 - Three things about Python

I chaired the tech fortnightly. It is an open agenda; anyone can put a topic in and speak. I always forget how much work it is to co-ordinate the events. Finding people to talk and suggesting topics takes more time than I expect.

I presented three things I have enjoyed while learning some Python. It sparked some good discussion in a community which does day to day work in Ruby. I am glad that my presentation served as a conversation starter. I want the tech fortnightly to become more two sided discussions rather than one sided presentations. I was a little dismissive of JavaScript in the middle of my talk, which I regret. It is insensitive to those who work primarily in JavaScript.

I started working on a prototype to explore data from a satisfaction survey. This involved putting together a database schema from a spreadsheet of data of denormalised and anonymised data. I inadvertently created quite a large chunk of what is a generic survey data design in the process.

I also attended a strategy workshop with other lead developers, head of tech and senior product managers. Thinking strategically is a skill in which I am not practiced. I still fall back to thinking of solutions and immediate implementation detail.

I spent some time tidying up my vale linting setup. Writing to vale's exacting standard is hard!

Weeknote 20200119 - Python, pip, dependencies

I started working with a new team focussed on using data science to make GOV.UK better for the end users. My previous team focussed on long term maintenance of the platform. Data science is a whole new world for me. I'm excited to get stuck in and learn.

The code is largely in Python and is the first time I have worked with a significant piece of production Python code. I immediately bumped into problems trying to install the requirements for the project.

In the project, two of the top level dependencies rely on Pygments. Pip installed an up to date version of Pygments when it resolved the first dependency, but the second dependency required an earlier version of Pygments. I think this was the result of merging Dependabot PRs without running pip install and ensuring a clean install.

Pip, to my surprise, does not resolve dependency versioning issues and I am reminded of DLL Hell.

My current understanding of workflow on a Python project is developers occasionally use pip freeze to write requirements to a file. Subsequent efforts can install from the file. Apart from the versioning issues, it is also easy to commit unwanted packages to a project if developers are not careful.

I spent some time investigating how other projects manage Python dependencies. A colleague pointed me towards PEP-0518 which looks interesting, but in my limited view of repositories around GDS, I did not see a .toml file being used so I don't know whether people are doing this in the wild or not.

I found pipdeptree which outputs a tree view of dependencies similar to Bundler's Gemfile.lock.

I discussed the problem with one of the other developers on my new team and went digging around some other Python projects. We found a pattern of two requirements files. One for base project dependencies that is hand crafted, and one autogenerated with all dependencies and their sub-dependencies. The advantage is developers are more aware of the dependencies they are adding and this should address the unwanted or unneeded packages sneaking their way into a project.

Going forward, I want to add some automated process around the projects to catch these errors earlier. The first thing to do is spin up a new virtual environment and run pip install -r requirements.txt on each branch push. After that, I want to put some linting in place. The code is still small enough for this not to be too daunting.

How to run a scheme script from the command line

Here's a small bit of scheme code:

(define (adding a b)
(+ a b))

(display (adding 7 4))

To run this directly from the command line, you can use the following:

mit-scheme --quiet < script.scm

How to force line breaks in markdown

I always forget this.
I don't know why, because my editor shows big nasty red blotches whenever I have trailing spaces.
To force a line break in markdown, end your line with two spaces.

A limerick

A couple of dev with nice Macs
Thought up some quite clever hacks
They opened PRs
Approved them too fast
Now production is being rolled back

How to output the current RSpec example

Here's a snippet you can add to your rspec config to print out the name of the method being run:

config.before do |example|
puts "----- state ----"
puts example.metadata[:full_description]
puts "inline: #{Sidekiq::Testing.inline?}"
puts "fake: #{Sidekiq::Testing.fake?}"
puts "----------------"

Why on earth would you wan to do this? Sometimes you are working with something like Sidekiq where state can bleed between tests (for example changing from inline to fake); this little snippet helps you figure out where it's happening without having to investigate all your test files.

Generating mongoid config in rails hangs

If setting up a new Rails project with Mongoid and trying to run rails g mongoid:config hangs, try

spring stop
spring start
Next Page