Eurovision favourites 2015

The last few years I’ve enjoyed Eurovision far more than I should, but completely forget the songs year-to-year. That’s probably not a bad thing but my squirrel-minded filing can’t let it go – so here’s a record, mostly for me.

Sweden deserved to win, this is great pop and a great show…

Was our entry really deserving of so few points though?

Not ballads (yawn), but not Euro-pop either, colour me interested:

Winter is coming!

Most Eurovision-y of them all (and I didn’t notice, a bit of a middle finger to Russia as well!)

Looking forward to 2016!

Keeping it simple – sometimes you don’t need to call .Any()

Something I’ve seen quite a lot of in the codebase I’m working on…

If a collection is empty, the count is 0 and the enumerator is valid but won’t return any items – so there is no need to call .Any() before summing or enumerating.

Count() example

articleTagListForTagGroup
    .Where(tag => tag.ChildTags.Any())
    .Sum(tag => tag.ChildTags.Count());

Because .Count() returns 0 if there aren’t any, this can be reduced to:

articleTagListForTagGroup
     .Sum(tag => tag.ChildTags.Count());

Enumerator / foreach example

if (tag.ChildTags.Any()) {
    foreach (var childTag in tag.ChildTags) {
        // Display

If there aren’t any ChildTags then the foreach has nothing to iterate over – but it won’t throw an error, it just jumps over the code block. It can be simplified to:

foreach (var childTag in tag.ChildTags) {
    // Display

Fairphone (FP1U) Review

The news that the final batch of FairPhones will be available to buy soon (the shop re-opens on Tuesday 3rd) has spurred me to write up a review now that I’ve been using mine for a while.

FairPhone is trying to create a phone while opening the transparency in the supply chain – improving workers’ rights, etc.

I’d been following their progress for a really long time, but felt I couldn’t really justify purchasing a new phone until my old had really died. The performance of my old HTC One X finally dropped to that point around December so I finally got one through the Phone Co-Op (bought outright with a PAYG SIM, so I can’t say anything about their offering).

Things I love about the FairPhone

Masses of usable, expandable storage: There’s 14Gb of built in storage, but it’s all one lump that you can use for apps or data, so I’m in no danger of running out of space, nor am I shuffling apps from “phone storage” to “internal storage”. If I want to more space for data, then there’s a MicroSD slot so I can expand as I like.

Battery life: I have seen it go south of 50% just a few times, and then only after heavy usage or if I’ve failed to charge it. Because I can easily replace the battery (or get a second one), I’m re-assured that this will never be a real problem.

UI is clean, phone is responsive: Even though the phone specs are not top of the range, they’ve kept the UI light and it felt really quick, especially when I first got it. A few apps down the line and it’s a little bit more sluggish, but still significantly faster the the HTC One X it replaced (which had a faster processor). I think part of that may be the complete absence of any pre-installed apps that you can’t get rid of – everything is a choice.

Design: it’s a little heavier than a lot of phones, but it’s got a sort of old-school charm to it and is nicely balanced, so that extra 30g doesn’t really matter to me.

Decent speakers: I can happily play music on this and bimble around – don’t try anything too bass-heavy on it and it’s fine. To place it – it beats the HTC One X (is that hard?), it doesn’t beat an iPhone 5.

The price: £230 – I’ve since read that this isn’t brilliant for the mid-range segment of the market, but I’ve found that to be great value for money. And, yes, you are paying extra to try and ensure that those who made it have greater freedoms – it would be weird if that didn’t cost some money!

Things that I don’t love about the FairPhone

No core OS upgrade path: This isn’t intentional from FairPhone, but a side-effect of the way that Google, Android, and chipset manufacturers work together. It’s still disappointing and is likely to be the reason I will upgrade in the future.

Original set up: None of the Google Apps come as default, and so you have to download them separately, and each time you upgrade the FairPhone part of the OS. That wouldn’t really be a problem except that the process failed a few times and it actually took me a few hours to get my contacts and e-mails on the phone.

Camera is only OK: An upgradable component please FairPhone!

Git tutorial for very basic usage

This quick how-to is designed for someone who needs to work on your code, but where it is not practical to train them on all the benefits of git/source control. I have some workflow thoughts for the git administrator at the end of the article. The tutorial is aimed at a Windows user but should be reasonably portable. Any thoughts, comments, criticisms, or ideas for improvements please let me know and I’ll edit the article!

Download and install software

Download the git client.

Run the installer and answer the questions as follows:

  • Install location: wherever you like!
  • Components to install: if you don’t want to use git much then feel free to remove the Windows Explorer integration, don’t bother with desktop and quick launch icons, etc. I would suggest you allow .git* to be associated with your default editor though.
  • Adjusting your PATH environment: select “Use git from git bash only”.
  • Configuring the line end conversions: Checkout Windows-style, commit Unix-style.

Get a copy of the project

GitHub and BitBucket clone URL locations

GitHub and BitBucket clone URL locations

For this step, the git administrator should give you a URL for the git repository and a branch name, use these values in the commands below. If you’ve been given access to a BitBucket or github repository, the URL for the repository can be found on the site and depends on your username.

  • Open up Git GUI.
  • Clone Existing Repository… Source location is the git repository URL you’ve been given and the target directory is wherever you’d like it to be on your computer. If you’re given a choice, select to download a Full Copy as well.
  • Hit the Clone button and wait (you may need to enter your password)
  • Git GUI open repository

    Git GUI open repository

    When the download has finished, the Git GUI will automatically open the repository for you in a window that looks like this.
  • Git GUI create tracking branch

    Git GUI create tracking branch

    Next you need to “checkout the correct branch”. In this case, we’re going to checkout the develop branch but you may have different instructions. Go to “Branch”, “Create”, “Match Tracking Branch Name” and click on origin/develop (or origin/branch-name) and then click create.

You are now ready to work!

You have work ready to send?

Git GUI Commit & Push

Git GUI Commit & Push

Open up Git GUI and it will list the repositories you have created – click on the correct one or use the open command to bring up the GUI window we’ve seen before. The changed files will be in the top left hand section. (Hint: if you’ve not closed the window from before, click the rescan button to show changed files).

Move these changes into the bottom left pane by selecting the files, the going to Commit -> Stage to Commit. Enter a message in the bottom right box and then click Commit. Then click Push.

You have sent your changes back to the repository owner (although it’s good form to let them know as well).

You have updated files to receive?

In this model, only either your or the repository owner can make changes at once (git is much more powerful than this, but we’re keeping it simple). If you know changes are coming from the source, wait until they’re ready then follow this update procedure.

Open up Git GUI to the repository and select Remote – Fetch From – origin. This gets the latest code data from the source.

Git local merge window

Git local merge window

To update your code you need to go to Merge – Local Merge – you should be able to select origin/<your-branch-name> and then click merge. If you’ve not made any changes – or your changes are in completely different files, then it will merge fine and you’re ready to go again.

Workflow thoughts for the git administrator

To avoid exposing any of the more complicated workings of git, I’ve set the user up with a branch that only they are using. If you need to send them new files, they need to commit, push and then stop editing their files until you have merged new changes back into their branch for them. At that point, ask them to update.

YouTube oembed parameters / documentation

While looking at a bug in Umbraco, I could not find, anywhere, a definitive description of the YouTube oembed service – so I’ve decided to write one up. Please let me know if you find other features, or if this has drifted away from accuracy. Or if I’ve just been incompetent and not found the official API documentation somehow.

The YouTube oembed service is available at https://www.youtube.com/oembed (note https, not http as otherwise advertised, it’s 301 redirected).

Standard parameters (as per oembed specification)

  • url – the URL of the resource
  • maxwidth – the maximum width. The thumbnail size is not affected. This value, if bigger than the usual video return, will increase the size of the video.
  • maxheight – the maximum height. The thumbnail size is not affected. This value will only decrease the size of the video.
  • format – “json” or “xml”

Non-standard parameters

  • scheme – you can set this to “https” to make the returned code work on a site served over https. (Why the returned data doesn’t use “//youtube.com”, I don’t know…)

Sources

Removing SSL 2.0, Adding TLS 1.1 and TLS 1.2 in on Windows 2008 (IIS 7.5)

By default, Windows 2008 R2 has some shonky SSL settings – it enables SSL 2.0, which is broken, and it doesn’t enable the best protocols – TLS 1.1 and 1.2. To disable and enable things as we want them, we need to go digging around in the registry.

I’ve compiled these instructions from this article details how to disable SSL 2.0 and this article with broken instructions on how to enable TLS 1.1 and TLS 1.2. As this process requires a server restart I thought this single article might keep downtime low.

IIS SSL capabilities are controlled at the system level, so this should work for other IIS versions as well.

Editing the registry

The keys we need to alter are in: HKey_Local_Machine\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols

There should already by a key (folder) called SSL 2.0, you need to create two new folders called TLS 1.1 and TLS 1.2.

Underneath these protocol keys, you need another set of keys (folders) called Client and Server. These may already exist for SSL 2.0.

Underneath the Server keys, we need to put a DWORD called Enabled and set it to 0 for SSL 2.0 and to 0xffffffff (Use the hexadecimal radio button) for the two TLS items.

Underneath the Client keys, we need to put a DWORD called DisabledByDefault and set it to 0 for TLS and ffffffff for SSL 2.0.

Reset the server and then check the protocols it now allows – everything should be sorted as more secure – check it using this tool.

Tool that sorts it out for you

If you’re happy installing random tools on your server, then you can get IIS Crypto to make the changes for you.

If I’ve got anything wrong, or you think I could be clearer, please drop me a comment below here! Thanks.

Splitting/cutting an m4a file

Every so often I have an audio file that I need to break into sections. With more files coming as .m4a, the various GUI options I’d used before no longer work.

Now I’ve found a method that doesn’t need a GUI – use command line ffmpeg to split these files. The basics I found from a superuser question that was automatically breaking a file into smaller pieces. Taking out the Ruby sections, here’s the useful snippet.


ffmpeg -ss 1:01:42 -i c:\Data\temp\in.m4a -vn -c copy -t 1:00:00 out.m4a

  1. The first time (1:01:42) is the start time of the cut.
  2. -vn means that only the audio stream is copied from the file.
  3. The second time (1:00:00) is the duration of the cut. It can be longer then the length of the whole file.

Note that the cut is made at the nearest point to that time that the stream allows, so it might be a little out.

Clearing DNS caches

When making DNS changes it can often take a while for various DNS caches between yourself and the source to clear. I’ve often found that the last ones to change are the ones in the last few metres – from your router to your browser.

You’ll need to find the one upstream that’s incorrect and fix “backwards” from that – i.e. check your Windows DNS cache first, then work towards the browser.

Browser

According to OpenDNS, all browsers will clear their DNS cache if you use their clear cache functionality, but that’ll take out a lot more than DNS.

Chrome: Visit chrome://net-internals/#dns and press the ‘clear hosts cache’ button. You can also see what IP it’s talking to on this page.

Firefox: Close and re-open browser should do it – otherwise there’s a fiddly method involving about:config. When I’ve tried out the plug-ins I’ll add a suggestion, but if you’ve using one let me know in the comments and I’ll update this.

IE: no independent DNS cache.

Local Windows machine

At command prompt: ipconfig /flushdns

Use ping to see if you’re resolving OK.

Windows Server (if acting as DNS cache)

At command prompt: dnscommand <servername> /clearcache

Checklist for large file upload issues in IIS7 / .net

I had an issue with large(-ish) file uploads yesterday and thought I should write up the things I needed to change, as it’s one of those things that I have to do from time to time and I invariably forget all of the settings.

This is in .net Integrated Pipeline mode – it’s different for Classic ASP.

The following two settings allow files of up to 200MB (value is in kilobytes) taking up to 10 minutes (value is in seconds). See documentation for this

<system.web>
  <httpRuntime executionTimeout="600" maxRequestLength="204800" />
</system.web>

You will also need to alter this setting (value is in bytes this time – see the documentation). It defaults to about 30Mb.

<system.webServer>
   <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="209715200" />
    </requestFiltering>
  </security>
</system.webServer>

My understanding is that these settings are usually kept quite low to avoid DoS attacks, and if you’re admin for a large site you should consider moving your uploads to a different server or at least a different application / application pool.

If there’s anything missing from these settings, or some nuance I’m missing, please let me know in the comments.