Search

A few odds and ends

I have a few odds and ends that I have been trying to put together into full posts, but for now it’s not gonna happen. Instead, I’ll share some thoughts as previews for posts that may or may not happen in the near or far future.

Testing ASP.NET / WebAPI projects

Web API is pretty freaking sweet! It’s possible to set up RESTful endpoints very easily. Having been working a bit lately on a WebAPI project, I really want to start off the post with some tips for route debugging and testing for WebAPI with NUnit and Moq.

Debugging routes

If you’re having issues with the “multiple actions were found that map the request” issue in a WebAPI project, start off by checking all of the public methods in your controllers. As weird as it may seem, refactoring some methods in a controller to be public can break your routes.

You can get the matched rule from within a Web API controller by retrieving the RouteTemplate stored in the controller’s Route member, for example:

this.Request.GetRouteData().Route.RouteTemplate

From the route template, you can make sure that your route is matching as expected.

Testing a route pattern is still matching as expected in WebAPI 2.0

You can make sure that the route patterns still work by constructing the route patterns in a request and then building the route configuration object. With this object, you can then test matching rules on a particular endpoint.

For example, the following code uses WebApiConfig to build out routes based on the specified patterns in the WebApiConfig.cs file and will then test the matching rules against the given request.

In the code, I’m making sure that the route for “http://localhost:4567/api/users/me” is correctly matching the expected route template.

Uninstalling Android Packages when you have a package you don’t want on your device:

While developing my Please Set to Vibrate Android app>, I on many occasions had to replace / remove duplicate packages that ended up on my device due to versioning and gremlins. If you have similar issues, you can use the ADB console to remove packages directly. The following command removes &lt;packagename&gt; where packagename is something like com.gclassy.pleasesettovibrate:

adb uninstall <packagename>

Another useful command to check for installed packages is:

adb shell pm list packages

What this does is list all the packages so that you can adb uninstall.

Editing Photos on the Web

These online photo editors are great replacements for basic editors like MSPaint and Preview. In particular, I have really come to appreciate the Google+ photo editor. To access it, just open a photo in Google+ and click edit. The following screenshot shows it in action:

It’s a reliable editor and it’s from Google and many of the Nik folks, so it’s solid and produces great results.

Upgrading the hard drive on an Asus K55

I recently upgraded / replaced the hard drive on an Asus K55A (or is it K-55A?). At any rate, the basic steps are:

Remove set screws on the back of the laptop

Remove the set screws on the drive bay underneath

Remove the hard disk from the bay underneath

Replace the drive

Done!

The laptop only has a single bay for disk drives, so if you’re going to add an SSD, you might want to splurge and get a 256. I ended up just putting the old drive into a USB-3 enclosure and using the external storage for basics.

Diffing files like a boss:

sdiff, or “split diff” is an improved version of the diff utility that ships with most *NIX variants. Here is some basic usage showing my favorite flags:

sdiff -s -w 150 file1 file2

The -s flag will suppress common lines (who needs context, anyways!) and the -w flag will set the width.

Why stop there though! You can use `vimdiff` for visually comparing and editing files! This is really useful for merging. You can edit any of the diff’d files and can see the changes in realtime. Screenshot showing a diff of my .vimrc on a few machines:

Speaking of Vim, a few pro tips

Vim has plugins. These plugins will save you time. To manage your plugins, you should be using a plugin manager such as:

Air-line – A sweet looking status line, you can see it in my vimdiff screenshot above.

If you’re theme-crazy like I am, you should also check out the wonderful Tomorrow vim theme. This theme uses really comfortable colors and has some great included variants, tomorrow-night being my preferred.

Amethyst

If you are an OSX user and aren’t satisfied with Apple’s window management, e.g. you’re like me and any day I have to reach for a touchpad to manage a window’s size is a bad day, then you should try out the free Amethyst project. Ever since OSX mavericks broke Divvy for me because the multi-monitor behavior changed , I have had a lot of frustration using my Mac. So long as I was already frustrated, I figured why not give this option a try. My conclusion: Amethyst is cool! You can reorganize your windows by pressing alt+shift+space and the provided templates are great. Here’s a short gif demoing the various window tiling modes.

Chromecast

In case you don’t already know, I think Chromecast is da bomb. I strongly recommend grabbing this tiny device, even if you already have a streaming player.

Conversion from Adobe Photoshop to HTML/CSS

I sometimes work with design agencies. These agencies tend to throw PSD files over the wall to me and expect me to be able to just magically convert them to HTML/CSS. This is not usually the case: you have to find the correct fonts, you have to setup the fonts to render correctly, you have to identify all of the right colors, you have to make objects the right size, and so on. To save some time, I have started using CSS Hat, a great tool that magically creates CSS from Photoshop layers.

Adobe recently added a very similar feature in PhotoShop CC. Again, you select a layer and can copy as css.

That’s it for now, I have a few exciting projects in the works, hopefully I’ll wrap some of them up soon and will have more to share.