Friday, February 27, 2015

Javascript: wrapping sync calls in a promise to they can be chained with async calls

Another StackOverflow answer that was recieved well by the person who asked the question was my answer on this question:

Here's the question:

So he's basically doing a bunch of async calls mixed with synchronous operations / mappings. In order to get a nice clean call chain - I wrapped all the synchronous things in a promise wrapper, so that all promises could be nicely chained:

Here's the direct link to the fiddle:

Thursday, February 26, 2015

Deploying bundled/minified AngularJS Application to Azure

I was awarded some of the bounty on the question: "Deploying bundled/minified Durandal Application to Azure". I responded describing how we optimized an AngularJS application at one of the major bank in Holland. 

Sunday, February 22, 2015

(De) serializing objects with private / protected properties using XmlSerializer, DataContractSerializer and Newtonsoft.JSON

So since I 'discovered' that objects with private / protected properties can be handled by Entity Framework, I needed to make sure they can also be serialized and deserialized properly. Because in my unit tests I do not want to test the database connection, I often make use of serialized objects that I use for testing.

However, not all libraries that handle serialization can work with private / protected properties. So here's a comparsion of:

  1. System.Xml.Serialization.XmlSerializer
  2. System.Runtime.Serialization.DataContractSerializer
  3. Newtonsoft.Json

In case you're curious: I'll be using Newtonsoft.Json from now on. 2 reasons: clean serialization format, and no modifications required on the class declaration.

Cannot work with private properties. Will throw an InvalidOperationException during deserialization.

Will deserialize an object properly, in case the class has the [Serializable] attribute. If this attribute is NOT present, the private / internal / protected / and protected internal properties are NOT serialized. So beware.

Downside: property serialization is verbose and very ugly:

<_x003c_name_x003e_k__backingfield>John Doe

But it will work.

Works out of the box with any access modifier. Also - the serialized format is very clean:
  "Id": 0,
  "Name": "John Doe",
  "ProtectedProperty": "Protected",
  "PrivateProperty": "Private",
  "InternalProperty": "Internal",
  "ProtectedInternalProperty": "ProtectedInternal"

NOTE: I did not do any type of performance benchmark, since I'm not really interested in it in the case of unit testing. Also - I did not look into serialization formats that are impossible to read ( binary or protocol-buffers )  since I want to be able to look at the data I'm using while testing.

Friday, February 20, 2015

Entity Framework works fine with private / internal / protected properties

This was probably just me, but I was always under the impression the EF had a hard time hydrating objects with private or protected access modifiers. Turns out not to be the case, at least not in EF 6.

I was looking around for solutions, but noticed that all solutions to - what I thought was a - problem, were pretty old. So I wrote a quick test to see how EF behaves nowadays.

Turns out: any access modifier can be hydrated from EF - no problem.

Here's my model:

Here's the roundtrip test - as you can see - the person coming from the database has all the properties set as expected:

Just for visual verification: everything is nicely in the DB. Although that's not what I was worried about.

Wow - I feel like a n00b not knowing this before.

Windows 8 on MacBook Pro: 1 core @ 100 %

I've noticed that one of the cores in my MacBook Pro was constantly at around 90 - 100 %. The list of processes showed that it was the system process.

Inspecting the processes with ProcessMonitor showed that is was ACPI,sys - as mentioned here, however - I couldn't find any drivers that could be updated in order to fix anything.

Turns out it's a more common problem on macs:

Someone on this forum thread suggests to make the computer go to sleep and wake it up again:

which worked like a charm for me:

Wednesday, February 18, 2015

My colleague is running some data-analysis tasks in R and has come up with an analysis that takes 4 days (!) on a dataset of 1.000.000 entries.

I'm looking into his R code to see if I can optimize this - because 4 days comes across as a bit much. So I had to dig up my Big-O knowledge again and came across this great reference website: 

It gives an overview of the time complexity of sort and search operations for different algorithms.

Thursday, February 12, 2015

>1 K StackOverflow rep :)

By trying to answer more questions on StackOverflow - I set a goal to reach 1K reputation and I did it. Nerd achievement :)