Thursday, July 19, 2012

Water pressure issues? Let it flow!

Most of my articles are about technology and software development, however I recently purchased a new home and, as I worked on various things around the house I realized others might benefit from a few of the more common issues I've addressed. Some of these problems might seem simple to fix, however I figure there are others like me who are learning these things for the first time and might find my experiences helpful.

Problem: Water pressure is fine at first, but within a few seconds flow decreases significantly. The hot water never gets beyond warm, but both hot and cold suffer from the same decreased flow.

Diagnosis: It's important to distinguish between water pressure and volume. Low water pressure results in a lower flow as soon as valve is opened. This can result from undersized pipes or the use of valves/connections that reduce flow as well as simply receiving low pressure from the source. A volume issue results from some restriction farther down the line that allows a higher pressure to build over time, but once that pressure is released (such as in the first few seconds of running water) then the pressurized volume is exhausted and flow is limited by the restriction. If both hot and cold lines suffer from the same symptoms then the problem most likely exists on the main water line before the water heater.

Solution: Every situation is different, but in my case I found that the main cutoff valve at the meter box was not completely open. One and a half turns more and the restriction was gone restoring full flow to the house.

If you've run into a similar problem I'd love to hear about it. Comments are appreciated and you can find me on twitter (@gainesk).

Friday, June 8, 2012

Should Internet Access be a Right?

Internet access has become a mainstay of our society and arguably more important to staying informed and the ability to make a living than phone or television. It's something that can be taken for granted when living in a densely populated city, but many rural areas are left with spotty or non-existent broadband service. For software developers in particular this can make working remotely and offering after-hours support difficult or even impossible.

I'm all for capitalism and a competitive market and I understand that most utility/service companies are out to make a profit so providing service to new areas is something they have to consider carefully, however when it comes to regional services these companies often have a monopoly that discourages new competitors and leaves residents with limited choices, and sometimes no choice at all. That's one reason why companies are often required to sign franchise agreements with city, county or state where they agree to provide a certain level of service in exchange for their territory.

For example, Comcast signed a franchise agreement with Franklin County (TN) which states they will, "provide Cable Service to every dwelling unit wtihin the Franchise Area reaching the minimum density of at least twenty-five (25) dwelling units per mile". To put this in perspective, if you split one square mile up into equal lots then each resident would have approximately 25 acres. This means that they have committed to providing service to all but the most rural and sparsely populated areas.

One important point regarding this agreement is that it only addresses Cable Service, which is defined as, "(A) the one-way transmission to Customers of (i) video programming, or (ii) other programming service, and (B) Customer interaction, if any, which is required fo rthe selection or use of such video programming or other programming service." While it makes sense they would offer additional services once the company has invested in running lines out to new areas, they have no commitment to providing internet access.

Does the area you live in have a franchise agreement with local internet service providers? Do you think that internet access is something they should be required to provide to residents or is it a luxury?

Tuesday, May 15, 2012

Using ODAC with EF4 via WCF

Oracle Data Access Components (ODAC) 11.2 Release 4 (11.2.0.3.0) with Oracle Developer Tools for Visual Studio includes support for Entity Framework and LINQ. Implementation is simple, however when I called the query from a WCF service I got the error:

System.ArgumentException was unhandled by user code
  Message=The specified store provider cannot be found in the configuration, or is not valid.
  Source=System.Data.Entity
  StackTrace:
       at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)
       at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
       at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
       ...
  InnerException: System.ArgumentException
       Message=Unable to find the requested .Net Framework Data Provider.  It may not be installed.

A bit of research discovered that 32-Bit Applications are disabled by default in the IIS Application Pool. As soon as I changed Enable 32-Bit Applications to True everything worked fine.


Tuesday, May 8, 2012

Testing the Untestable with VS2012 Fakes

One of the new features included with Visual Studio 2012 is the Fakes Framework which offers the ability to detour code at runtime and isolate functionality for true unit testing, regardless of whether the code was written with testing in mind.

I began speaking on Fakes back when it was a beta product from Microsoft Research called Moles. While the core functionality remains the same, Microsoft has streamlined the implementation and now calls the detour mechanism a shim rather than a mole.

If you have attended this or another of my talks at a user group or conference, please take a moment to share your feedback on SpeakerRate.

The PowerPoint is available on SlideShare and below are links to the code demonstrated in the presentation.

Demos
Y2K Checker (simple introduction)
DateTime Audit (avoiding non-deterministic tests)
File Reader (shimming file system access)
Repository (stubbing interfaces)

Resources
Visual Studio 2011
Fakes MSDN Documentation

Friday, March 16, 2012

Ignite Talk on Gaming

I signed up to give an Ignite talk this evening on why everyone should play games. For anyone who's not familiar with Ignite talks, presenters share a personal or professional passion, using 20 slides that auto-advance every 15 seconds for a total of five minutes.

My slides can be found on my SlideShare profile:
http://www.slideshare.net/gaines/ignite-reasons-to-play-games

If you attended one of my talks, please feel free to provide feedback at SpeakerRate:
http://speakerrate.com/gaines

Tuesday, February 21, 2012

Truncating Text by Pixel Width

If you've ever tried truncating text by the number of characters then you've probably noticed that most of the fonts we use are not fixed-width, resulting in different lengths depending on which characters are used. This is particularly true of spaces which are much thinner than other characters.



I ran into this problem recently when creating a message preview module and I solved it by placing the text in a hidden div set to my desired width, then chopping off characters from the end until it fit. Of course, we don't want partial words so I wait until we reach a space before returning the truncated text.

Here is the div (placed in the page body):
<div id="hiddenTruncateHelper" style="position: absolute; visibility: hidden; display: block; height: auto;"></div>

...and the JavaScript:
var truncate = function (str, width, height) {
    var bits, bit, i;
    $("#hiddenTruncateHelper").width(width);
    $("#hiddenTruncateHelper").text(str);
    bits = str.split('');
    if ($("#hiddenTruncateHelper").getHiddenDimensions().height > height) {
        for (i = bits.length - 1; i > -1; --i) {
            $("#hiddenTruncateHelper").text(bits.join(''));
            bit = bits[i];
            bits.length = i;
            if (' ' === bit && $("#hiddenTruncateHelper").getHiddenDimensions().height <= height) {
                break;
            }
        }
    }
    return bits.join('');
};

One problem I had was that the browser kept returning zero for the div height because it is hidden. While searching for an answer I found a blog by Tim Banks where he shares an extension method to get the dimensions for a hidden element.
//Optional parameter includeMargin is used when calculating outer dimensions
(function ($) {
    $.fn.getHiddenDimensions = function (includeMargin) {
        var $item = this,
        props = { position: 'absolute', visibility: 'hidden', display: 'block' },
        dim = { width: 0, height: 0, innerWidth: 0, innerHeight: 0, outerWidth: 0, outerHeight: 0 },
$hiddenParents = $item.parents().andSelf().not(':visible'),
includeMargin = (includeMargin == null) ? false : includeMargin;

        var oldProps = [];
        $hiddenParents.each(function () {
            var old = {};

            for (var name in props) {
                old[name] = this.style[name];
                this.style[name] = props[name];
            }

            oldProps.push(old);
        });

        dim.width = $item.width();
        dim.outerWidth = $item.outerWidth(includeMargin);
        dim.innerWidth = $item.innerWidth();
        dim.height = $item.height();
        dim.innerHeight = $item.innerHeight();
        dim.outerHeight = $item.outerHeight(includeMargin);

        $hiddenParents.each(function (i) {
            var old = oldProps[i];
            for (var name in props) {
                this.style[name] = old[name];
            }
        });

        return dim;
    }
} (jQuery));

That's all there is to it. We just call our method and pass in the string, desired height and width (in pixels) and it returns the truncated text. Just add some ellipses with a tooltip (title) and we're done!
<a href="#" title="FULL TEXT">...</a>

If you have a suggestion for how this solution could be improved or a question, please post it here. Thanks for reading!