Connectify Mobile Hotspot

A friend and I wanted to play a LAN game at work using our Kindle Fires. The problem is that Kindle Fire is wifi-only, and we didn’t have a wireless network available. First we tried using our Android phones. (In retrospect, this would’ve worked, but we unknowingly had different versions of the game.) The next thing I tried was to find software that would allow me to use my laptop as a mobile hotspot. And that’s when I found a great little application called Connectify.

With Connectify, you create a virtual hotspot that you can connect your devices to. You can choose to share your internet connection–an AMAZING feature for Kindle Fire owners–or simply act as a local network. For my LAN gaming needs, we chose to create a non-internet-sharing hotspot, and it worked fantastically. You can use the application for free or upgrade to the Pro version for $30 to get some additional functionality.

I definitely recommend checking it out!

Dear WP7, I’m in love with Android

Ever since the 2010 PDC when I got my first Windows Phone 7, I’d been in love with it. I was coming from a Blackberry and was thrilled with everything I was getting–Zune, local scout, a decent camera, the UI.

Buuuut there were some things that I wasn’t so happy with, too. The biggest thing for me was the availability and quality of apps. Sure, there are some great apps. But there’s a lot of essential apps that aren’t available, like Pandora and Google+. The “standard” apps that were available–like Facebook and Twitter–were glorified bookmarks and didn’t have nearly the functionality that my wife had with her Android. The thing that finally pushed me over the edge was seeing a co-worker use Android’s mobile hotspot while on the road at a customer site. That justified a new phone platform right then and there.

So I’ve switched from my Samsung Focus to Samsung Epic 4g Touch, and I must say, I’m thrilled! What do I love about it? All the apps are great. I have two GPS solutions (Google Navigation & TeleNav) that are WAY better than what I had with WP7. I have unlimited data, which is incredible. (I know this isn’t a WP7 flaw, but it’s something that I didn’t have with AT&T that I now enjoy with Sprint.) I love having access to Pandora again. Oh, and MOBILE HOTSPOT!!

Is there anything I miss about my Windows Phone? Not a lot, but there are some things. The integration with SkyDrive and Office was nice. I love OneNote, so I liked having it as an app that would sync automatically to the web. The battery life was great. Battery life is what I was worried most about before switching. My wife’s EVO 4g has pretty sad battery life, but my E4GT seems decent.

So, WP7, we had a good run together, but my heart now belongs to Android. The E4GT is the everything I’ve ever wanted in a phone, and I plan on sticking with Android for the foreseeable future.

Cross-Server Mass Inserts with SSIS

I only recently learned about SSIS packages, a feature that was introduced long ago with SQL Server 2005. They were presented to me as a solution to a customer problem that required millions of records from separate vendor databases to be archived and up-to-date in a single location. I wasn’t the brains behind that solution, but I had a similar, less-business-critical situation and I decided to give it a shot.

There’s a small learning curve, but after a few hours I was able to extract hundreds of thousands of records from a database on one server and insert them into a different table in a different database on a different server. One of the most exciting parts is that it was able to do all of that in about 10 seconds!

I was so impressed with what I’d accomplished that I wanted to document my journey in this mini-tutorial. Disclaimer: I’m by no stretch any sort of expert with SSIS nor do I claim to be any sort of SQL guru–I’m just a dude trying to move some data.

I started by creating my extraction query in SQL Server Management Studio. I actually started by using SSMS’s “script as INSERT” feature on my destination table and evolved that into my data extraction query. The nice thing about that approach is that the column mapping for the insert will be handled automagically by SSIS. I didn’t know that at the time, but it worked out well!

Once I had my SQL extraction query, it was time to start with the SSIS:

  1. Open SQL Server Business Intelligence Development Studio from Start > All Programs > SQL Server 2008
  2. Create new project
  3. Business Intelligence Projects > Integration Services Project

When the project opens, you have a canvas-like screen with several tabs at the top. One of the things that I did not realize right away is that toolbox items change depending on which tab you’re on. Since I wanted to move data between databases, I eventually found and decided to use the Data Flow Task. I dragged it from the toolbar onto the design surface of my Control Flow. Double-clicking the Data Flow Task took me to the Data Flow tab, where I added the meat.

Since I was extracting data from one database to be inserted into another, the logical step was to figure out how to extract that data. From the Data Flow tab, I found a OLE DB Source control in the toolbox. I double-clicked the control was it was on the design surface and was able to add my database connection and provide the SQL statement I wrote previously as the source. Pretty easy!

There was another control in my toolbox called OLE DB Destination–sounds perfect. Once again, I was able to double-click the control from the design surface to access properties like database connection and destination table. The final step was to drag the arrow from OLE DB Source to OLE DB Destination. I ran the package using the standard Visual Studio debugger controls, and it worked great!

The only other cool thing I found was that I could run the package from outside of Visual Studio, and I was given the ability to do things like update database connections. That seems great for package re-usability and sharing! I’ve definitely only scratched the surface of SSIS, but I will certainly keep it in mind for future problems!

The Art of Agile

I was out on the internet doing some general research for ideas to improve my team’s agile software practices, and I found a terrific resource. More specifically, I was in search of information about how to improve our story-writing, and I found it here. I then stumbled upon an equally interesting article about including slack in a sprint. This is something that I’ve felt is necessary for a long time, but I didn’t know how to introduce it. There are a lot of good ideas; read more here.

If you’re doing agile and struggle with any aspects or just looking for new ideas, I recommend checking out this website: James Shore: The Art of Agile

Thanks to James Shore for making this wonderful resource available!

Value Extraction with Regular Expressions in C#

Regular expressions are one of my favorite things in programming. Each time I write one, it’s like a challenging little brain teaser. One of the things that I commonly use them for is to extract data out of a string.

In the past, I’ve done this by instantiating a Regex with a pattern, checking for matches, getting a MatchCollection, iterating through its matches, and, finally, pulling my “value” out of the match’s group. That’s a whole lot of work to extract a piece of data, and I’ve always suspected there’s an easier way.

I figured out how to do this elegantly just the other day, and I was thrilled. I was working with an alphanumeric text field that was left-padded with 0s. I needed to strip the 0s, and my mind instantly went to regular expressions. Using the static Result method, you can specify capture groups for the output. So, getting my value could be done in a single operation!

// trim leading 0s 
if (value.StartsWith("0")) 
{ 
    value = Regex.Match(value, "^0+(.*)$").Result("$1"); 
}

For those of you who may not be as regular expression savvy, here’s what’s going on:

  • ^ – the beginning of the string; we use this so that we don’t match on a subset of the string
  • 0+ – one or more 0s
  • (.*) – zero or more characters; the parentheses indicate that this is a capture group
  • $ – the end of the string; we again use this so that we don’t match on a subset of the string
  • $1 – $n can be used to output the value of a capture group

Wonderful!

Manipulating Objects in a Collection with LINQ

I was chatting with a co-worker about using LINQ to replace for-each loops. More specifically, we were discussing how to modify the properties of items in a collection or a subset of the collection. I didn’t know how to do it immediately, but I worked on it a bit and found a pretty cool way to do just that.

My first thought was that you could just put your logic into a Select method, modify the objects, and then return a dummy value that would be ignored. Something like this:

// this does not work!
values.Select(x =>
{
    x.Name = x.Name.ToUpper();
    return true;
});

This did not work, though! I’m not entirely sure why, but I tried a few different approaches and found a way that does work. It feels less hacky, too, since I’m not returning that meaningless dummy value.

Here’s the solution that I came up with:

values.Aggregate(null as Person, (av, e) =>
{
    e.Name = e.Name.ToUpper();
    return av ?? e;
});

If you only want to manipulate a subset of the collection, you can insert a Where method before your aggregate, like this:

values.Where(x => x.Name.Equals("Blah"))
    .Aggregate(null as Person, (av, e) =>
    {
        e.Name = e.Name.ToUpper();
        return av ?? e;
    });

You can read more about the Aggregate method here.

Wireless TV Receivers from AT&T U-verse!

I’m so excited that AT&T U-verse has come out with wireless TV receivers. I have not had cable in my upstairs bedroom for the 6 years that I’ve lived in my current home due to the fact that the wiring was not in-place. I’d been told by multiple companies that I couldn’t get cable installed up there without tearing through the walls or running a cable up the side of the building, and I haven’t been ambitious enough to do such things. I’d dream to myself–why can’t they just come up with a wireless receiver? I can stream wirelessly from my computer, so why not do the same with TV?

Well, my prayers have been answered, and I am so happy! I ordered my wireless receiver from AT&T the day after I found out that they offered it. They charged me a one-time fee of $49.99 plus $7 per month, which is the same as a second non-wireless, non-DVR HD receiver. It arrived in the mail two days later, installed in minutes, and has worked flawlessly since.

There are two pieces to the setup. A small access point that plugs directly into the U-verse home portal (or whatever they call it–the router), and the wireless receiver. When you turn them on, you pair them much like a bluetooth device. And that’s all there was to installation & setup.

Hats off to AT&T for this. I love it 🙂

Undoing Pending Changes from Another User in TFS

From time to time, we run into a situation where a team member leaves or becomes unavailable, but they still have files checked out in TFS. This can be troublesome if they have an exclusive lock on a file, or it can be a housekeeping issue if they have a lot of files checked out everywhere.

If you have rights, there is a relatively simple way to undo changes from another user to clean-up a bit.

First, you need to know the name of the user’s workspace(s). You can do this by running the following command:

tf workspaces /owner:"username" /server:http://tfsserver:8080/collection

Then, to undo all pending changes from a particular workspace, run this command:

tf undo /workspace:"WORKSPACE;username" /server:http://tfsserver:8080/collection /recursive "$/teamproject"

If successful, you should receive a message like this:

The operation completed successfully.  Because the workspace xxxx;xxxxxxxx is not on this computer, you must perform a separate get operation in that workspace to update it with the changes that have been made on the server.

Reference: here.

Convert images to a PDF with iTextSharp

I just finished working on a project that required multiple images to be combined into a single PDF document. I used iTextSharp to create the PDF, and I’m pretty happy with the solution that I came up with. There were only two functions required: one that converts an image to a smaller size & lesser quality and one that combines the images into PDF.

Here’s the code:

/// <summary>
/// Takes a collection of BMP files and converts them into a PDF document
/// </summary>
/// <param name="bmpFilePaths"></param>
/// <returns></returns>
private byte[] CreatePdf(string[] bmpFilePaths)
{
    using (var ms = new MemoryStream())
    {
        var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER.Rotate(), 0, 0, 0, 0);
        iTextSharp.text.pdf.PdfWriter.GetInstance(document, ms).SetFullCompression();
        document.Open();
        foreach (var path in bmpFilePaths)
        {
            var imgStream = GetImageStream(path);
            var image = iTextSharp.text.Image.GetInstance(imgStream);
            image.ScaleToFit(document.PageSize.Width, document.PageSize.Height);
            document.Add(image);
        }
        document.Close();
        return ms.ToArray();
    }
}

/// <summary>
/// Gets the image at the specified path, shrinks it, converts to JPG, and returns as a stream
/// </summary>
/// <param name="imagePath"></param>
/// <returns></returns>
private Stream GetImageStream(string imagePath)
{
    var ms = new MemoryStream();
    using (var img = Image.FromFile(imagePath))
    {
        var jpegCodec = ImageCodecInfo.GetImageEncoders()
            .Where(x => x.MimeType == "image/jpeg")
            .FirstOrDefault();

        var encoderParams = new EncoderParameters(1);
        encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, (long)20);

        int dpi = 175;
        var thumb = img.GetThumbnailImage((int)(11 * dpi), (int)(8.5 * dpi), null, IntPtr.Zero);
        thumb.Save(ms, jpegCodec, encoderParams);
    }
    ms.Seek(0, SeekOrigin.Begin);
    return ms;
}

Force the Mango Update

I have a Focus v1.3 on AT&T, and it was announced that the Mango update was available for me. I got home from work super excited, but when I went to my computer, Zune told me that there was no update.

After a few minutes of googling, I found this link that tells you how to trick/force Zune into letting you have the update, though! It worked for me, so give it a try if you’re in the same boat 🙂

http://www.wpcentral.com/force-mango-update-early-through-zune-software