This is an example of a Optin Form, you could edit this to put information about yourself or your site so readers know where you are coming from. Find out more...


Following are the some of the Advantages of Opt-in Form :-

  • Easy to Setup and use.
  • It Can Generate more email subscribers.
  • It’s beautiful on every screen size (try resizing your browser!)

Thursday 28 November 2013

// // Leave a Comment

SVG text in boxes with Snap.svg

SVG differs from the HTML5 that you're used to in lots of ways. One of which is text. One requirement I had was to create a box round an arbitrary length of text, like this:
That's pretty easy in a DIV with some CSS and it's not difficult in SVG, just different. We're going to use the Snap.SVG library to implement it.

The code

First we create the box, add some style. Then we create the text, then some style. Finally, we update the width of the box using the width of the text.

JSFiddle Live example.

Group to join together

The resulting SVG is just two elements that are happened to be one on top of the other. The text is not actually contained in the box, it's floating on top. Unlike a DIV, if you were to add drag functionality to the box, the text would remain exactly where it is. To do this, you need to use Snap to group the elements together. Then you can then assign the drag functionality to the group and it behaves normally.

Changing the length of the text

If you were to change the text in the box, you would need to manually update the width of the container too. DIV do that automatically with flow but you don't get that in SVG. If that kind of text flow is required, you might want to avoid SVG altogether and stick with a mix of HTML and SVG.
Read More

Wednesday 27 November 2013

// // Leave a Comment

Using Snap.svg to create a box that snaps to a grid

I reviewed Snap.svg, the SVG javascript library as my favourite of the current tranche of libraries. This post begins an exploration of how to do simple things in Snap. First we're going to create a square and give it drag behaviour. Then we're going to update the drag behaviour to make it snap to a grid.

Basic Dragging

The first task is to create a square and make it draggable. In Snap, that's very simple:

Working example. The rounded-corner square is made, some attributes are set and then it is made draggable. Very simple.

Snapping to Grid

The next task is to make the box snap to a grid:

Working example.

The drag function is passed two handler functions, the first is called when dragging is happening and the second when drag starts. We use the Snap function snapto to work out the new x and y position of the box. We have to store the original position of the box because it is not passed into the method anywhere.

I do not like having the orig global variable to store the location of the box. I appreciate that this is used temporarily but global scope variables feel dirty. One solution to this is to wrap the whole lot in a function so that the scope of the orig variable would only be in that scope. I would prefer Snap to store the origin and pass it to me.

Dragging with the transform method

SVG elements have a transform attribute that take the original description of the SVG object and transforms it automatically. I needed the original x and y to change, so rejected the transform method. Perhaps this could still be performed with a "drag stop" method that takes the transform and applies it to the original but for simplicity, I will leave it as-is. The transform method looks like this:

Working example. This is the method that is used in the Snap.svg source code.

The problem with drag

I would prefer that drag accepted a context object that had named methods, rather than relying on the order of parameters. Drag would look more like this:

Please note your version! I am writing this in November 2013, the API version is 0.1. There may well be a better way to do this by the time you read this.
Read More

Tuesday 26 November 2013

// // Leave a Comment

Entity Framework upgrade to 6 configuration and nuget magic

This post discusses the update from Entity Framework 5 to 6 and where where must be vigilant in the face of nuget's magic.
TLDR; Nuget doesn't update .config if there is custom config and setting the Copy Local property on the reference didn't change the actualy csproj file.
Nuget package manager is a wonderful thing. It allows you to simply manage all the of the packages in the solution, update them all automatically, include other dependencies and so on. Wonderful! Glad to have it in the workflow. However, this magic can be dangerous too. Relying on nuget and assuming that it can do no wrong means that debugging problems takes longer because you don't start with it.

The EF Upgrade

I assigned a junior member of the team to perform the upgrade of Entity Framework from 5 to 6 on our greenfield application. We're not live anywhere and are code-first so the database can be deleted each time. We manage Entity Framework (like all our favourite external libraries) with nuget. We did our reading and watched the MSDN video and were prepared.

The upgrade was simple enough, with some namespace changing and when the unit and integration tests went green, the update was committed through TFS gated checkin and all was good.

Missing config blows up integration tests

We use a local Team Foundation Server instance to manage our integration builds. The cloud TFS server orchestrates the integration build and the integration tests are run against a local virtual machine that mimics a live environment as closely as we dare (or can afford!). However, the test kept going bang. The TFS cloud window won't show you the stack trace of a local build (yet) but you can retrieve it through Visual Studio 2013. The message I got was quite clear:

System.InvalidOperationException: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

Nice error message, so I followed the instructions and put the configuration in. Nuget usually sets up the configuration for you but it could not in this case because we already had some existing configuration. Nuget does not mess with existing configuration. The error went away but was replaced by a new error.

DLL not copied blows up integration tests

The integration tests were still not happy. This was the error:

System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

When a type cannot be loaded for a DLL that is referenced in a project, it usually means that it has not been copied to the output bin/ directory. When you're not using a type from a referenced library, it will not be copied. That's expected behaviour, when you're linking DLLs dynamically (through reflection), you need to tell .NET that the DLL must be copied.

To ensure a DLL is copied to the output folder, go to the properties of a reference, you will see a property Copy Local. This must be set to true. False means that it will only be copied if there are types being used, which is usually what you want - there's no point copying DLLs across if the code inside isn't being used. More info on it default value here.

For me, that meant that EntityFramework.SqlServer wasn't being copied.

Nuget sets Copy Local property to true but .csproj is not updated

I checked the properties of the EntityFramework.SqlServer reference and it was set to true. Being suspicious, I also checked the .csproj file in a text editor and found that the "Private" property (which represents Copy Local) was not set at all. Changing the property in the Visual Studio 2013 properties window created the tag in the .csproj.

Copy Local was not enough

A quirk that I have not got to the bottom of yet is that Copy Local is not enough to ensure that Entity Framework 6 can find the Sql Provider. The final step was to reference a type in the base domain context (which overrides the databasecontext you get from EF). This is echoed elsewhere, on this Stack Overflow answer. I hate it, it's crazy but I'm out of time and this does work.

Things to learn

The integration tests blowing up on the server means the way in which we develop code has gone awry. The learning point for us here is that nuget is great but don't ignore it when you're investigating issues. If something feels like the install or upgrade went awry then check there first, don't assume it's all gone OK.
Read More

Thursday 21 November 2013

// // Leave a Comment

SVG Libraries as of November 2013

Support Vector Graphics (SVG) allows us to create vector images on the browser. Support is pretty good on modern browsers. The difference between Canvas and SVG is best described on Wikipedia. Interacting directly with the SVG document object model (DOM) sounds like a nice low-level computer science thing to do but in industry, it's best to use libraries constructed by others to take over some of the heavy lifting.

TLDR; I'm going with Snap.svg. It's new but based on a mature library.

This is a round up of the best three libraries I've found as of November 2013.

jQuery SVG

jQuery SVG by Keith Wood is a series of extensions to the jQuery framework for handling SVG. jQuery works brilliantly for working with a DOM, so it is only reasonable to assume that SVG (which uses a DOM) should also be suitable for jQuery too. The documentation is good, there is a community and plenty of examples.

The syntax for building and animating is sensible:


Working Example. My concern with jQuery-SVG is that the last update was in April 2012, for jQuery 1.7. This does not feel like a project that has someone owning it under active development.

Raphael

Raphael by Dmitry Baranovskiy is a well established SVG library that acts as an abstraction in front of SVG and VML (used in IE6 and 7). If you need to support older browsers, it's the best choice. The problem with supporting older browsers is that it is very difficult to implement modern SVG functionality and still support IE6 and 7.

The syntax for building and animating a rectangle is neat too:


Working example. For my project, supporting older browsers is not a requirement. Raphael is still well supported and there is documentation, but I didn't get on well with the docs: I needed more concrete examples of use of the various elements and how they fit together. That's a matter of taste, you might get on better.

Snap

Snap.svg is also by Dmitry Baranovskiy and is supported by Adobe (since Dmitry was hired by their Web team - fair play!). Snap shares a lot of code with Raphael and is identical in places. Snap drops support from IE6/7 and is lighter for it. The interface is much like Raphael.

The interface for building and animating is simple:


Working example. The current version of the Snap framework is 0.1 and usually this would set off alarm bells. I am not concerned in this case as Snap is based so heavily on Raphael that it brings with it a long history and support community. Snap is going to be my choice.

Not d3.js?

D3.js is an excellent library for representing data. Although it does have a nice API and a framework, I do not need the data visualisation pieces, I just need a lightweight layer over the top of SVG. I am sure that D3 can be used in that way but I think that it not meant for that.

Other Libraries

SVG Web is not updated enough. Processing.js is great for data visualisation but not quite what I needed. Dojo looks light on support and I can't find out how often it is revised. SVGKit has a bunch of libraries and is cross-browser but appears to be rarely updated. Plotkit looks neat but last updated 2006. Pergola is all about building whole apps in SVG, which is a sledgehammer for my particular nut.

Further Reading

Read More

Friday 2 November 2012

// // Leave a Comment

Noam Chomsky: Where AI went wrong

Noam Chomsky was interviewed by the Atlantic. The article is well written but biased towards Chomsky's viewpoint. I think the title of the article is ridiculous, but that's the modern media for you. It's inflammatory, over-reaching and ignorant. AI may have fractured but it's not gone wrong. Gone wrong is when your toaster decides your dog needs to die. I do like Chomsky's viewpoint that:
"new AI" -- focused on using statistical learning techniques to better mine and predict data -- is unlikely to yield general principles about the nature of intelligent beings or about cognition
Which is quite true and has been eating away at me for some time. My dynamic neural networks, although used for clustering and classification, have the potential to simulate more organic systems. The way I actually treat my algorithms is without due care. I'm less bothered with finding maxima but investigating the dataset to see what there is. Novelty and discovery are more important to me than function approximation or reasoned logic. My latest batch of code (written in javascript) has the facility to give the network neuron damage to see what the affect on learning is. Optimisation it certainly isn't. It's a child-like approach to investigation (and mathematics!). What the article did for me was hold up a mirror. Some years have passed since graduating with my PhD, I'm still fascinated by my wobbling algorithms but have struggled to grasp why. Now I think it might be that I am more interested in the biological parallels than using them to predict, cluster or classify. The parallels are bi-directional. Steal more from biology, understand a little more.

Action

With that in mind, I can see my own research with greater lucidity. It's OK not to worry about something's ability to classify or cluster, what other biological parallels can I draw. Firstly, I think neurons with different properties (rather than homogeneous ones) might work well, as might limits on connectivity. That would better represent the physical limits of the real world. I'm very much thinking out loud now, which leads me into trouble.
Read More

Thursday 16 August 2012

// // Leave a Comment

Q&A with Luke Muehlhauser, CEO of Singularity Institute

An interesting reddit Q&A session with Luke Muehlhauser, the CEO of the Singularity Institute. He answers questions from "What if we make something more intelligent than us?" through to questions on morality and friendly AIs. The questions and the answers are interesting throughout.

Singularity Institute

The Singularity Institute is an interesting research organisation that focuses on creating AI in such a way that we don't destroy ourselves as a civilisation. The idea of friendly AI and ethics is an interesting one. As an algorithm-based researcher, my focus is rarely on the ethics but the efficiency of the algorithm.

This area of AI is known as AI Risk and a term you'll see a lot is Intelligence Explosion, where learning machines are capable of exceeding their original configuration and programming.

Should I stop doing AI?

No. However, it's definitely worth bearing these ideas in mind before starting a simulation.
Read More

Wednesday 11 July 2012

// // Leave a Comment

Microsoft Research: Machine Learning and Intelligence in Our Midst

This is an interesting video from Eric Horvitz at Microsoft Research that covers a little on the use of Inference Networks. Real world applications include traffic prediction and hospital admission. Eric also talks about how they constructed a model for the receptionist of the MS Research building. Video below the jump.
Read More