Fixing a typo across multiple repos

Yesterday I found a typo in a pull request description while browsing another team’s project which I stumbled upon. I mentioned it to the author but it turned out that that part of the text came from the repository’s pull request template, which means every pull request will have this amusing but irritating mistake. I sent them a pull request, modifying the template, to fix the mistake at the source and avoid it in future, and thought that would be the end of it.

It turns out that template was written once and then copied across to new repos, which means this typo actually exists in almost all the pull requests in all of that team’s projects. Well that escalated quickly. This is the point where the average person probably says “OK whatever, it’s not worth it for something so small, there are too many repos, it’s just a small typo, never mind” and stop. A very determined person might actually start opening browser tabs and psyching themselves up to do pull requests. I open my terminal emulator and start writing a for loop.

Continue reading

Packaging Wakatime CLI for ArchLinux

I’ve decided to give Wakatime a second try. It’s a tool that tracks the time you spend programming on different projects by integrating into your IDE. This works well for typical development work where you open your IDE in the morning and type code in it, do commits with it, and everything else related to the project and Wakatime will track that.

I don’t work like that though, so I had two issues with it last time, both resulting in a lower reported time spent working:

  • I spent most of the day working on different remote servers and it would be a hassle to set it up in the text editor on each of them and it would undoubtedly cause slowdown on the older servers
  • I use the command line tools as my IDE, so the time recorded opening the text editor to make some changes is not representative of the time spent working

This time it’s different because nowadays I virtualise most of the services I work with, using Docker on my local machine, and I’m hoping that using the Wakatime Z Shell integration will give a better record of time spent working on a project.

Installing the Wakatime zsh plugin is as easy downloading the script and sourcing it in your .zshrc file. The only issue is it depends on the Wakatime CLI, which is usually bundled with Wakatime integrations, just not this one. The README file instructs you to get the CLI with sudo pip install wakatime but that leads to a system that’s difficult to maintain: Ideally you’d like to be able to install it from your distribution’s package manager but there’s no official ArchLinux Wakatime package and nobody has written a package script for it in the AUR yet. Luckily it turns out to be pretty easy to do.

The CLI is Python based and available for download on pypi (what pip does when you pip install). There are clear instructions on the ArchLinux wiki on how to make a Python package with the distutils tool that comes with Python, and a prototype Python package script you can use as a starting point.

All I had to do was fill out the fields in the example package: The download URL, version number and md5 hash are found in the pipy page. The licence, website, description and everything else is on the GitHub page. The result looks like this:

# Maintainer: Siôn le Roux <sinisterstuf@gmail.com>
pkgname=wakatime
pkgver=10.1.0
pkgrel=1
pkgdesc="Command line interface used by all WakaTime text editor plugins"
arch=('any')
url="https://github.com/wakatime/wakatime"
license=('BSD-3-Clause')
groups=()
depends=('python')
makedepends=()
provides=()
conflicts=()
replaces=()
backup=()
options=(!emptydirs)
install=
source=('https://pypi.python.org/packages/7c/28/7d98467580850eb41d75a6b988fabf68caa0e930882f6f3188fe68a01c8b/wakatime-10.1.0.tar.gz')
md5sums=('e26017168caaf12eafceb129690d97f7')
 
package() {
  cd "$srcdir/$pkgname-$pkgver"
  python setup.py install --root="$pkgdir/" --optimize=1
}
 
# vim:set ts=2 sw=2 et:

After installing the package built from this script, everything works as expected, so I’ve published it to AUR as wakatime. If I’ve made any mistakes packaging this, please report them as issues on the package script’s GitHub repository or leave a comment on its AUR page.

Use HOME as your GOPATH

How and why I normalised my Go paths and personal/local home paths.

Like many people, I have my own scripts and stuff in a bin directory in my home directory. Actually it’s a symlink to ~/.local/bin because I saw there was a ~/.local/share which some programs use to store user-specific things and I wanted to be consistent.

Then I saw some people have ~/bin and ~/src and I thought that looked like a tidy way to organise things. So far my approaches have been putting code in ~/Scripts ~/Projects/Programming or more recently ~/Work and ~/Hacking. The capitalisation being inspired by the Free Desktop common User Directories style, e.g. Music, Desktop, and so on.

And then Go, which is inflexible in where you place your code, requires you to specify a $GOPATH to a directory containing src/, pkg/ and /bin. I initially misunderstood this to be some useless path for internal use by Go tools and not needed by the user, so I put it in ~/.go where it wouldn’t bother me. It turns out that you actually keep all your source code there and use it every day. It’s so common for people to put their code in ~/go that starting with Go 1.8 this will be the default $GOPATH if you don’t specify one.

On the other hand, grouping your files by what language they were written in is silly. Imagine ~/Work/Java Projects/ ~/Work/PHP Projects/ instead of grouping them sensibly based on what they’re for instead of how they’re written. Or imagine /bin/c/ls /bin/bash/update.sh /bin/go/docker

From the “How to Write Go Code” document:

Another common setup is to set GOPATH=$HOME.

And so that’s what I did.

I moved everything from ~/go to ~ and I moved my own scripts and stuff from ~/.local/bin to ~/bin, symlinking ~/bin back to ~/.local/bin so that anything expecting it there can find it.

Go requires you to organise your programs under src/ by host and then by author (raising some new issues, like what if it’s unhosted) which seems like a reasonable way of organising lots of things, conveniently also keeping work separate from free-time open-source stuff on GitHub. And since it’s inflexible about it, I might as well make lemonade from lemons and use it for everything else.

I’ve just scratched a 5 year itch and that’s where I am now. This seems neater than before, let’s see how it works!

grml zsh inPlaceMkdirs

I keep forgetting this, but it’s really useful when working in the command line so I’m writing it down now. I use the grml zsh configuration in my shell and it has several very good features; a cool one I’d use more often if I could remember the shortcut is “in-place mkdir”. The key sequence is:

Ctrl-X, Shift-M

That’s Ctrl and x, followed by an uppercase M.

Here’s an example use case: Imagine you’re writing a command to do something with a very long path, like moving a file deep into a source tree

mv File.java src/something/very/long/

except half-way in your realise some of the directories in that path don’t exist. No problem! Usually you’d have to cancel that command, create the missing directories and then type it again. Now you can just type Ctrl-X, Shift-M, the directories are created and you can just press enter to use them. Much less annoying! This can even work for different directories in the same command; move the cursor to the directory you need and zsh will create that one!

For other useful shortcuts, see the reference card.

Finding photos of a known size

Recently I did a friend a favour and installed Linux Mint on her laptop as she was a bit frustrated with Windows. Unfortunately I assumed she’d backed up everything before handing it over to me, so I re-partitioned the whole drive to ext4. She hadn’t.

On the bright side the computer was quite new and the only thing she wanted from the disk were some photos she’d taken. Well, that just made it my lucky day because there just happens to be a tool specifically for recovering photos (and a myriad of other filetypes) from disks that have been written over: TestDisk! Continue reading

Checking Computer Specs With No Operating System

After my previous post about checking computer specs in Linux somebody asked an interesting question: how do you check your computer’s specifications if you don’t actually have any operating system to check them with?

In my opinion the easiest way to do this would be to download a disk image of a live CD for a lightweight Linux distribution, such as my favourite: ArchLinux. Once you’ve burned it to a disc you can put it in your computer and boot directly from the disc. ArchLinux is light and fast and will allow you to log in as root with command line access, where you will be able to run the commands I talked about in my other post to find your computer specs even for a computer with no OS or in other cases, for example where you don’t have permission to check with the current OS. If you’re not familiar with Linux don’t worry, follow the on-screen instructions and just type the commands I described. When you’re done checking you can turn off the computer and take out the CD and things will be just as they were before.

Checking Computer Specs in Linux

❗ Note: automated script downloadable at the bottom of this post!

Something you always want to do on a computer, even if only once, is to check its hardware specifications, that is:

  • how much RAM do I have?
  • how much hard disk space do I have?
  • how “fast” is my CPU?
  • how much RAM does my graphics card have?

Of course most modern GNU/Linux desktop environments like Ubuntu usually come with some kind of graphical tool to find this information. GNOME’s System Monitor program should provide at least some of what you’re looking for. The information here is more for when you’re staring at a blinking cursor on a black screen trying to remember what the command was to show information about the CPU, RAM or Graphics Card.

This is the third time I’ve had to go on an internet search quest to remind myself how to do this in a Linux terminal. To save myself the trouble in the future, I’m writing down the commands here and if anyone else finds it useful then that’s great, and a second bird is figuratively killed!
Continue reading

A Game With No Pictures

You can look down on the idea of it all you want but command-line games have their place. Not only are there situations where you need them but in a way, not having any graphics sometimes allows them to focus on other aspects of gameplay that makes them better. I was installing a new operating system on my computer today but I messed up somewhere and ended up with no Desktop Environment. Imagine turning on your computer one day and where you usually get:

“Hi, welcome to your computer [insert lots of fancy graphics and stuff], please pick who you want to log in as and I’ll give you a desktop with buttons and icons that will show you programs in little windows and let you click on things to do stuff.”

you now instead get this: Continue reading