Sorting table columns in Microsoft SQL Server Management Studio (SSMS)

From a simple web search, I have seen I’m not alone when it comes to wanting to sort table columns within the Object Explorer view of Microsoft SQL Server Management Studio.

It’s terribly annoying to have to scan hundreds of columns line-by-line until you find the one you’re interested in.  Eventually, your eyes will get blurry and you’ll end up scanning right past the targeted column name.  Frustrating…

I did find a way arssms1ound this.

From the View menu, click Object Explorer Details.  I docked the window right above the Object Explorer window (you could also open it below).

Once it is docked, highlight the table you’re interested in searching in the Object Explorer window and watch the context change in the Object Explorer Details window.

Double-click “Columns”, then click the “Name” button above it to sort by column name.  Voila!



How To Install Atom Packages Manually

Recently, I switched away from using Sublime Text 3 as my primary text editor to Atom, from the folks at GitHub.

I found installing themes and plugins or packages was far simpler.  No manually editing of JSON files just to switch up a theme for example.  Atom includes a simple UI that makes the installation and update process easy.cda7a1c2ac02fd3d[1]

I ran into one issue today though.  When updating multiple packages at once, my PC froze.  All CPUs were max’d at 100% and I had to force reboot.

Apparently the “atom-beautify” build was failing and this somehow caused Atom to lock-up during the update.  I uninstalled atom-beautify and found I could not re-install it.  Perhaps it was the failing build or perhaps Atom was compromised by the lock-up.

I found that I could manually install Atom packages by downloading the right version (i.e. a “passing” build) as a zip file and extracting that out to the Atom package directory in my home folder.  You can find where this is on your machine by using apm, the package manager for Atom:

That command should return the package directory for Atom, where you can then drop the unzipped package contents into its own folder.  Restart Atom and you’re good to go 😉

For more details on Atom’s package manager, visit https://github.com/atom/apm.


HackerRank “Lonely Integer” Solution (Java)

The problem statement for HackerRank’s “Lonely Integer” challenge says:

“There are N integers in an array A. All but one integer occur in pairs. Your task is to find the number that occurs only once.”

hackerrank-logoSo the first numbered entered into the algorithm will dictate the number (N) of integers to process.   The second input will be a space-delimited series of N integers.  With that series of numbers, you are to determine which value only occurs once.

There are many ways of configuring an algorithm to do this but the simplest solution is to use java’s HashSet collection-framework data structure.  One of the attributes of a HashSet is that there are NO DUPLICATES.  Another attribute of HashSet is that when using the add() method to add values to the collection, a boolean value of TRUE or FALSE is returned.

How can this be useful?

Well, if the set already contains an integer of a certain value (say, “5”), then when you attempt to insert another value of “5”, the collection will return a FALSE boolean (meaning it could not perform the action).  Using this quirky feature can be beneficial in weeding out the duplicates.

Remember:  according to the problem statement, ALL integers occur in pairs EXCEPT one.

My solution for “Lonely Integer” uses the quirky boolean return feature of HashSet to weed out all of the duplicates with the single-occurring digit remaining – which is our ultimate answer:



Recursive Fibonacci Algorithm using Memoization and Dynamic Programming Don't be "naive". Use memoization and DP to defeat the recursion nightmare

My first article on Progamming the Fibonaaci Sequence over two years ago referred to a couple of approaches at generating the Fibonacci sequence programmatically using recursion.  This approach is largely considered “naive” in the mature world of algorithmic programming.  Using dynamic programming and memoization, we will learn that we can drastically reduce run time and really impress those in your future interviews.

More to come…


Preparing for the Google Interview (Part 1) Divide and Conquer

I have an interview scheduled one month from now with the #1 Best Place to Work (FORBES, FORTUNE, etc), Google.google[1]

I applied online and was contacted by a Google recruiter soon after.  Originally my interview was scheduled for September, 2015 but I knew I needed a lot more time to prepare.  Google interviews are famous for their level of difficulty, though much as changed in the past few years as they have changed their position on hypothetical brain-teaser questions.  No longer are they considered accurate measures of a person’s ability to succeed in the workplace.  That’s good news for me.

The bad news (well, not bad – let’s say challenging) is that the interviews are still highly technical in nature and cover core Computer Science principals, which are tough to understand if you have never received a computer science degree (like me).  In fact, I never graduated college.  Shhhh, keep this between you and me.

The first step is a technical phone interview.  I know it’ll be roughly 45 minutes in length and will require the use of Google Docs, an online application that can be shared in real-time between you and the interviewer.  I have an idea of some of the questions they might ask.  But I’m really shooting in the dark, so I decided to use my favorite online website, Glassdoor.com, to get a better idea of what I am in for.

The most voted interview summary on Glassdoor broke the syllabus for a Google interview down into these main categories:

  • Dynamic Programming & Memoization
  • Super Recursion
  • Breadth-First and Depth-First Search Graphs (BFS, DFS)
  • All basic data structures:  Arrays, Lists, Hash Tables, Binary Search Trees, Red-Black Trees
  • All basic algorithms:  searching, sorting, median, etc
  • Distributed systems: parallel and concurrent programming

Let’s get one thing straight:  I barely know what some of these are.  So this is my problem.  In finding a solution to this problem, I will use the Divide & Conquer approach which is common in searching and sorting algorithms.  In this case, however, I will break each one of these categories down into re-searchable areas that I can then re-use to test myself.  I also bought two white-boards online, along with markers and erasers so that I can practice writing code from scratch as I will most likely be required to do if I manage to get through the technical interview.

So, first up:  Dynamic Programming & Memoization.  I tend to refer to YouTube initially since I am a very visual learner.  I remember what I see very well.  MIT has places a large amount of lectures online for anyone to view, which is fantastic.  Here’s on on Dynamic Programming:  MIT Dynamic Programming I: Fibonacci, Shortest Paths.

My next post will cover what I have learned and my solution for the fastest way of remembering how this stuff works.  Wish me luck!


HackerRank “Funny String” Solution (Java)

In an attempt to significantly boost my coding skills, I began solving puzzles on Codility and HackerRank, and will post my solutions here on my blog for feedback or too help anyone else out there that may have been just as initially confused by the problem statements as I was.

These solutions are by no means the most efficient or meet any “Big-O” criteria but they are at most my first attempt at solving the online coding puzzles.

My solution for HackerRank’s “Funny String” problem, in Java:


jQuery Presentation Yes, Java developers are allowed to code the "UI" too

I presented a slide-deck on jQuery a while ago to my company and I thought it would be helpful to share that with you all.

The PowerPoint preso is about 45 pages long…which is a rather comprehensive overview but if it helps one developer understand the potential of jQuery then it was all worthwhile 😉

Enjoy!  Download here:  jQuery



Java Basics: Upcasting vs Downcasting What is the difference?

I’ve always known the difference between upcasting and downcasting, but earlier today when I tried to test my knowledge, I discovered I had a hard time explaining it.   There has to be an easy way to remember the difference.

I think there is.  Let’s take the words themselves for starters:   UPcast vs DOWNcast.

The “up” and “down” prefix references the inheritance chain of an object in Java (or any object-oriented language).  For example, if Cat extends Mammal, and Mammal extends Animal, our object inheritance hierarchy would look like this:

Why do the arrows point upwards?

This is standard UML notation where a class (like Cat) points to a generalization of itself (Mammal).  You could also think of it as saying, a Cat “is a” Mammal.  A Mammal “is an” Animal.  The arrows show the inheritance chain for each object, or where each object was derived from.

This diagram is also helpful in seeing the difference between upcasting and downcasting.  If you take something from the bottom of the diagram and turn it into something above or at the top of the diagram, you are UPcasting.  Think of it like this:


“I want to turn a Cat into an Animal”


Nature would have no problem with this because, well, a Cat is an Animal already so you’re not technically doing anything different.

Let’s take a look at some example code.

For instance, if you UPcast from a Cat to an Animal in Java, it would look something like this:


As you can see, this code literally says “Create a new Cat and turn it into an Animal”. You can do this because a Cat “is an” Animal. Anything an Animal can do (eat, sleep, poop), a Cat can do as well.

Instead of using instantiation, let’s try the same thing but using casting.  In Java, you can explicitly cast an object into a different kind of object by using parentheses.

See, this is doable and rather pointless.  In fact, you may get warnings in your IDE that the above expression is redundant.

Now, let’s flip the tables and try DOWNcasting.  Think of it like this:


“I want to turn an Animal into a Cat”

Let’s see the code:

Using instantiation with static compiler checks, this won’t even compile. You’ll get an error saying “Incompatible types”.

If you look back at our diagram, you’re trying to downcast from an Animal object into a more specific object called a Cat.  It’s just not possible, though you can get around the compilation error by manually casting an Animal to a Cat in code:

Though this compiles, you will get a runtime error:  ClassCastException.

So the big question is:  if “upcasting” is allowed in Java, and “downcasting” results in either compile time or runtime errors, why EVER do downcasting?

The only case I can think of is when needing to use the power of polymorphism:

Here you are downcasting an Object into a String.  In this particular instance, you’ll get past compile-time checks (because we’re casting), and the cast will not cause any runtime exceptions because this Object just happens to be a String “behind the scenes”.

I would say this is poor programming practice, but there may be a case when you have no choice.

Can anyone else think of cases where downcasting is in fact, desired?

Let me know in the comments 😉


Java Data Structures Cheat Sheet Arrays, Hashmap, TreeSet?? Here is an easy way to pick the right structure for your data

I recently stumbled upon this cheat sheet on the web and decided I would pass it on.  If you’re looking for a quick visual way to pick the right data structure for your Java application, follow this easy to navigate guide:

Sergiy Kovalchuk

Though I found this image on Stack Overflow, I found what may be the  origin here:  http://www.sergiy.ca/guide-to-selecting-appropriate-map-collection-in-java/


The Basics of Git Version Control By Subversion Users. For Subversion Users.

If you are a Subversion user, like I have been for many years, you may have noticed the surprising rise in popularity of Git – another VCS that has spread like wildfire throughout the open-source community and is now finding its way into the hearts of the Enterprise.

After attending the 2014 JavaOne conference in San Francisco, one of the sessions that resonated with me the most was a two-hour hands-on lab called “The Foundationsgit_logo of Git and GitHub“, hosted by Matthew McCullough and Mike McQuaid of Github.  I thought it was remarkable and couldn’t understand how my company had not switched to it, or even considered switching to it.  Perhaps no one brought it up before?

We’ve had our headaches with SVN for years and like that kink in the neck that won’t go away, you eventually learn to get used to it.  Merge conflicts, tree conflicts, permissions conflicts, no offline access, those stupid .svn folders all over the place…well you get the idea.  Subversion may have been light-years over RCS and heck even CVS but that didn’t mean it was modern.

I felt we had another option that the world software community was embracing and maybe we should too.  Git.

There are many Git-related resources and tutorials out there and I didn’t want this blog post to be thrown onto that heap.  I’ll try something different:  in ten minutes, I’ll attempt to teach you (a master Subversion user) how to use Git…enough to be dangerous at least.

So here we go…


Git, like SVN, is just a code respository

Git tracks code history: who committed something and when, just like SVN.

The internal mechanisms for doing so vary drastically, however.

Subversion stores “deltas” (code differences) in the file from commit to commit.  In other words, on a file’s very first commit, SVN will store the whole file.  On the next commit, if the developer added one line and deleted another line, SVN will store the difference like this:  “ blah blah blah”, and “+ blah blah blah”.

Git stores an entire snapshot copy of each file, in its entirety, but only if the file changed.  If on the next commit, a file has not changed, Git will not store another copy of the file into it’s database (that would just be wasteful).  Instead it stores a reference to the first, unchanged file.  The creators of Git believed this was much faster since Git did not have to take a file and add or subtract a entire history worth of changes to it before it can be viewed by the  developer.

* image credit: Pro Git by Scott Chacon and Ben Straub


Git doesn’t actually stand for anything.  

It’s just a name.  Linus Torvalds, Git’s creator, joked that it meant “idiot” and that he likes to name his software after himself.


Git does not rely on a central repository

Subversion stores code in a central repository.  Users connect to that central repo and check out a copy of a branch to their hard-drive.  When they are finished, the check the code back into the central repository.

Git is somewhat similar.  However instead of checking out a branch or the trunk of a project, you copy or clone the entire repo: every branch with every commit in its history ever made.  Thus, anyone working on a project has a complete backup of all of the code ever written for a piece of software.  This is why Git is referred to as a distributed version control system.

The advantage?  

You don’t need to constantly communicate over the wire with a potentially slow or inaccessible central repo.  Everything you need is right on your machine.  Once code changes are made, commit to your local Git repo and you’re done.  This makes Git exponentially faster than SVN.  You also may optionally push your changes to a network Git repo or Github.  If a friend wants to add some work to your project, he can clone the entire repo right off your machine.

Git vs SVN

* image credit: Pro Git by Scott Chacon and Ben Straub


Using Git

Since Git is a code repository that sits on your own machine, you can create a new repo anywhere on your hard-drive.  All you have to do is initialize Git (this will create one hidden .git folder), then add/stage your files, then commit.  This is great when you already have code written somewhere and now wish to keep track of future changes.

Committing code to Git is the same as SVN except for one notable difference:  staging.  In Git, you select which files you want to include as part of a commit.  Gone are the days of committing one big batch of code changes that span multiple requirements or bug fixes.  This is called staging and uses this syntax:

The period means to add all unstaged changes, but you can be much more specific and list out individual files to include as part of one revision.

This is then followed by:

The “-a” switch means to add ALL staged changes to a commit.  The “-m” switch adds a commit message.  You can also choose to commit a single staged file rather than all staged files if you wish.

Let’s say that you don’t have any code to add to Git and merely want to copy some some forked code off Github, a friend’s computer, or your company’s network Git server or wherever.  Use the clone command and you’re done!  (note: just change the below GitHub URL for any other git repo location or use mine as a test)

Git has several other commands to branch, merge, stash, and rebase to harness Git’s other Jedi-like powers.  It’s quite addicting once you get into it.  I can’t say the same for SVN when I was learning it.

Also when you download Git, try using Git Bash to really learn the commands.  


Most likely you’ll use a plugin in an IDE (like Eclipse or IntelliJ) to connect and pull git repositories, but because the Git commands are so simple and because Git Bash gives you near-Linux command-line capability (on Windows), it’s a great tool for learning and ultimately enjoying Git.

Download Git here:  https://git-scm.com/downloads


Under the Hood

Git stores your code in a local content-addressable file system.  Git will label files by hashing the code contents into a 40 character SHA1 cyptographic hash.  You’ll see this when using the “git log” command to look at the commit history, for example:


This is honestly one of those things that discourages developers when learning Git.  However it’s not something that you need to calculate or decipher.  It’s meant to assist Git in determining quickly if a file’s content has changed.  Hashing code takes a fraction of a second and comparing two 40-character hashes to each other takes even less time.  Git also uses these hashes to name the file itself.  

In Git, every file is an object.  Code is an object (these are called blobs in Git-land).  Directories are also objects.  Git records files and directories into a database that is indexed by the hash of their contents.  It then creates pointers between these objects to construct a map of what one particular revision looks like.


As complicated as this may seem, it is not something you need to understand thoroughly in order to use Git, thankfully.  Just know that Git has been engineered to be as light-weight as possible and this mechanism of code traversal is imperative to Git’s efficiency and speed.  

There are several resources on the web which can explain this architecture at a deeper level and I invite you to take a crack at learning it.  You’ll have a new appreciation to what many believe is the future of distributed version control software.

Though this primer may have taken a bit longer than 10 minutes, the goal was to show that Git is not some thing of magic or witchcraft.  It’s quite simple yet fast and powerful.  Many employers nowadays are assuming you’ll already have Git expertise so if you’ve held off this long without learning it, NOW is the time to hunker down and educate yourself