gabrewer.com

Life is too important to be take seriously.

Wednesday, November 19, 2014 at 3:39 AM UTC

Display Collection+JSON in the browser

In the last year I have become enamored with Hypermedia APIs and the Collection+JSON API in particular that I first came across in Mike Amundsen’s book Building Hypermedia APIs with HTML5 and Node.  It seems to be a perfect fit for many of the APIs that I have been working on.  Glenn Block created the CollectionJson.Net library to make it easy to create Collection+JSON based ASP.NET Web APIs.

However when I browse to a WebAPI endpoint that returns a Collection+JSON result in Internet Explorer or Firefox I get a prompt to download the file.

image

image

Chrome displays the raw JSON result in a more friendly manner.

image

Although Fiddler or the browser debug tools make it fairly easy to see the results as JSON sometimes it is convenient to see the results rendered directly in the browser.

I found an old post from Rick Strahl’s blog regarding how to display application/json.  He suggests using JSONView for Firefox and adding a registry entry for Internet Explorer.  I was able to easily tweak the Internet Explorer registry keys to handle vnd.collection+json.  Unfortunately JSONView for Firefox will not work for the application/vnd.collection+json media type. https://github.com/bhollis/jsonview/issues/7

For internet Explorer it is just a matter of changing the Content type entered in the registry from application/json to application/vnd.collection+json

Create a new application/vnd.collection+json key in:

  • HKEY_CLASSES_ROOT\MIME\Database\ContentType**application/vnd.collection+json**
  • Add a string value of CLSID with a value of {25336920-03F9-11cf-8FD0-00AA00686F13} (the CLSID for the “Browse in place” action)
  • Add a DWORD value of Encoding with a hex value of 0x00080000
[HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/vnd.collection+json]
“CLSID”=”{25336920-03F9-11cf-8FD0-00AA00686F13}”
“Encoding”=hex:08,00,00,00

image

Now Collection_JSON results will display directly in Internet Explorer.

image

For Firefox it was just a matter of specifying the application to open the media type as Firefox.

image

This adds the application/vnd.collection+json media type to the Applications list in the Firefox Options dialog.

image

And now Collection+JSON results will display directly in the Firefox window.

image

This technique will work for other types of +json media types as well such as Mason (application/vnd.mason+json) and HAL (application/vnd.hal+json).

Friday, September 12, 2014 at 3:39 AM UTC

Setting an IP address using netsh instead of arp -s on Windows 8.1

I recently had to setup many Epson TM-T88V receipt printers for a POS installation and out of the box they are configured with a static address of 192.168.192.168.  Pressing the reset button for 3 seconds prints out the status of the printer including the MAC address so I though I would just use arp –s to configure the printers but I received an error.  So after a some googling with Bing I turned up this article that pointed me to the the fact that you need to use netsh with recent versions of Windows.

First you need to get the name of the interface that the device is connected to.  Then you execute the netsh interface ipv4 add neighbors command.

netsh interface ipv4 show interfaces

Idx     Met         MTU          State                Name
---  ----------  ----------  ------------  ---------------------------
  3          10        1500  connected     Ethernet
  1          50  4294967295  connected     Loopback Pseudo-Interface 1
 63          10        1400  connected     vowire hosting
 10           5        1500  connected     vEthernet (Internal Ethernet Port Windows Phone Emulator Internal Switch)
 29          10        1500  connected     vEthernet (VirtualBox Host-Only Ethernet Adapter Virtual Switch)

netsh interface ipv4 add neighbors "Ethernet" 10.1.10.45 xx-xx-xx-xx-xx-xx

Friday, May 23, 2014 at 9:38 PM UTC

Cool Development Utility - xip.io

I stumbled across a mention of a free service xip.io that spared developers the hassle of editing their host file for every new development web site they needed to setup. Having had to edit the host file many times this really appealed to me. So I went to find out what type of black magic enabled this.

What I found was a very simple and brilliant solution from Basecamp (formally 37signals. xip.io is a public custom dns service that given a [domain name].[ip address].xip.io returns the ip address specified.

For example

www.gabrewer.com.192.168.1.10.xip.io resolves to 192.168.1.10
dev.gabrewer.com.192.168.1.10.xip.io resolves to 192.168.1.10
dev.www.gabrewer.com.192.168.1.10.xip.io returns 192.168.1.10

Since this is a hosted service it works for all devices that have an Internet connection including tables, phones and other Internet connected devices.

I always love it when I find a nice piece of engineering that simplifies my development experience.

Saturday, August 17, 2013 at 8:39 PM UTC

My first pull request - WebApiContrib.Formatting.CollectionJson

In my latest project I am using the great Collection+Json ASP.NET Web API library that Glenn Block put up on GitHub a while ago.  After using it for a while I decided to refactor my code and use something other than an int for my type identifiers.  When I changed to use the generic type, I discovered an issue with the code that had added the generic identifier capability to the library.  The Create method was still retuning an int instead of the generic TId.

So I wrote up the issue on GitHub and Glenn Block immediately responded asking if I was going to submit a Pull Request.  I am still relatively new to git and am still trying to grok it.  But since I had already forked the repository and updated the code, I figured this would be as good time as any to figure how to submit a pull request. 

Even though it was a one line change to the return type of the Create method, I realized that there were no unit tests for the CollectionJsonController class taking a generic identifier value.  So I decided I should fix that as well and created a XUnit test for this scenario by cloning the existing tests with just a Controller that used a string for the identifier.  Once I had the tests and the code working, I went about figure out how to submit my first pull request.

I found an excellent resource that made the process relativity straight forward and painless.  https://www.openshift.com/wiki/github-workflow-for-submitting-pull-requests 

You can find my first pull request (modest as it may be) at

https://github.com/WebApiContrib/WebApiContrib.Formatting.CollectionJson/pull/12#issuecomment-22815387

Saturday, April 6, 2013 at 7:56 PM UTC

Nice JavaScript library for formating numbers and currency

In my continuing effort to really learn JavaScript, I was working on putting together a shopping cart application using JavaScript.  One of the things I needed to do was format some of values as currency. 

So I started looking around at the various techniques to accomplish this and ran across accounting.js a tiny JavaScript for number, money and currency formatting that seemed to fit the bill nicely. 

Now I can just do this.

accounting.formatMoney(12345678);    // $12,345,678.00
http://josscrowcroft.github.com/accounting.js/

Sunday, March 3, 2013 at 3:52 PM UTC

Cisco Nexus 1000V for Microsoft Hyper-V Beta Program and Webinar

I just found this post from Aidan Finn via Damian Flynn’s blog post regarding the webinar and beta program for the Cisco Nexus 1000V switch for Microsoft Hyper-V on March 6th at 12pm EST. 

I am interested in learning what features the Nexus 1000V will provide leveraging the Hyper-V Extensible Switch.  We are currently using the SFlow Agent for Window Server 2012 Hyper-V to monitor our VM traffic and it is great for getting insight into the network utilization of the individual VMs.

Damian Flynn - Cisco Nexus 1000v Public Beta Program

Aidan Finn - Unveil Of Cisco Nexus 1000V Distributed Switch For Windows Server 2012 Hyper-V