About Siôn le Roux (sinisterstuf)

I like freedom, GNU/Linux, programming and music. I work as a software developer and I play guitar for fun when I'm not out enjoying extreme sports.

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!

Vim “fake fullscreen”: open split windows in a new tab

Since I use a lot of split windows in Vim, for example when exploring the git log or editing closely related files, a pattern I noticed is I often want to make one of the smaller windows full screen momentarily so I can read more at once without scrolling and then close it when I’m done. I made a really simple mapping to simulate this “full screen” idea:

:nnoremap <Leader>f :tabe %<CR>

This opens the current window’s buffer in a new tab (fake full screen 😁) and when I close it I’m back to tab one with my split windows.

To demonstrate, here’s a gif in which I inspect the git blame for a file, open a patch and then open it “full screen” in a new tab:

Vim fake fullscreen demo gif

Vim fake fullscreen demo gif

Browsing the git log isn’t the best example because fugitive’s blame window already has an O mapping which opens the patch in a tab instead of a split and the necessity for this would be clearer with bigger files like those I edit at work.

This is one of the few things I use tabs for since I’m mostly jumping through buffers. Hopefully it’s useful for you too!

Várkért Bazár

Last month we went to see the recently renovated Várkert Bazár –literally “Castle Gardens Bazaar”— in Budapest’s castle district, here are some photos.

Rooting Samsung Galaxy Mini

Samsung Galaxy Mini

Samsung Galaxy Mini

My wife’s phone (Samsung Galaxy Mini GT-S5570I) doesn’t get system updates any more, so I need to manually move Google’s updates into ROM to make space for regular apps. You need root privileges to do this, so I was following these instructions on the XDA Forum which almost work fine. You need to download and apply a file update.zip but the problem is the update script inside doesn’t include S5570I in the list of phone models it checks for, so the script aborts.

All you need to do is edit /META-INF/com/google/android/updater-script inside update.zip and include this phone model in the assertion list, for example, I duplicated lines 15 and 16 and just added an I to the end:

getprop("ro.product.device") == "GT-S5570" ||
getprop("ro.build.product") == "GT-S5570"  ||
getprop("ro.product.device") == "GT-S5570I" ||
getprop("ro.build.product") == "GT-S5570I"  ||

Everything works completely fine after that. Obviously this is not a general solution when rooting, you can’t just blindly add your own phone model into any update.zip not knowing what’s in it, but since this was from a post for specifically this model and it already had several very similar models listed, I thought it was worth the risk and it turned out just fine. Woop! 😎

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.

Secured my site with Let’s Encrypt

You might notice if you browse this blog now, that it’s served over HTTPS. I’ve even added an Apache configuration to redirect plain HTTP requests to secure HTTPS and I’ve spent the last few days checking the pages for URLs including non-secure content and rewriting them to use HTTPS where possible, or otherwise removing them. You’ll also notice in the left-hand corner of the browser’s address bar, there’s a (hopefully familiar) little green lock which indicates:

  • your communication with the site is encrypted well
  • the authenticity of the site is verified by a trusted authority

Of those, the latter usually involves paying a trusted certificate authority a lot of money to verify and sign your site’s certificate so that browsers will mark it trusted. Security is important but this high cost often creates a barrier for small companies wanting to use https. Continue reading

Mathematical Range Summing

Immediately after the last post about summing a range of numbers, a talented friend of mine, Gábor, offered an even shorter, cleverer solution:

What I especially like about it is that instead of relying on esoteric JavaScript functions to do the job, it’s done with reasoning and plain maths, which makes it clearer and easier to read too.

The Maths.abs() call is only needed because in the original problem, the arguments could be in either order; the logic is still the same though, you just need to make sure the range is positive. In short, it’s (a+b) × (a-b+1) ÷ 2.

Sum All Numbers in a Range

A solution to Free Code Camp’s “Sum All Numbers in a Range” JavaScript challenge, in a Functional Programming style.

A friend of mine hosts meetups for the Free Code Camp, which describes itself as:

We’re an open source community of people who learn to code and help nonprofits.

He organises casual meetings in coffee shops to allow participants to work on their assignments in a nice environment and help each other. If you’re looking to learn programming I recommend finding a Free Code Camp group in your area.

Today I visited such a meeting and one of the Code Campers was working on a solution for one of the JavaScript problems in the Intermediate Algorithm Scripting section. The task was to write a function that takes an array of 2 numbers as an argument and returns the sum of all the numbers between them, including the 2 numbers themselves. For example, an input of [3, 1] should result in 6, because 1 + 2 + 3 = 6. As a hint, it’s recommended you read the documentation for Math.min(), Math.max() and Array.prototype.reduce(). Continue reading