ngrok is awesome!

I don’t know if I’m the last one to the party, but if you haven’t checked out ngrok, do yourself that favor!

In short, ngrok is a secure tunneling application which lets you expose a web application publicly with essentially zero setup.  You can always configure a server, deploy to the server, test against the server, read the logs… 

If you want a faster process, download and unzip ngrok, then run this on the command line:

X:\ngrok> ngrok http [port]

Then get on with your life.  ngrok will generate a custom [http/https]://*******.ngrok.io subdomain for your process and you can connect immediately.  Best of all, it’s free!  There are paid plans, and they’re well worth the low price IMHO.

If you’re using IIS Express, you’ll want to include a host header command:

X:\ngrok> ngrok http [port] -host-header=”localhost:[port]”

TL;DR, this is required due to the default binding information in IIS Express.  Thanks to, and please check out, Devin Rader’s excellent write-up for a better explanation as well as alternate methods of working with IIS Express and ngrok!

Grokking a Legacy Database

Just a quick note today.  Thought I’d share one of my favorite queries for getting to know a legacy database.

Now, we all know that legacy databases are always comprehensively documented, and we never forget where we put that documentation, and the author of the documentation can always predict exactly what you need to know about the database…  but for those of us who live in a world where good practices and intentions don’t universally lead to perfect results:

SELECT
[col].[TABLE_NAME],
[col].[COLUMN_NAME],
[col].[DATA_TYPE],
[col].[CHARACTER_MAXIMUM_LENGTH],
[col].[IS_NULLABLE],
[con].[CONSTRAINT_NAME]
FROM [INFORMATION_SCHEMA].[COLUMNS] AS [col]
LEFT JOIN [INFORMATION_SCHEMA].[CONSTRAINT_COLUMN_USAGE] AS [con]
ON [col].[TABLE_NAME] = [con].[TABLE_NAME]
AND [col].[COLUMN_NAME] = [con].[COLUMN_NAME]
WHERE [col].[TABLE_NAME] LIKE '%%'

Database diagrams make for a nice 5,000 ft. view, but when I’m ready to try to understand a single table nothing beats a quick and simple view of the basic column data.

A view of information returned from the above Gist, when targeting the Employee table in Microsoft's Northwind database.

Just looking at the results for Microsoft’s Northwind database’ Employee table, I know; the Primary Key is EmployeeId, the BirthDate column is a datetime and has a check constraint which is worth investigating, the general structure of the data, and I can intuit that the column ReportsTo, with the Foreign Key constraint FK_Employees_Employees, is likely a cyclic key linking one employee to another in a management hierarchy.

Not bad for a single query.

Kill it with fire!

Part of the reason I haven’t written anything lately, is that I just built the gaming PC I’ve been waiting to get for the past 3+ years.  After waiting that long, I’m making good use of it!

One of the first things I did was to boot up Fallout 4 and explore the wastes…  Until it crashes, of course.  Not sure what it is about the series, but I always end up playing for a random amount of time before the game crashes and locks up my system, in this case allowing me to see all my applications, but not view the actual windows.

PowerShell to the rescue!

  After the latest crash, I found myself staring at my computer thinking, “Really?  I can open task-manager, I just can’t interact with it using a mouse, so I can’t kill Fallout!  Wait a minute…  Since when do I need a mouse?”

Get-Process | Where-Object { $_.ProcessName -like '*fall*' } | Stop-Process

Fortunately, Fallout has a fairly distinct process name.  Next time someone’s software tries to eat your computer, don’t get mad.  Kill it with fire!  (Fire, or PowerShell.  Please note: PowerShell is probably far less destructive in the long-run.)

Update:

For the busy developer who just doesn’t have time to enter all those characters, the shorthand is much simpler:

gps '*fall*' | kill

option:checked, not [selected].

Just a quick note.  I’m not sure if this is just me, but until recently I’ve only interacted with the option element by checking for a [selected] attribute.  This caused me no end of problems when dealing with the excellent bootstrap-select library.

Once the element is loaded into the DOM, the [selected] attribute is not how you need to check the state of an option, or query for options.  To query for options which have been selected by the user, use the :checked pseudo-class selector, just as you would with a radio or checkbox input.

InternalsVisibleTo

Just a quick tip.  Every once in a while, you’ll need to share code between specific assemblies, and only those assemblies.  A common example is when you want to strap a test-harness to an object, but not publicly expose the type.

/// <summary>
/// Vital component.
/// </summary>
/// <remarks>
/// Ensure stability but don't publicly expose.
/// </remarks>
internal static class CriticalComponent
{
}

Sometimes you just need to expose an object, type, or method to another specific assembly.  Fortunately, you can!

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
 
// Allow ExampleAssembly.Tests to test internals
[assembly: InternalsVisibleTo("ExampleAssembly.Tests")]
 
// General Information about an assembly is controlled 
// through the following set of attributes. Change 
// these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ExampleAssembly")]

Check out the MSDN for full details.  It’s a handy thing when you need it.  Oh, and remember to put your assembly attributes in your AssemblyInfo file.