Wednesday, September 14, 2016

Selling the house

https://my.matterport.com/show/?m=6SH1cnAxWLr&brand=0

Sunday, June 7, 2015

The Counted

http://www.theguardian.com/us-news/ng-interactive/2015/jun/01/the-counted-police-killings-us-database#

Wednesday, April 8, 2015

Why Ember

http://blog.yodersolutions.com/why-i-recommend-emberjs-over-angularjs/

Saturday, November 22, 2014

Ember.js sucess story

http://www.talentbuddy.co/blog/building-with-ember-js-at-groupon/

Tuesday, March 18, 2014

Asynchronous Repository Pattern

I've been thinking a bit about network and other I/O latency problems and the traditional repository pattern. Started toying with the idea that a repository facade could explicitly expose a "promise-like" interface like the following.


public interface IRepository<T, in U> where T: class, new()
                                          where U: struct
    {
        Task<T> GetById(U id);
        Task<bool> Save(T entity);
        Task<bool> Remove(T entity);
        Task<IEnumerable<T>> GetAll();
    }

Where T is the DTO and U is the underlying identifier type (int, Guid etc.)

This is all essentially client-side whereas the client is communicating with a resource (and perhaps resource is a better name than repository). So for instance, if I was communicating with a ReSTful service - my resource (or implementation of this particular pattern) could look something like the following.(This is currently implemented using RestSharp client using the ServiceStack.Text serializers)


public class RestfulClient<T, U> : RestClient, IRepository<T, U> where T: class, new()
                                                                     where U: struct
    {
        private readonly string _resource;
        private readonly ServiceStackJsonDeserializer deserializer;
        private readonly ServiceStackJsonSerializer serializer;
        private const string requestString = "application/json";
        private const DataFormat requestFormat = DataFormat.Json;

        public RestfulClient(string baseUrl, string resource)
            : base(baseUrl)
        {
            this._resource = resource;
            this.deserializer = new ServiceStackJsonDeserializer();
            this.serializer = new ServiceStackJsonSerializer();
            ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
            this.AddHandler(requestString, new ServiceStackJsonDeserializer());
        }

        private string UrlWithId(U id)
        {
            return string.Concat(this._resource, "/", id);
        }

        private RestRequest FormatRequest(string resource, Method method, T entity)
        {
            var req = new RestRequest(resource, method);
            if (entity != null)
            {
                req.RequestFormat = requestFormat;
                req.JsonSerializer = this.serializer;
                req.AddParameter(requestString, this.serializer.Serialize(entity), ParameterType.RequestBody);
            };
            return req;
        }

        public Task<T> GetById(U id)
        {
            var t = Task.Factory.StartNew(() => 
                this.deserializer.Deserialize<T>(this.ExecuteGetTaskAsync(FormatRequest(UrlWithId(id), Method.GET, null)).Result), 
                CancellationToken.None);
            return t;
        }

        public Task<bool> Save(T entity)
        {
            var t = Task.Factory.StartNew(() => 
                this.Execute(FormatRequest(this._resource, Method.POST, entity)).ResponseStatus == ResponseStatus.Completed, 
                CancellationToken.None);
            return t;
        }

        public Task<bool> Remove(T entity)
        {
            var t = Task.Factory.StartNew(() => 
                this.Execute(FormatRequest(this._resource, Method.DELETE, entity)).ResponseStatus == ResponseStatus.Completed, 
                CancellationToken.None);
            return t;
        }

        public Task<IEnumerable<T>> GetAll()
        {
            var t = Task.Factory.StartNew(() =>
                this.deserializer.Deserialize<IEnumerable<T>>(this.ExecuteTaskAsync(FormatRequest(this._resource, Method.GET, null)).Result), 
                CancellationToken.None);
            return t;
        }
    }


Instantiating the implementation could be as simple as:



var rc = new RestfulClient<ToDo, int>("http://localhost:53327", "api/v1/todos");
Consuming looks like:
rc.GetById(id).ContinueWith((todo)=> Console.Write(todo.Result.Title));
The nice thing is that the consuming client gets all the benefit of .ContinueWith (etc.) I'm not sure if I'm chasing dragons at this point - but I'm mulling it over...thoughts?

Monday, June 10, 2013

Adhering to the DRY Principal in Javascript/Knockout

One of the things that honestly "hurt my feelings" when developing an HTML5 replacement application awhile back - was that the ViewModel needed to be declared in multiple places. Once in the service and again in the client. Of course, all the demonstrations during tech-week seemed to gloss over this with very simplistic applications. Required reading - Pragmatic Principles
Now, there may be ample reason to want to do this -> what I'm enacting upon in the client may require a subset (possibly?) but I would contend that it should probably be a different service call. Don't transfer bytes that you don't need! So I created a static class helper to be used within a Razor template - and proceeded to forgot all about it. 
A colleague from another department heard about/asked me about it and I rediscovered it. Enjoy. As always YMMV. If you improve on it - share it. I'll laud you copiously.

The helper:
public static class HtmlHelper
    {
        private static string JavaScriptify(string s)
        {
            return string.Join(".", s.Split('.').Select(x => x[0].ToString().ToLower() + x.Substring(1, x.Length - 1)));
        }

        public static IHtmlString KnockoutFrom<T>(this HtmlHelper<T> html, T obj)
        {
            var serializer = new JsonSerializer
                                 {
                                     ContractResolver = new CamelCasePropertyNamesContractResolver()
                                 };

            var sb = new StringBuilder();
            sb.Append("(function() {");

            var json = JObject.FromObject(obj, serializer);

            sb.Append("var vm = ko.mapping.fromJS(" + json + ");");

            var type = obj.GetType();

            var ns = JavaScriptify(type.Namespace);
            sb.Append("namespace('" + ns + "');");
            sb.Append(ns + "." + JavaScriptify(type.Name) + " = vm;");

            sb.Append("})();");

            return new HtmlString(sb.ToString());
        }
    }


The template:
@Html.KnockoutFrom(Model)

Friday, May 17, 2013

WSDL service returning DataSet? Seriously?

Just got a 'last-minute' TODO - have to establish another interface for state agency. Like any good developer - I grab the WSDL and 'prop-up' a test service. Imagine my surprise when I see the defined method results as DataSet. Yup. Can be anything - based on nature of the "select" - egads. 

The ONLY reasonable  - and its by NO MEANS reasonable - "theory" that *might* explain this 'design' decision is that auto-generated proxies won't 'break'. (Yea. It's a lame excuse and kinda defeats the purpose of contract-first development) Besides, auto-generated proxies are for the faint-hearted (HTTP/XML for me).

How to generically 'mock' a dataset? Grab NBuilder from NuGet and add to your project. Then add a POCO representation of the fields you wish to return. Then call this:
private static DataSet CreateDataSet<T>(int numberOfRows = 1)
        {
            var datatable = new DataTable(typeof (T).Name);
            typeof (T).GetProperties().ToList().ForEach(
                x => datatable.Columns.Add(x.Name));
            Builder<T>.CreateListOfSize(numberOfRows).Build()
                                    .ToList().ForEach(
                                        x => datatable.LoadDataRow(x.GetType().GetProperties().Select(
                                            y => y.GetValue(x, null)).ToArray(), true));
            var dataset = new DataSet();
            dataset.Tables.Add(datatable);
            return dataset;
        }

soapUI tests against WSDL methods work - now 'back-to-work'!

Tuesday, May 14, 2013

More Hibernation Fun :: Dialect does not support variable limits.


Had a sad-panda moment when I went to Linq to NHibernate with the following (rather straight-forward) syntax.

...

 var e = r.Where(w => w.Name.Contains(searchBy)).Select(c => c).Take(5).ToList();  
...
I bombed out on a simple test - with the exception being "Dialect does not support variable limits." Rather broad base of Google hits on this one...

Seemed like something wrong with the underlying dialect - so I needed to override; something like this:
 public class FixedMsSqlDialect : NHibernate.Dialect.MsSql2005Dialect  
   {  
     public override bool SupportsVariableLimit  
     {  
       get  
       {  
         return true; //because SQL Server DOES support TOP selects  
       }  
     }  
   }  

...


What was unclear was "where" does that go? Quick breeze through source revealed that it was 'set' right after the IPersistenceConfigurer was instantiated - so static method to use for my fluent configuration.
... 


 private static IPersistenceConfigurer PersistenceConfigurer(string connection)  
     {  
       var provider = MsSqlConfiguration.MsSql2005.ConnectionString(connection);  
       provider.Dialect<FixedMsSqlDialect>();  
       return provider;  
     }  
...

Now based on connection string - I can inject the "home-grown" default behavior from my GetConfiguration method.

...
 public FluentHelper(string connectionKey, bool autoConfig = false)  
       : this(  
         () =>  
         Fluently.Configure()  
         .Database(GetConfigurationOption(connectionKey))  
         .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))  
           .ExposeConfiguration((c =>  
           {  
             if (autoConfig)  
             {  
               BuildSchema(c);  
             }  
           })).BuildSessionFactory())  
     {  
     }  
 private static IPersistenceConfigurer GetConfigurationOption(string connectionKey)  
     {  
       string connection = ConfigurationManager.ConnectionStrings[connectionKey].ConnectionString;  
       switch (ConfigurationManager.ConnectionStrings[connectionKey].ProviderName)  
       {  
 ....omitted for brevity  
           default:  
             return PersistenceConfigurer(connection);  
       }  
 }  

Hurray - Linq Take() actually works now.



Sunday, May 12, 2013

NHibernate 3.x changes


Working on a sample project for a perspective company - when enabled NuGet for FluentNHibernate, and saw a breaking change in the NhQueryable constructor. (I've been building from the source for awhile so this one passed me by, 2.x - 3.x introduced some breaking changes)

This breaks:
...
public ReadOnlyRepository(ISession session)
        {
            this.selection = new NhQueryable(session);
        }
....

This 'seemed' to work - at least the compiler didn't complain:
...

public ReadOnlyRepository(ISession session)
        {
            this.selection = new NhQueryable(session as ISessionImplementor);
        }
...

After a few unit-tests later I discover that the session passed in is NOT being preserved. Now what?

So I look at the IQueryOver interface - inside of Hibernate seems to add some Extension methods and a Linq-like interface; but I miss the more "natural" feel of regular Linq expressions. Granted, I won't have as much fine-control over the underlying query - but I'm not doing anything too crazy - yet.

I end-up changing the original interface/implementation from:
 public interface IReadOnlyRepository where TEntity : class  
  {  
      IQueryable Linq();  
  }  
...
#region IReadOnlyRepository Members

         public IQueryable Linq()
  {
   return this.selection.AsQueryable();
  }

#endregion
...

to the 3.x friendly:

public interface IReadOnlyRepository : IQueryable where TEntity : class
    {
        IQueryable AsQueryable(); 
    }
...

Note: The implementation then explicitly marshals the "queryable-ness" to my preserved session.

Also Note: the explicit usage of namespace System.Linq - otherwise it WILL conflict with Hibernate:

#region IReadOnlyRepository Members

        public System.Linq.IQueryProvider Provider
        {
            get { return session.Query().Provider; }
        }

        public System.Collections.Generic.IEnumerator GetEnumerator()
        {
            return session.Query().GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

        public System.Type ElementType
        {
            get { return session.Query().ElementType; }
        }

       public System.Linq.Expressions.Expression Expression
        {
            get { return session.Query().Expression; }
        }

        public IQueryable AsQueryable()
        {
            return session.Query();
        }
        #endregion

Turns out this tripped out quite a few, as I searched the web. Hope this helps someone transitioning from building from source to moving to NuGet.

Why did I ever switch to MSTEST?

Ran into a wicked problem with MSTEST today, resurrected an old project went to run the tests - and boom - nothing appeared to run - very similar to the "cylon" symptom I talked about in 2010. Eventually ran into this wonderment which gave me at least an indication of what was happening (and only 2 days after latest VS2012 update too...hmmm)



So I waded through the following links to try and discover what was happening...

Came across a number of Open, Closed and Unreproducable issues from Microsoft Connect. Then finally a Resharper related post seemed like it was worth trying out (super shoutout to JetBrains forums). 

So I ended up switching from MSTEST to NUNIT and all tests ran. (Big Surprise)
I am reminded of an old song going back to NUNIT...

So how to switch in between NUNIT/MSTEST quickly - use a build directive - NUNIT.
Add the following code to the the head of your test files (or possibly a partial class, or just a plain base-class that all test files inherit from). Then you are basically remapping the MSTEST attributes to the appropriate NUNIT ones. You are rocking with NUNIT - thank you Resharper & StackOverflow. 
(Note: There is no TestContext available in NUNIT so if you rely heavily on that you will have to do something else)


#if NUNIT
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using ClassCleanup = NUnit.Framework.TestFixtureTearDownAttribute;
using ClassInitialize = NUnit.Framework.TestFixtureSetUpAttribute;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif

StackOverflow

http://osherove.com/blog/2010/3/5/nunit-vs-mstest-nunit-wins-for-unit-testing.html

Sunday, September 23, 2012

Entice Me
Opening my eyes and looking around to see what is available. Willing to relocate for the right opportunity or area (I like the coast). I bring a great deal to the table and I'm kinda fun to work with...let's see what we can do for each other.

Curriculum Vitae/Resume
Zerply-Profile 

Friday, June 8, 2012

Ninject + MVC 4

Nothing earth shattering here - but was wrestling with current WCF services and trying to leverage the delicious newness of the WebApi with Ninject 3.0. A bit of pain and a few tears later...
   1:  public class MvcApplication : NinjectHttpApplication
   2:      {
   3:          /// <summary>
   4:          /// Called when [application started].
   5:          /// </summary>
   6:          protected override void OnApplicationStarted()
   7:          {
   8:              base.OnApplicationStarted();
   9:   
  10:              AreaRegistration.RegisterAllAreas();
  11:              FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
  12:              RouteConfig.RegisterRoutes(RouteTable.Routes);
  13:              BundleConfig.RegisterBundles(BundleTable.Bundles);
  14:          }
  15:   
  16:          /// <summary>
  17:          /// Creates the kernel.
  18:          /// </summary>
  19:          /// <returns>IoC container object</returns>
  20:          protected override IKernel CreateKernel()
  21:          {
  22:              IKernel kernel = new StandardKernel(new NinjectSettings { LoadExtensions = true });
  23:   
  24:              // add AutoMapper to the core -> needs to be first; as services will use this.
  25:              kernel.Bind<ITypeMapFactory>().To<TypeMapFactory>();
  26:              kernel.Bind<ConfigurationStore>().ToConstant(new ConfigurationStore(kernel.Get<ITypeMapFactory>(), MapperRegistry.AllMappers())).InSingletonScope();
  27:              kernel.Bind<IConfiguration>().ToMethod(c => c.Kernel.Get<ConfigurationStore>());
  28:              kernel.Bind<IConfigurationProvider>().ToMethod(c => c.Kernel.Get<ConfigurationStore>());
  29:              kernel.Bind<IMappingEngine>().To<MappingEngine>();
  30:   
  31:              kernel.Bind(
  32:                  x =>
  33:                  x.FromAssembliesMatching(new[]
  34:                      {
  35:                          "*.Service.dll", "*.Service.Mvc.dll", "*.Service.Data.dll"
  36:                      }).SelectAllClasses().BindAllInterfaces());
  37:              kernel.Bind<ServiceHost>().To<NinjectServiceHost>();
  38:                          
  39:              // not intended to be used when deriving from NinjectHttpApplication <sigh>
  40:              ////kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
  41:              ServiceLocator.SetLocatorProvider(() => new NinjectServiceLocator(kernel));
  42:              var locator = new NinjectServiceLocator(kernel);
  43:              ServiceLocator.SetLocatorProvider(() => locator);
  44:              return kernel;
  45:          }
  46:      }

Friday, April 13, 2012

Well - its been awhile. I've been mostly tweeting and/or G+ Anyway, new look. New trends. Job Trends 2012

Saturday, June 11, 2011

SheepAOP::SheepAspect

Another aspect orientated framework -SheepAOP now SheepAspect by Hendry Luk.

I'm glad to see someone else in this space. I'm also happy to see that it is derived with an IoC container in mind. Seems straightforward enough - could have some real promise. I will keep this framework in mind for any future projects.

Sunday, February 27, 2011

Building Silverlight Toolkit (again)

Paths I find most useful - especially when compiling SL Toolkit 4.0 from source (on an x64 machine). For whatever collection of reasons (IDE resolving assemblies, poor source-code structure - whatever) I usually end up wasting x hours of my life (usually on the weekend) trying to resolve these things. The Design solutions seem to be the worst offenders. 

The saddest comment I saw posted on the message boards (from a moderator no-less) was along the lines of - "Well, just don't build those projects." 


The sound you just heard was me throwing up, just a little bit...

Anyway - some of magical GAC paths....


(Useful for the little things - like System.Windows and System.Windows.Controls)
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\

(For the Blendability aspects - notice the 10.0 - instead of the 9.0; which is generally how the IDE(?) resolves it)
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\


(For the all the references that look to C:\Program Files (x86)\Microsoft SDKs\Silverlight\v3.0\Libraries)
C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\

I love what SL has done to the CLR - I really do! In general, the IDE is a pleasure to work with but that said....
  • My best advice is stop using the GAC! Use the shared binary folder (only if source is unavailable or overly prohibitive) for the shared dependencies consistently and across the board.
  • Where's the automated batch build? If Code-Plex = MS <3 OS  at least follow some basic principals... 
  • The few tests that there are suffer the same path dependency problems as the rest of the project. (No automated build - or automated tests?) 
  • Developers are your audience - and we are relentless when we don't have a sense of assurance with the project we are working with. It needs to be clear, well-organized and predictable. I've personally abandoned Open Source projects for less than this.
  • Source-tree restructuring - make-over is well overdue. What a bloody-mess! (Take a look at the majority of projects at github if you want to see how its done.)
  • All this being said - I want SL to succeed; but MS needs to want their developer base to succeed. We're paying attention...are you?
Every minute (wasted) compiling/resolving references is a minute NOT spent writing those oodles of apps required to catch up to Apple, oh - no wait - it Android now.
 
Assimilated the new Android SDK yesterday -> was out for about 15 minutes as the emulator changed paths and Eclipse required an update. Just saying...

Sunday, January 30, 2011

KoL Wiki Search

Because the KoL Text search hurts my feelings.




only search the KoL Wiki


*Update: Wiki editors - please steal this code!

Monday, January 3, 2011

Language Trends (Predictions for future?)

Programming Language Trends (Dec. 2010)
Programming Language Trends (Aug. 2010)
 
Not a clue - but interesting to see java in forefront and an increase in objective-c (certainly not my favorite :P)

Shakes fist at iPhone

Saturday, November 27, 2010

Eclipse Update :: Android update :: OS Update

When free-software costs you development time, it's not free - its costing you! Now that I have your attention here's my disclaimer:

I have had equally horrid experiences with other expensive OS' and development tools.

My dilemma has always been with trying to reconcile the differences and find what works best for me.

So who is to blame when a working development environment just "stops" after a week of updates. So Ubuntu had a minor distro release (10.10) - I waited over a month before installing, Eclipse (3.5.2) had a series of seemingly innocuous updates, and the latest version of android development had a minor bump (.7 to .9 release). To make matters even more convoluted, I'm also running an x64 bit OS on top of it all.

What is the issue - the Android project type is no longer available from the Eclipse IDE? Compiler can't reconcile imports, keywords etc. Horrible. So like any good troubleshooter what do I do?

I tinkered with various settings (for awhile - how bad could it be) then I remembered it took less than 30 minutes to set-up before. I un-installed everything (downloaded the latest of all-the-above - installed) - and restarted; no love - no joy - but a slew of half-muttered obscenities.

The real tragedy of this is that I've been working with both Linux::Eclipse and Windows::MonoDroid and I actually preferred the Linux set-up.

It was clean, seemingly more stable (has been a plugin provider for a long time), generally unobtrusive and the resulting program responded better - i.e. very snappy!

So after wasting half-a-day tinkering with Eclipse - I'm removing it completely for now. If I want to develop on the Unix side of things maybe I'll try Netbeans with Android, though it seems younger and potentially more unstable than Windows with MonoDroid (as it is in its .2 release). 

I'm so frustrated at this point - I don't know if I'll continue for today. Ah well, live learn.

UPDATE: Just because I can't leave well enough alone. I figured out a solution to aforementioned problem(s).  This assumes that you've unpacked the SDK to the same path as before (and that you've already added to PATH).

With the new Android SDK - make sure ALL Shell Scripts have execute permissions (under \tools) chmod +x

Completely uninstall everything from Eclipse.

Delete the .eclipse folder under home (with whatever reside exists in there)

Reboot (for good measure)

Run android script (follow Google destructions as before)

Reinstall Eclipse/ADT Plugins/ etc. -> will be golden afterwards.

MORAL: Living on-the-bleeding-edge hurts (just a little).

NOTES: Not at all impressed with NetBeans 6.9 after trying it out - feels like a work in progress.

Friday, October 1, 2010

iPhone and MonoDevelop

Seems that initial reports (back in April) about Apple dropping support for anything but Objective-C was aimed primarily against Adobe - and not Novell. So MonoDevelop (w. MonoTouch) can still be the choice development-platform for i(Whatever) applications. Full article (complete with dispelling misconceptions, etc.) stumbled upon here.