Tuesday, June 09, 2015

Austin .Net User Group Pictures from June 8, 2015

Chander Dhall spoke to the Austin .Net Users Group last night about JavaScript. Here's two pics. The room actually filled up after I took the first one so it was Standing Room Only. Chander was an entertaining speaker and really showed how JavaScript is really weird. My cryptic notes for the evening:
Use Xamarin tools for coding Android and iOS apps in C#
UserGroup.tv has lots of tech videos.
Chander had no powerpoint, just raw code.
JavaScript is not going anywhere.
Angularjs is having problems, so reactive is getting some traction to replace angular.
You really need to understand the weirdness of JavaScript - frameworks are not going to solve your problem.
The answer is IIFE.

How to remove Perforce from the right-click context menu in Windows 7

When I right-clicked on a file in Windows Explorer it took an agonizing 8 seconds for the context menu to appear. I noticed that "Perforce" was in the context menu.

 I tried to go to the control panel and modify the P4V installation to remove it, but windows whined about not being able to find a log file. No dice.

So I did the next best thing. I renamed the actual program from P4EXP.dll to something else in C:\Program Files\Perforce\P4EXP. My context menu now appears in under a second.

I'll let you know if this causes downstream perforce weirdness, like files with two heads or three arms.


Wednesday, May 20, 2015

Windows 7 Outlook issue: "ost is in use and cannot be accessed".

I got to work early today, ready to get to work, and was greeted with this cheery note from my Windows 7 box when opening Outlook:

"The file C:\Users\username\AppData\Local\Microsoft\Outlook\username.ost is in use and cannot be accessed. Close any application that is using this file, and then try again. You might need to restart your computer."

Restarting the box did not help. I had to open the "Windows Task Manager" (Ctrl-Shift-Esc), select "Lync.exe" and kill it (you might also need to kill "Communicator", "ucmapi", or "Outlook" itself). Then Outlook was happy and I could start my day.

This morning's ambush reminds me of Cato hiding in wait for Inspector Clouseau to return so Cato can attack him, just to keep Clouseau sharp.

Friday, May 15, 2015

Testing .Net C# WebAPI methods with NUnit and HttpResponseMessage

I recently wrote my first NUnit test for a .Net WebAPI controller. I learned two interesting things. (The code has been simplified to be more explicit).

1. When you create your controller, set a value for it's "Request" object.

//helper function to create testable "projects" controller
private ProjectsController GetTestProjectsController()
{
    ProjectsController controller = 
         new ProjectsController(logger, new ProjectRepository())
    {
        Request = new HttpRequestMessage()
        {
            Properties = { { HttpPropertyKeys.HttpConfigurationKey, 
                 new HttpConfiguration() } }
        }
    };
    return controller;
}

2. When retrieving an object use the TryGetContentValue() method to extract the returned value as a C# object. Notice on line 18 we free the C# object from the clutches of the evil HttpResponseMessage object.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[Test]
public void GetTestWithExistingProjectName()
{
    string projectName = "GetTestWithProjectName";
    var projectRepository = new ProjectRepository();

    // Arrange
    DeleteProjectIfItExists(projectRepository, projectName);
    var newTestProject = CreateNewTestProjectAndWriteToRepository(projectName,projectRepository);
    var controller = GetTestProjectsController();

    // Act
    HttpResponseMessage httpResponseMessage = controller.Get(projectName);

    // Assert
    Assert.IsTrue(httpResponseMessage.IsSuccessStatusCode);
    Project project = null;
    httpResponseMessage.TryGetContentValue(out project);
    Assert.AreEqual(projectName, project.Name);

    //cleanup
    DeleteProjectIfItExists(projectRepository, projectName);
}

This is the code for the api GET.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
public HttpResponseMessage Get(string name)
{
    var project = _projectRepository.GetProjectByName(name);
    if (project != null)
    {
        return Request.CreateResponse(HttpStatusCode.OK, project);
    }
    return Request.CreateErrorResponse(HttpStatusCode.NotFound, 
            "Sorry, the project '" + name + "' could not be found.");
}

Special thanks to the folks at hilite.me for their awesome code highlighter site.

Tuesday, April 21, 2015

The Power of Culture and Public Education

I watched a documentary about Able Archer, the 1983 NATO exercise that was misunderstood by the Soviets, who almost launched a full scale nuclear strike.

One of the most interesting parts was an interview with an older Soviet women. She could not understand why all the world wanted to destroy her beloved Russia which was only trying to bring a better way of life to the oppressed.
Here was a women living in the "Evil Empire", an empire that invaded countries without provocation, routinely used torture, had a vast surveillance state, had secret courts with secret trials, overthrew democratically elected governments, and was run by an elite for the elite.

Yet since she had grown up with the state education, watched the national news and was surrounded by her culture, she thought Russia was the "Good Empire".

Friday, March 13, 2015

A Human Colony on Mars? Not So Fast.


In 1698 the Scots, in a frenzy of nationalism,  invested an enormous amount of money, 20% of the entire nation's money, on a  quest to colonize Panama.  The project failed spectacularly two years later due to disease - a condition that could easily have been foreseen, but Scots neglected due diligence and wasted many fortunes.

I fear our country is neglecting due diligence on our space colonization efforts.

For the long term human survival on Mars, the big question is not whether we can build shelters against the deadly radiation, or grow our own food in hostile soil or can we get water, but can a human fetus grow to adulthood in 38% gravity.  I doubt it.

Astronauts staying aloft in the International Space Station for extended periods have many physical issues like heart, bone, and eye problems. Many, many questions need to be answered, like "Since Martian-born humans would probably be taller with thinner bones, would the volume of marrow inside those bones make the appropriate amount of blood?".

We need to fund something like the Mars Gravity Biosatellite before spending any more money on a manned trip to mars.  Conceptually we need to put mice in 55 gallon drum  in the International Space Station spinning just fast enough  so the centrifugal force simulates Mars gravity.  Let's see if the mice can survive and reproduce two generations.  It would be better to know now if earth mammals can reproduce in 38% gravity than after we have spent an astronomical amount of money.

 I personally would rather NASA be spending our precious space dollars on sending robotic craft to all the moons in our solar system and building telescopes, instead of a project which, like the Scotish colonization of Panama, may be doomed from the start.


Json.NET Error: Could not create an instance of type IAmAnInterface

While using NewtonSoft's excellent Json.NET library, I was trying to deserialize a dictionary containing interface objects and got this error message:

"Could not create an instance of type IAmAnInterface. Type is an interface or abstract class and cannot be instantiated. "

Fortunately Json.NET has a very easy way around this by telling it to save the type metadata in the output.  To serialize the dictionary:



        static readonly Object Locker = new object();
        public void Save()
        {
            lock (Locker)
            {
                File.WriteAllText(reportFilePath,
                    JsonConvert.SerializeObject(_dictionary, Formatting.Indented, new JsonSerializerSettings
                    {
                        TypeNameHandling = TypeNameHandling.Objects,
                        TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
                    }));
            }
        }


To bring the objects back:

         public void Load()
        {
            _dictionary = JsonConvert.DeserializeObject>(File.ReadAllText(reportFilePath),
                new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.Objects
                });
        }



This does make the json file larger, but for us, it's well worth the price.