F-150: Every Day Carry

Recently I discovered reddit.com/r/VEDC, a community dedicated to discussing essential tools and supplies one should carry in their vehicle at all times – your “vehicle every day carry.”  I made a post in r/VEDC, but I will share it here as well.  I like to keep my truck pretty well stocked with tools and supplies that I may need to handle a car emergency, breakdown, or minor injuries.   Just about every item in my vehicle inventory has been used, or I was in a situation where I wish I had a certain tool or item so I added it to the collection for the next time.  I found some inspiration from the internet as well as from real world experience.  Flat tires, dead batteries, and small repairs are common when driving and camping in the Arizona mountains and desert.  I need to be able to repair my vehicle, or remain safe until help can arrive.  It’s also not uncommon to find a stranded motorist when off-roading, so I like to be able to offer help when possible.

First, the truck – a 2013 Ford F-150 3.5 EcoBoost:


And what isn’t pictured is probably the most important safety item you should be be carrying – water.  Living in Arizona this is especially important.  I learned this quickly after moving to this state when a serious accident backed up a mountain highway in both directions for miles.  It was summer, and highway patrol officers were walking up the highway, handing bottles of water to the motorists.  An unplanned extended stay in the desert in the summer time without water and air conditioning can get dangerous fast!  So if I’m going to be more than 15 minutes from a Circle K, I’m packing a gallon or two of water just in case.


The tokens that wouldn’t die

Here’s a funny post from The Daily WTF that shows some production code that allowed an API to issue tokens that were valid for nearly 50 years!


I found this especially relevant to me as I’ve been working with API authentication recently and it reminds me to take extra care when dealing with theses security concerns, especially as someone who is new to this area of software development.


Making a POST request to an oAuth2 secured API using RestSharp

Recently, a coworker asked me how to best consume (using C#) an oAuth2 secured API which I had deployed.  I have been using RestSharp (along with JSON.NET) to make web requests in some of my applications recently, so I wrote a quick sample application for him demonstrating how to communicate with my API using those libraries.  I included it with the documentation for that API, but I want to share the basic concepts here as well.  Since the API is using oAuth2, the first step is to get an access token using an API key and password:

var url = "https://my.api.endpoint/GetToken";
var apiKey = "api_key";
var apiPassword = "api_password";

//create RestSharp client and POST request object
var client = new RestClient(url);
var request = new RestRequest(Method.POST);

//add GetToken() API method parameters
request.AddParameter("grant_type", "password");
request.AddParameter("username", apiKey);
request.AddParameter("password", apiPassword);

//make the API request and get the response
IRestResponse response = client.Execute<AccessToken>(request);

//return an AccessToken
return JsonConvert.DeserializeObject<AccessToken>(response.Content);

If you were successfully able to authenticate using your API credentials, you should receive a response that contains an access token and other information. Depending on the API you’re accessing, it may look similar to this:

  "access_token": "v5s5UckbViR9gZUXiu...",
  "token_type": "bearer",
  "expires_in": 43199,
  "userName": "api_key",
  ".issued": "Sun, 30 Jul 2017 17:05:37 GMT",
  ".expires": "Mon, 31 Jul 2017 05:05:37 GMT"

Now that the application has been authenticated and has be granted an access token, we can then provide this token when calling various API methods to get authorization.  Here is a sample POST request to my API, calling the DoStuff() method and including an object which contains the input parameters:

var url = "https://my.api.endpoint/DoStuff";

//create RestSharp client and POST request object
var client = new RestClient(url);
var request = new RestRequest(Method.POST);

//request headers
request.RequestFormat = DataFormat.Json;
request.AddHeader("Content-Type", "application/json");

//object containing input parameter data for DoStuff() API method
var apiInput = new { name = "Matt", age= 34 };

//add parameters and token to request
request.AddParameter("application/json", JsonConvert.SerializeObject(apiInput), ParameterType.RequestBody);
request.AddParameter("Authorization", "Bearer " + access_token, ParameterType.HttpHeader);

//make the API request and get a response
IRestResponse response = client.Execute<ApiResponse>(request);

//ApiResponse is a class to model the data we want from the API response
ApiResponse apiResponse = new ApiResponse(JsonConvert.DeserializeObject<ApiResponse>(response.Content));

And that’s pretty much it – the ApiResponse object now has all the data we need from the server response, whatever that may be depending on the API.  As you can see, both of these libraries together make sending and receiving data to/from a server very easy with just a few lines of code.  Getting authenticated with the API server, sending some data, and receiving a deserialized response is very simple.  More information about RestSharp and JSON.NET can be found here:




Color Calibrate Your Monitor

When designing a web app or map, it is important to realize that the colors you see on your monitor may not be the same colors somebody else sees on their monitor or mobile device.  Perhaps you may have noticed that one of your monitors looks a little “off” compared to a second monitor, or maybe a map you designed looks different on screen when compared to a printed copy.  This is because your monitor color settings may not be calibrated correctly.  Most modern flat panel monitors will have on-board controls to adjust various display settings like brightness, sharpness, and contrast. Often they will come with preset options like “theater mode” or “game mode.” These work well for the average consumer, allowing them to quickly pick a color setting that looks good for their preferences.  However, if you’re doing color sensitive work – cartography, web development, photography, etc – you don’t want the monitor to just “look good,” you need your monitor to display as close to true colors as possible.  This will ensure that content created on your computer will display as accurately as possible when viewed on a wide array of devices – devices which may or may not have been properly color calibrated by their user.

So how do you color calibrate a monitor?  There are two basic ways to do this, the first involves purchasing a device that can sense the color output of your monitor and automatically adjust settings.  These devices are very accurate, but are more aimed at professional photographers and others who perform extremely color sensitive work.

The second method for color calibrating a monitor involves using test images and adjusting various hardware and software settings.  This method is sufficient for most web developers and GIS professionals, and depending on the make and model of the monitor, should yield sufficiently accurate color display.  If you’re using Windows, there are some basic built in settings accessible via Control Panel > Display > Calibrate Color:

This wizard will take you through some easy to follow steps and will yield a rough monitor calibration.  More information is available from digitaltrends.com, including information on performing the same task in MacOS.

I prefer to fine tune the calibration on my monitors a bit more, however. I use some test images from lagom.nl that allow me to properly adjust settings on both the monitor itself, as well as settings in the operating system or video card settings application.  Here is the first test image, which assists in adjusting contrast.  When properly calibrated, a monitor should display roughly equal steps in brightness over the full range from 1 to 32 for each color:

Adjust the contrast setting on your monitor until you can just barely see the first color bar, and you can also see a division between each subsequent color bar.  Here is a link to the complete set of monitor test images – each image tests a different setting and gives some instructions on what setting to adjust:


If you are using an NVIDIA graphics card, they provide some excellent utilities and information on how to properly calibrate monitor color:


Browser diversity is good for the web

Develop for the web, not for a browser! Here’s a good quick read about why having a single web browser for all operating systems and devices would not be a good thing:


The article also included this quote from Steve Jobs that I found kind of interesting:

“What’s the point of focusing on making the product even better when the only company you can take business from is yourself?”

Competing browsers are part of what drives innovation on the web. Developing for the ever-changing hardware and software landscape of the web is definitely a challenge. It is important to test websites thoroughly – you want your users to have a good experience regardless of the device and browser they are using.