RambleJam

My little rambles in cyberspace …

Entries Comments


Mechanican Keyboards – Ducky Shine 3

30 January, 2014 (03:29) | Computing, Deployment, General Jamblings | No comments

Well well …

I might be showing my age with this post but I don’t care frankly. I recently broke, I couldn’t take it any more. I’m officially sick of shit computer keyboards. As a developer I spend a lot of time in front of a keyboard. I type a lot. Years ago I remember using an old terminal style machine, far from anything fancy but sheesh the keyboard. The keyboard was frankly epic, turns out it was one of the now classic IBM Model M jobbies. So What?

Well, I never typed with so much accuracy since that beast was callously taken from me. Urgh!

Today we are brainwashed with always getting the best deal – read “cheapest”. Yay! I saved X number of Dinari for my life story, big deal. The IBM Model M ironically ISN’T a mechanical keyboard but a resistive spring loaded affair. Anyway, I can’t be arsed with the details frankly it had an epic feel, like a futuristic typewriter from a parallel universe in comparison to the shite that Dell et al shove out the door in a minute by minute basis.

Anyway, what did I do about it? I just received my order from Overclockers.co.uk. I proper Cherry MX Blue stuffed Ducky Shine 3 Mofo. Dreamlike. I nearly went with Filco Majestouch but the TenKeyLess (TKL- no number pad) Ducky won that particular battle and I’m now typing this on it. Tactile, Small and fully featured (a bit like me actually).

Don’t hesitate, buy one, your figures will love you forever … the Ducky Shine 3 will probably also out-live your fingers btw … but at £118 isn’t for everyone. I spend at least 12 hours a day bashing away at keyboards so I can justify it easily, either way have a look. It really is a joy to use.

Code Review Hell

7 October, 2013 (10:16) | Computing | No comments

The subject of code reviews for developers can produce many reactions ranging from abject horror to complete disinterest. And that’s before the code review has even started! The following article makes for some really good reading on the topic and should be read by everyone involved afaic.

EFFECTIVE CODE REVIEWS

CI Process – Why?

4 September, 2013 (10:09) | Computing, Continuous Integration, Deployment | No comments

Why is having a CI process good?

There are so many reasons why CI is good. I use it on everything I do. For my recent web based project it’s simple a must have. Forcing you to take an application and pipe it through a series of standardised processes is invaluable. In regards to web applications I go through the full monty. The process I use is:

  • Dev & Debug in Visual Studio
  • run unit tests locally
  • commit to SVN
  • TeamCity Debug Build (Unit Tests included)
  • TeamCity Debug Build with ReSharper Code Inspections and FxCop
  • TeamCity Release Build with NuGet Artifacts
  • Octopus Deploy to local IIS for Staging

I do this even though it’s only me on the project. A web application should be sturdy enough to make it through this process and flourish at the other end of the process. It helps keep things robust, transferable, repeatable, tracked and traceable. All good things for software!

Obviously the quality and coverage of your unit tests is a key element in the process but the pipeline described above is also key to ensuring that an engineered process is always taking place, the randomness is removed entirely. Ideally the build process should be occuring on separate machine as the environment it’s being integrated in is same environment it’s designed in which isn’t ideal but arguably less troublesome than doing it with a desktop application complete with windows installer.

The next step to be added to this process is something along the lines of Selenium automated tests to run against the website itself.

MVC Deployment – JavaScript – ReferenceError is not defined …

31 August, 2013 (14:07) | ASP.NET MVC, ASP.NET WebAPI, Computing, Continuous Integration, Deployment, JavaScript, Visual Studio 2012, Web Stuff | No comments

This had me stumped for a moment.

All the Javascript was there (linkable from bundle links in the page source), all the files were there, everything worked in dev (doesn’t it always?).

Anyway, if you’re seeing this error in your deployed applications there are a couple of steps to take.

Firstly you should download and install the Visual Studio tool JSLint.VS2012. Then set this up to show warnings and don’t set it up to fail the build. JSLint is not kind and very strict about things (your adherence to BP is your choice but recommended for sure!)

So, you deploy your app and BANG all your lovely JS is twatted. Never fear … pop over to your web apps Global.asax file and in the Application_Start method include this:

BundleTable.EnableOptimizations = true;

So now with this setting set you can launch your app in debug mode with all the Optimizations forced on to test minification and more closely model your testing to the deployed version.

Once you have that working and are seeing the problems more clearly you can start to work through the potential issues using the reports from your new JSLint VS plugin to fix the syntax and other formatting issues.

MVC – Display Version Number in Your UI

29 August, 2013 (11:01) | .NET / C#, ASP.NET MVC, Computing, Deployment, Web Stuff | No comments

If you ever want to display the version of your app in the UI (useful in development with lots of environments) you can do the following.

In your Global.asax start method you can add:

Version version = Assembly.GetExecutingAssembly().GetName().Version;
Application["Version"] = string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision);

This somewhere in your site UI you can do this:

@HttpContext.Current.ApplicationInstance.Application["Version"]

Build Process – TeamCity, NUnit, dotCover & Octopus Deploy

28 August, 2013 (13:12) | Computing, Continuous Integration, Deployment | No comments

I’ve blogged about TC a bit in the past but I’ve just setup a whole new build process for my current project.

Added into the mix these days is dotCover and Octopus deploy. Have to say that I’m seriously impressed with the simplicity of this flow to release. Still a few elements of Octopus Deploy to get my head around (deceptively simple tool!). Anyway, as ever getting some of the reports configured took a while …

Get your coverage filters right in TeamCity:

+:<SomeString>*
-:*Test

If for instance your project is called JamSoft and all your application dlls are called JamSoft.blah or JamSoft.blah.blah then somestring should be “JamSoft” and of course you’ve suffixed all your test libraries with .Test haven’t you … :)

Unless you already have a tool you’re using I found the TeamCity internal instance of dotCover a good solution. I tried to get NCover 1.5.8 working and just gave up in the end, it’s old and getting problematic as far as I’m converned and since the TC internal solution is available use it. Saves some potential headaches.

I also had a few teething problems getting NUnit working this time around. I was using an installed version of NUnit 2.6.2. However on first build in TeamCity it could completely the initial compile process as it couldn’t find the dlls. I ended up switching over to using a NuGet NUnit package and then the compilation steps were fine. Bit odd since I was running the TC builds on my development machine so NUnit was definitely available.

As soon as I’ve got a couple of things ironed out with my use of Octopus Deploy I’ll no doubt blog about that as well, however for now I’m total noob so …

Entity Framework Code-First Stored Procedures & Foreign Key Entities

16 August, 2013 (19:41) | .NET / C#, Computing, Entity Framework | No comments

I was recently looking at some changes I’d made to a project I’m working on using the Entity Framework for data access. I realised that as I had moved to using a stored procedure for the data retrieval I had lost the immediate loading of some of he object related by foreign keys. If you want to load the related entities, don’t do this:

var searchResults = _context.Database.SqlQuery<MyObject>("GetMyObjects" @UserId", inputTerm);

Do this! :)

var searchResults = _dbSet.SqlQuery("GetMyObjects" @UserId", inputTerm);

Executing the stored procedure on the DbSet rather than the DbContext object will load the foreign key related entities.

Tip: If your entities still aren’t loading, check to make sure you have marked them as virtual in the entity class:

public virtual Organisation Organisation { get; set; }

Using HttpClient to Send Dates in URL Using AttributeRouting

9 August, 2013 (09:11) | .NET / C#, ASP.NET MVC, ASP.NET WebAPI, Computing, Serialization, Web Stuff | No comments

After doing a lot of reading it appears that it is possible to do what I was attempting to do but it requires relaxing a lot of useful security measures in order to do so. Since there is a simple workaround it just doesn’t make sense to relax these measures in light of increased security risks.

The error I was getting at the API was:

A potentially dangerous Request.Path value was detected from the client (:)

Obviously this is the colon characters used to separate the elements of the time portion of the DateTime string. So I have made the following changes.

My Api action method now looks like this:

[System.Web.Http.HttpGet]
[GET("range?{startDate:datetime}&{endDate:datetime}")]
public HttpResponseMessage Get(DateTime startDate, DateTime endDate)

The dates are now defined as part of the query string rather than parts of the path itself.

To handle the creation of the query string I also have the following extension method:

public static string ToQueryString(this NameValueCollection source, bool removeEmptyEntries)
{
    return source != null ? "?" + String.Join("&", source.AllKeys
        .Where(key => !removeEmptyEntries || source.GetValues(key).Any(value => !String.IsNullOrEmpty(value)))
        .SelectMany(key => source.GetValues(key)
            .Where(value => !removeEmptyEntries || !String.IsNullOrEmpty(value))
            .Select(value => String.Format("{0}={1}", HttpUtility.UrlEncode(key), value != null ? HttpUtility.UrlEncode(value) : string.Empty)))
        .ToArray())
        : string.Empty;
}

Which is used in my client code like this:

var queryStringParams = new NameValueCollection
    {
        {"startDate", start.ToString(_dateService.DefaultDateFormatStringWithTime)},
        {"endDate", end.ToString(_dateService.DefaultDateFormatStringWithTime)}
    };

var response = httpClient.GetAsync(ApiRootUrl + "plots/range" + queryStringParams.ToQueryString(true)).Result;

The date service in my application simply provides the default date formatting string and uses this pattern:

“yyyy-MM-ddTHH:mm:ss”

The complete URI that is produced from this looks like:

http://localhost:51258/plots/range?startDate=2013-07-30T21%3A48%3A26&endDate=2013-08-06T21%3A48%3A26

C# Query String Builder

7 August, 2013 (09:06) | .NET / C#, ASP.NET MVC, ASP.NET WebAPI, Computing, Web Stuff | No comments

Here is a nice little extension method for building your query strings in C#


public static string ToQueryString(this NameValueCollection source, bool removeEmptyEntries)
{
    return source != null ? "?" + String.Join("&", source.AllKeys
        .Where(key => !removeEmptyEntries || source.GetValues(key).Any(value => !String.IsNullOrEmpty(value)))
        .SelectMany(key => source.GetValues(key)
            .Where(value => !removeEmptyEntries || !String.IsNullOrEmpty(value))
            .Select(value => String.Format("{0}={1}", HttpUtility.UrlEncode(key), value != null ? HttpUtility.UrlEncode(value) : string.Empty)))
        .ToArray())
        : string.Empty;
}

SQL Install error occurred creating the configuration section handler

23 June, 2013 (23:51) | .NET / C#, Computing, SQL | No comments

Seeing this error … fear not …

Delete the “C:\Users\{Username}\AppData\Local\Microsoft_Corporation\” folder (Replace {Username} with your user name

I kid you not … ridiculous frankly.

« Older entries