Working as a coder at a technology company versus working as a coder in other contexts

I was just skimming a book about Python and I found a rather interesting quote:

“Programming as a profession is only moderately interesting. It can be a good job, but you could make about the same money and be happier running a fast food joint. You’re much better off using code as your secret weapon in another profession.

People who can code in the world of technology companies are a dime a dozen and get no respect. People who can code in biology, medicine, government, sociology, physics, history, and mathematics are respected and can do amazing things to advance those disciplines.”

Looking at salaries for developers as well as reading the experiences of coders in technology companies this really seems to ring true. I’m the other kind, I’ve picked up a bit of code in order to do my day job which is really focused on collecting and analysing user experience data. And actually I do get respect and I have been able to do a lot of new things that nobody was doing before I got started.

Quite inspiring words, really. I feel a renewed urge to develop my programming skills within the current role that I have to try to push things even further and will stop daydreaming about what it would be like to be a “real” programmer.

 

 

The NHS, hammers, and spanners, part 27

The scene- a group of NHS managers stand around a bolt fixed to the wall, repeatedly hitting it with a hammer in a futile attempt to remove it, and a valuable painting, from the wall. Every manager is holding a new, shiny, and identical, hammer.
A colleague and I walk in and, wielding a spanner, easily remove it from the wall, and hand the painting to the most senior person in the room. We turn to leave.
“Wait!”
“Yes…?”
*gesturing to a huge bank of paintings on the wall, each affixed with a single bolt* “Can you port what you just did to hammers?”
Without a word, we trudge wearily out.

Open document formats and why we need them

The whole world is moving to open document formats for the obvious reason that in order to read and write documents one shouldn’t need to waste money on Microsoft’s increasingly ungainly Office application when perfectly good free and open source alternatives exist (thinking particularly of the mighty LibreOffice). The UK Government has formally adopted an open standard for all of its documents.

Despite this many public bodies in the UK, including the NHS, councils, and many other organisations, continue to use Microsoft’s proprietary formats for documents. It may seem to the casual user that the arguments for proprietary versus open document formats are rather arcane. I would like to tell a story from my own life that illustrates why in actual fact every citizen and certainly every public body should be interested in open document formats.

My wife has just applied for a job. The application process involved filling out a Microsoft Word document. Naturally, she wanted to appear efficient and professional and so was concerned that if she used LibreOffice the tables within the document would be mangled. We don’t own a copy of Microsoft Word. I consider it to be a waste of money and besides object to funding Microsoft since they have done so much to oppose open standards.

As a consequence, I have spent three hours, which I could have spent working, or looking after my family, or just relaxing from doing either, using a huge pile of technology (a Citrix enabled Word program that I can access through my job, Google’s own document preview function in their email, a .pdf to .docx converter, and LibreOffice) to ensure that the document renders nicely.

This was further complicated by the fact that the document itself, in its original state, was badly formatted, and so I had to ensure that the bad formatting left in the document really was in the original or if we had introduced it using LibreOffice.

I’m a computer programmer fluent in R, moderately proficient in PHP/ MySQL, and manage two Linux servers. Not only that but I have extensive experience with Microsoft Office from my PhD. I actually made the document better.

Not everybody will want to or be able to pay for Microsoft Office. Not everybody will know somebody who can fiddle around with the huge pile of technology necessary to make the form look reasonable. But I think it’s pretty obvious that we don’t want to make job decisions based on an application form’s looking unprofessional because the applicant didn’t have Office and wasn’t married to a geek.

And that, ladies and gentlemen, is why we need open document standards.

Backing up a remote MySQL database on a remote server using cron

This is more a collection of links, really, than a proper blog post, but I just spent quite a while figuring out how all of these different technologies all fit together to do the job I wanted so if you want to do what it says on the tin of this blog post then you should find it useful.

I have a remote server running a MySQL database. I wish to backup this server daily. I would rather do this on my other remote server than on my local machine because, obviously, my server is always switched on whereas my local machine isn’t. So the task is to dump a MySQL database to a file and upload it to a remote server.

To begin, you’re going to make sure that the server with the MySQL database on it can access the other server. This is easiest using ssh key login. I use this for all my servers and all of my local machines. There is a summary here. The beauty of using a key based login is it eliminates the need for passwords, which is not only secure in general but also means you do not need to store passwords in cron scripts or anywhere else on the computer which is highly insecure. Unless you really know what you’re doing you should never do this.

Next you’ll need to create a user on your MySQL and give it SELECT privileges so it can read the data to make the backup. This is very simple

GRANT SELECT, LOCK TABLES ON mydatabase.* to ‘backup’@’localhost’ IDENTIFIED BY ‘password’;

Now you need to set up a cron job to back up the database every day. There’s some stuff about it here, but you won’t need the bit about passwords because we’re using key authentication. As I mentioned above, it’s easier and safer. We’re also going to add some terminal magic to automatically change the file name every day to the current date so you can have daily backups on the server. Here’s the finished cron entry.

0 1 * * * mysqldump -u backup SUCE | ssh chrisbeeley@178.79.158.221 “cat > ~/backupDB/$(date +\%F)_SUCE_DB.sql”

This runs the backup operation every day at 1am.

You’ll need to clean up the old files occasionally, otherwise your server will get full of very old copies of the database. The following command will remove all files from the directory that are older than 31 days old:

find ~/backupDB -type f -mtime +31 -exec rm {} +

BE VERY CAREFUL with this command. If you run it with the wrong directory or have any strange errors with it you may find yourself deleting a lot of files that you did not want to delete. ALWAYS be safe and test by running find ~/backupDB -type f -mtime +31 first and reviewing the files which come back. Only when you’re happy that it’s finding the right files should you add -exec rm{} +

I haven’t added this to a cron job, partly because it doesn’t seem worth the risk (the command is safe in my environment today, but always be wary of PEBKAC, even for yourself), and also because it means I can choose when to flush the old database files, just in case I find some current problem in the database which I can fix with an older version.

Make your own HTML tables in R

I’ve avoid writing HTML tables by hand in R, reasoning that it would be far too complicated. But the problem with using packages like pander and rmarkdown, much as I love those packages, is you can’t fine tune the outputs. So if a colleague asks you to add little extra touches for a report you can’t really do it.

So it was a nice surprise to find that it’s actually not that hard. Here’s a table with 3 columns which looks very nice with bootstrap (don’t know what the styling options are on WordPress so it just looks unformatted here)

Service quality 95 90
Promoter 90 85
SUCE returns 1000 1200

Code:


paste0(c("<table class='table table-striped'>", 
  "<th>Score</th><th>Current quarter</th><th>Previous quarter</th>",
  "<tr>", paste0("<td>", c("Service quality", 95, 90), "</td>"), "</tr>",
  "<tr>", paste0("<td>", c("Promoter", 90, 85), "</td>"), "</tr>",
  "<tr>", paste0("<td>", c("SUCE returns", 1000, 1200), "</td>"), "</tr>",
  "</table>"), collapse = "")

Obviously you can make it dynamic pretty easily, the table above is from a Shiny app I’m currently developing, I’ve just replaced the numbers with static values for the blog post. So the next time someone asks me to style a table it should be pretty easy.

G++ error compiling on R

I was installing R packages (the httpuv package, but I imagine others would generate the same problem) on my Ubuntu server today and I got a very strange error message:

g++: error: Welcome: No such file or directory
g++: error: to: No such file or directory
g++: error: R!: No such file or directory

It was a problem with my .Rprofile.site file. That’s why it looks funny, because R is saying “Welcome to R”, but for some reason this is messing with g++. In my case it seemed to be generated by running R as sudo, but I need to do that to make the package library writable. Just invoke R at the terminal with:


R --no-site-file

and it will be fixed.

Sharing files from host machine on virtualbox

I’ve really started getting into virtual machines recently. Firstly because I like to try different flavours of Linux and constantly reinstalling partitions is starting to get a bit of a drag, especially when it often takes ages to get the graphical desktop to work because of my silly graphics card. Secondly, and more importantly, because I’m finding if you want to do programming, or especially write about programming, you often need a “clean” system or a system set up a particular way to test things and work on multiple things at once. So the code I write for Shiny is based on the newest 0.12 version. However, my server is all the way back on 0.7 for various reasons to do with browser compatibility. So this means I need a local 0.7 installation to test programs that I’m updating on the server. Or sometimes it can be important to check what the dependencies for your programs are. You may have installed something a year ago that makes everything work beautifully that you’ve long since forgotten about, and if you tell someone else to do what you’re doing it won’t work on their machine. In the Linux world technologies like Docker which package up whole environments at the operating system level and help you to manage dependencies (amongst other things) are starting to spring up and in the R world things like packrat roll up packages into bundles in order that all package versions are the same and dependencies satisfied.

I haven’t learned those technologies yet so I’m going to stick with virtualisation for now (Docker is probably a bit of a sledgehammer to crack a nut for me, anyway, really).

I am mainly making this post because I keep forgetting how to access the host file system on the guest system, so I’ll be able to refer to it in future. I hope it helps you. It’s based on Ubuntu. Some of it is probably similar in other OS’s, I really have no idea I’m afraid.

Go to Devices (on the Virtualbox host machine, i.e. on the window that contains the graphical environment of the guest machine) and select Insert Guest Additions CD image. It will be mounted for you. You need to find out where it’s mounted so you can access it from the terminal. Mine mounted at /media/chris/VBOXADDITIONS_4.3.10_93012/.

Run the Linux script within the mounted folder, on my machine it was:


cd /media/chris/VBOXADDITIONS_4.3.10_93012/

sudo sh ./VBoxLinuxAdditions.run

Presuming this works okay, reboot the virtual machine, and now select Devices… Shared folder settings on the host machine. Click “Add shared folder” over on the right. Find the folder and click “Auto-mount”. Select “Read only” (a lot of people seem to do this, don’t know why, seems safer anyway).

If you restart the folder should now be in /media. If you get “Unknown filesystem”, “Cannot open folder”, or something like that then you need the advice from here.

From the VBox User Manual:

Access to auto-mounted shared folders is only granted to the user group vboxsf, which is created by the VirtualBox Guest Additions installer. Hence guest users have to be member of that group to have read/write access or to have read-only access in case the folder is not mapped writable.

Therefore run:


sudo adduser yourusername vboxsf

Restart and it should all work. I restarted the virtual machine after each stage, just in case. If it still doesn’t work, sorry, off to the forums with you.