Fetching a remote file in Linux

Downloading a file to your computer, only to upload it to a server, is time consuming, especially if it’s a large file. Why not just download it from the server using the command line? It’s a lot easier than you might think.

Sometimes you need to download a file from a remote location. I can think of a couple of quick examples:

  1. Fetching a data feed published by an external source;
  2. Downloading a package (e.g. WordPress) to avoid downloading it to your computer and uploading it again from there.

In the first instance, being able to download the file from your server makes you a step closer to automating the process (e.g. if the feed is updated, say, once an hour). In the second instance, it’s much faster as it’s a one-step, rather than a two-step, process. And it’s really easy, using a package called wget, which supports downloads over HTTP, HTTPS and FTP:

wget -O /path/to/filename url

The -O switch controls where the resulting file will be saved, and the URL is the file to be fetched. If only a filename (no path) is entered, the file will be saved to the current directory set in the terminal. For example:

wget -O latest-wordpress.tar.gz https://wordpress.org/latest.tar.gz

This command would fetch the latest copy of WordPress from the WordPress servers and save it at latest-wordpress.tar.gz in the current directory.

One thing to be aware of: the switch (-O) is case sensitive. It must be upper case.

The wget command has a large array of other options at runtime, but for simple cases like fetching and saving a single file, this is all you need.

2016 Political Predictions

Want to know everything about politics in 2016? Well, you won’t get that here. But I can tell you what I think will happen, and we can all laugh at how bad those predictions were come the end of the year. Or probably in March, to be honest.

The start of a new year is always a great time to make predictions which will ultimately be shown at the end of the year to be entirely misplaced.

That’s certainly true in politics. Who would have predicted a Conservative majority government at the start of last year. Well, me, actually… But I wouldn’t have predicted Jeremy Corbyn would be Labour leader… Or that Jim Murphy would be such a disaster as leader of Scottish Labour.

So,here are some predictions for 2016. Most revolve around the Scottish elections, since that’s what’s mostly on my radar right now.

The SNP will win a majority in the Holyrood elections
There’s nothing I can think of that can stop this. The question is, can they win a majority on constituency MSPs alone? They would need to pick up twelve of the twenty constituency seats they don’t currently hold in order to do this. I think it’ll be very close.

The Conservatives make gains on Labour
I don’t see Labour holding all thirty-seven seats they currently have. They currently hold fifteen constituency seats. Good luck.

The Conservatives, on the other hand, will, I think, gain a small handful of seats, mainly on the list. They’ll gain on Labour more because Labour lose seats rather than by gaining their own, but I think it will be a bit of both.

The Greens will finish with more seats than the Liberal Democrats
The Lib Dems will struggle. I think they’ll pick up a single constituency seat and a few on the list. The Greens won’t win any constituency MSPs, but they’ll win more on the list, because they’ll pick up pro-indy, anti-SNP votes. I’d be surprised if the Liberal Democrats get 5% of the vote.

I would say Willie Rennie will no longer be their Scottish leader, but will there really be anyone there to replace him? I think it’ll be grim for the Liberal Democrats, despite the outward optimism they seem to have now.

Britain will vote to remain in the EU
I know Brits are hardly fond of the European Union, but I don’t think people will be prepared to take the risk of leaving when faced with the choice in a referendum. When making a choice, thinking about factors like jobs and money in their pockets, people will stick to what they know. They won’t want to take the risk.

Don’t believe me? Well, it was the same with Ed Miliband.

Jeremy Corbyn will survive as Labour leader
Getting rid of Corbyn would result in full-scale civil war. Labour MPs will decide to let him continue to poll badly, rather than stick the knife in quickly. It’s probably safer.

Hillary Clinton will win the US Presidential race
This will happen for the simple reason that no-one can beat her to the Democratic Party nomination, and all the Republican Party candidates that might do well are crackpots can’t reach out to enough voters. That, in essence, is the problem the Republican Party has at every election at the moment.

London will get a new mayor
But I’ve no idea who. London mayoral election’s are a mug’s game. I think it’ll be the tightest mayoral election yet, though. If forced to make a prediction, I’d probably pick Sadiq Khan, based on gut instinct and nothing else.

NFL 2015-16 Power Rankings

With the playoffs fast approaching, how do the teams stack up against one another, and who should we be looking out for on the road to Super Bowl 50? Well, the good news is, I can point you in the right direction (with a little explanation of how I got there).

For the last few seasons, I’ve published my own version of the popular NFL Power Rankings that appear on a number of sites. On most sites, these seem to be calculated arbitrarily, whereas I’ve tried to produce something that adds at least a slightly more scientific approach. What follows is an explanation of the method, but if you just want to see the rankings, they’re at the bottom of the piece.

It’s worth noting, before reading further, that I’ve adjusted my rankings formula again, so if you’ve read my rankings in previous years, they’re not directly comparable.

Finding common games

This approach is made a little tricky by the way the NFL organises schedules, but not impossible. No team plays the same sixteen opponents across the regular season, but in each division, every team plays a similar schedule across fourteen games:

  • Home and away against each team in their own division;
  • Once against each team in a designated NFC division;
  • Once against each team in a designated AFC division.

There are some differences in that schedule, as the combination of games played at home and on the road is different, and the final two games are unrelated, based against each team’s relative performance in the previous season, but it’s a good start. Thus, I base my Power Rankings on those fourteen common games, ignoring the two outside that.

Comparing divisions

As games are only common within divisions, I need a way to compare divisions. I do this by comparing the number of total wins in each division, as each division. Whichever division has the most wins is the strongest division (for now, at least). It’s the mark by which all the other divisions are marked. All other divisions are then assessed based on their relative percentage of wins. If the division with the highest number of wins has forty wins, and therefore has a relative strength of 100%, a division with thirty wins would have a relative strength of 75%.

Matching divisions

Whilst a good start, this is still very crude. What if a division had fewer wins than another because the divisions it was matched up against were actually very tough? What if a division Was matched against two weaker ones, and so had an easier ride?

Well, this is relatively easy to solve, as each division is matched against two others. So, by combining each division’s relative strength with that of the two it was matched against, I can calculate an overall division strength, and I do this by adding the three values together. Thus, carrying the previous example, if the top division has forty wins, and it’s up against two divisions with thirty wins each, the formula would be:

1 + 0.75 + 0.75 = 2.5

The resulting figure of 2.5 is the division’s overall schedule strength. A higher number means a tougher schedule. This value is then, for each team multiplied by their record as a decimal value, where 16-0 would equate to 1, or 12-4 to 0.75. The resulting figure is the team’s final ranking.

The final formula

So, the final formula (when fully expanded) looks like this:

(D + A + N) * R


  • D – Division strength
  • A – AFC opponent strength
  • N – NFC opponent strength
  • R – Record

Whilst form is important enough to be in, I reduce its weighting because I consider the overall division strength and record to be a more reliable indicator.

The rankings…

So, without further ado, here are the 2015-16 NFL Power Rankings (as of week 16):

Arizona Cardinals2.7350.8672.372
Carolina Panthers2.3820.9332.223
Cincinnati Bengals2.7350.7332.005
Denver Broncos2.7060.7331.983
New England Patriots2.3820.8001.906
Green Bay Packers2.8530.6671.903
Minnesota Vikings2.8530.6671.903
Kansas City Chiefs2.7060.6671.805
Seattle Seahawks2.7350.6001.641
Pittsburgh Steelers2.7350.6001.641
New York Jets2.3820.6671.589
Washington Redskins2.7060.5331.442
Houston Texans2.6760.5331.427
St Louis Rams2.7350.4671.277
Atlanta Falcons2.3820.5331.27
Oakland Raiders2.7060.4671.264
Indianapolis Colts2.6760.4671.25
Detroit Lions2.8530.4001.141
Chicago Bears2.8530.4001.141
Buffalo Bills2.3820.4671.113
Philadelphia Eagles2.7060.4001.082
New York Giants2.7060.4001.082
New Orleans Saints2.3820.4000.953
Tampa Bay Buccaneers2.3820.4000.953
Baltimore Ravens2.7350.3330.911
Jacksonville Jaguars2.6760.3330.891
Miami Dolphins2.3820.3330.793
San Fransisco 49ers2.7350.2670.73
San Diego Chargers2.7060.2670.722
Dallas Cowboys2.7060.2670.722
Cleveland Browns2.7350.2000.547
Tennessee Titans2.6760.2000.535

I’ll likely write a separate post about the various methodologies I’ve used to calculate the Power Rankings, and why I’ve changed them along the way. I’m also open to refining the formula and also to know if any of the teams look out of place in these results!

Wondering why I’m publishing this before the final regular season games? I’m doing it because I want to see how the rankings stack up against the week 17 games. Not entirely scientific, I know, but interesting all the same.

Truncating a file in Linux

Linux has a very useful and easy command when you need to keep a file but empty the contents of the file. Very useful when developing or testing and you only need to look at data in real-time.

When I’m working on websites, I often have a need to empty an existing file.

The most common need for this is when looking at error logs. When I’m working on something, I always keep a close eye on the error logs and when I find a problem, I fix it. I then clear the error logs to see if the error reappears. I have no real need to archive or rotate the log. I just want it cleared so next time I open the file, I can see anything that’s new without the need to wade through what was there previously.

It’s very easy to do this, using the truncate command:

truncate -s 0 /path/to/file

If the logged-in user doesn’t have permission to modify the file you’ll need to run the command as the super user:

sudo truncate -s 0 /path/to/file

The truncate command is used to shrink or expand a file to a specified size, and the -s 0 switch tells it to empty the file.

Very useful for situations where you have files like logs where you don’t need to keep the data once you’ve looked at it.

New year, new site

Sometimes, you need to make a clean start. I’ve neglected my website a lot over the past few years, so I’ve decided to start again in 2016. I’m sure you won’t like everything on it, but hopefully you’ll find some of it at least a little interesting!

Many years ago, when I was a student (and yes, many is the correct term for that now), I had a very active website – mainly because I had a lot of free time and a lot to say. Unfortunately, times change, and over the last few years, the amount of content on said site has dwindled, almost to zero.

I’ve often thought to myself, “I’ll just redesign it nicely, and then I’ll start using it properly again“. Of course, that never happens. And so, I’ve bitten the bullet, so to speak, and decided to do it the other way round. The old site will be burned to the ground (at some point) and this new site will go in its place. It will look nice and pretty if I ever get around to it, but for now I’m just focusing on using it.

My main focus subjects will be:

  • Eurovision – you know I love this, right?
  • Faith – something I’m rubbish at writing about;
  • Politics – you know, that thing no-one cares about, until it impacts them?
  • Sport – American Football, Formula 1, and anything else that takes my fancy;
  • Technology – probably a mixture of things related to my day-job and server-side website bits too.

It’s unlikely all five of those categories will interest many people, but hopefully at least a couple will interest some.