UI and other network considerations – Embracing the Network lunch’n’learn

This talk is available in various forms across the web and it’s interesting the difference in reaction it received – with the old team at Haymarket we came up with about two pages of suggested changes to our front-end code and other improvements.

At Mountain Warehouse, a lot less interest – but then the team is fairly back-end focused and never really get to play with the UI.

Note: this is a different video of the same talk as the original has vanished.

SmashingConf 2015 Barcelona: Patrick Hamann — Embracing the network from Smashing Magazine on Vimeo.

MassTransit / RabbitMQ lunch’n’learn

Today I ran a lunch’n’learn around MassTransit and event driven architecture. In addition to some demo code, we watched the video below. It covers things quite nicely, not a lot of detail in the demonstration but as it’s MassTransit 2.x (not 3.x) that was OK. Quality is good, speaker is a little drone-y so a bit of snooze-danger if you’ve had too much pizza!

Loosely coupled applications with MassTransit and RabbitMq – Roland Guijt from NDC Conferences on Vimeo.

RESTful API lunch’n’learn

A little while ago we did a RESTful API lunch’n’learn session. These are the videos that we used.

This video from Stormpath covers a lot from basics to good patterns to use – it’s also good quality and as a speaker he’s quite animated so this kept our attention:

For those people who’ve used more SOAP services this video has been good to help compare approaches – however it does seem as if the presenter prefers SOAP (what else would you expect from Oracle?) so you have to apply your own salt:

Other notes

Here’s a quick overview of the properties of the HTTP verbs (this applies to more than just REST APIs!):

GET – Safe, Idempotent
PUT – Idempotent
DELETE – Idempotent
HEAD – Safe, Idempotent
POST – (none of these)

Safe: Makes no change to the server / performs no action. For e.g. reading an entity is a safe, incrementing a counter or sending an e-mail is not.

Idempotent: Doing this multiple times is the same as it doing it just once. For e.g. “a = 1” is idempotent. “a += 1” is not.

Eurovision 2016 round-up

Again, squirrel mindedness means I need to make some records of the ones I liked this year.

Called it – Bulgaria went from outside chance to placing 4th this year:

Belgium brings something different to Eurovision again this year:

Spain, so upbeat!

Stick a bow on it…

What does a love wave look like?

The interval shows…

Monitoring ViewState size

A short and very dirty script I wrote for TamperMonkey that keeps an eye on the size of your ViewState and alerts you if it gets a bit big. I appreciate this could be a lot better written feel free to take and adapt and improve – although let me know as well please!

Don’t forget to change the @match parameter

// ==UserScript==
// @name         Monitor ViewState size
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Monitors ViewState on page and alerts you if it gets big!
// @author       Rob Church
// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser-polyfill.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.min.js
// @match        http://*.yourdomain.com/*
// ==/UserScript==

/* jshint ignore:start */
var inline_src = (<><![CDATA[
/* jshint ignore:end */
/* jshint esnext: true */

    var allowedViewStateSize = 5000;
    var alerted = false;
    
    var viewStateSize = document.querySelector('#__VIEWSTATE').value.length;
    if (viewStateSize > allowedViewStateSize) {
       alert('Viewstate is large: ' + viewStateSize);
       alerted = true;
    }

    window.setInterval(function(){
       var viewStateSize = document.querySelector('#__VIEWSTATE').value.length;
       if ((viewStateSize > allowedViewStateSize) && (alerted == false)) {
          alert('Viewstate has *BECOME* large: ' + viewStateSize);
          alerted = true;
       }
    }, 2000);
    

/* jshint ignore:start */
]]></>).toString();
var c = babel.transform(inline_src);
eval(c.code);
/* jshint ignore:end */

Videos for unit testing / TDD in .net

I recently ran a lunch and learn about unit testing and test driven development. Could not find any amazing videos out there, so we went with these. Any better suggestions please let me know in the comments!

This one is more theory up to about 1 hour, then it gets hands on but with Java.: https://vimeo.com/user28557683/review/153480907/f38b042f2a

Hands on with .net and some great advice for writing good tests, but pretty low resolution: https://www.youtube.com/watch?v=dJUVNFxrK_4

If you have PluralSight, here are some good courses:

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.