Thursday, October 23, 2014

Git Tip: find unmerged branches

Here is handy little git command to find merged or unmerged branches.

The command is as follows

git branch <whereToLook> --merged <branch>
Where to look can be :
  • -l locally (default)
  • -r remotely
  • -a both
  • The branch to check. The default is your current branch.

To find merged branches both (remotely and locally)

git branch -a --merged

To find unmerged branches remotely and locally)
git branch -a --no-merged
To find unmerged branches we append the merged command with no

If you don't specify a branch it will default to your current branch.

Monday, May 19, 2014

Simple web server on mac

Here's a cool little command that you can use to start a simple web server to any directory on your mac.

  1. Open terminal 
  2. Navigate to a directory 
  3. Execute the following command
    python -m SimpleHTTPServer 8000

Friday, July 20, 2012

Nifty Trick: Minimize remote desktop from your keyboard

Every time I try to go mouse-less I find one or two programs that have me reaching for the mouse. Remote desktop is one of those programs.

I found a nifty short cut to exit full screen mode in remote desktop. All you have to do is press CTRL + ALT + Break. To go back to full screen mode use the same key combo.

Thursday, July 19, 2012

I'm a Published Apple Developer

Over the last several months I had the pleasure of making an iPad app for eCompliance. It's a simple application that allows one to perform an inspection. The application comes with a number of predefined inspections or you can create your own. The name of the application is ec-InspectionPad. 

Learning to program in Objective C wasn't as difficult as I thought it would be. The most challenging aspect of learning Objective C was the absence of many .Net language features that I've grown a custom to. For example, objective C does not have anything similar to LINQ or generics. If I've learned anything from working with Objective C it's that C# is a progressive modern language that I would much rather work with.

Just an example of a method call in Objective C.
[redirect to:ec-InspectionPad. andOpenInANewWindow:YES] 

Monday, July 25, 2011

Reshaper 6 JavaScript Support

JavaScript support in Resharper 6 is absolutely amazing. I was playing around with KnockOutJS and was surprised to find intellisense. Even Ctrl + p worked to show the signature of a JavaScript function. If you do alot of JavaScript I highly recommend Resharper 6.

Sunday, July 24, 2011

Visual Studio 2010 JScript Editor Extensions

Install it. Enough said.

Monday, July 19, 2010

NHibernate Detached Criteria is not Reusable

While working on a paging feature for our application I discovered that the NHibernate detached criteria is not reusable. My goal was to create a single call to a repository using one detached criteria. The Idea was to reuse the detached criteria to perform two queries. One query to retrieve the total number records. The second query to retrieve a list of items for the specified page number and number of records per a page.

On the repository we have the following method.
QueryResult<T> FindBy(DetachedCriteria query,int pageNumber,int numberOfItemsToDisplay);

The QueryResult returned from the repository has a total and the items for the requested page.
public class QueryResult<T>
        public int TotalNumberOfItems { get; private set; }
        public IEnumerable<T> Items { get; private set; }

        public QueryResult(int totalNumberOfItems, IEnumerable<T> items)
            TotalNumberOfItems = totalNumberOfItems;
            Items = items;

Here is my implementation of FindBy. I had a few helper methods but removed them to fully illustrate the problem.
   public QueryResult<T> FindBy(DetachedCriteria query, int pageNumber, int numberOfItemsToDisplay)
            var pageIndex = pageNumber - 1;
            var firstResult = 0;

            if (pageIndex != 0)
                firstResult = pageIndex * numberOfItemsToDisplay;

            ICriteria executableQuery = query.GetExecutableCriteria(CurrentSession());

            var count =  executableQuery.UniqueResult<int>();


            var items = FindBy(query.SetFirstResult(firstResult).SetMaxResults(numberOfItemsToDisplay));

            return new QueryResult<T>(count,items);

The confusing part
ICriteria executableQuery = query.GetExecutableCriteria(CurrentSession());
Calling getExecutableCritieria returns an ICrtieria object. One would think that the criteria object does not have a connection to the detached query object. Calling the code below should not change the detached criteria.

var count =  executableQuery.UniqueResult<int>();
The quick fix is to set the projection to null and reset the result transformer.


//Excute new query
var items = FindBy(query.SetFirstResult(firstResult).SetMaxResults(numberOfItemsToDisplay));

In Summary
I find the behaviour of the detached criteria object to be somewhat odd. It might just be a misunderstanding on my part but the API led me to believe that the ICriteria object had no relationship to the detached query. The coupling between the ICriteria object and detached criteria was a big surprise. If I were to ask I bet the NHibernrate/Hibernate team or even Oren Eini could provide me with an explanation.

Sunday, July 18, 2010

Razor View Engine for Asp.Net MVC and More

Microsoft has done it again. They are releasing a new view engine for Asp.Net MVC code named Razor. Even more impressive is the fact that you will be able to use more than one view engine in your application. This means that you can develop an application using the web forms view engine, spark and razor. To learn more head over to Scott Gu's blog. The new view engine is slated to be released with the next version of MVC.

In other news Microsoft is working on two other products: IIS Express and SQL Server Compact Edition 4. With IIS Express you can have a full featured web server that does not require administrative privileges. This is wonderful news for the security conscious developer with a locked down machine(for example this guy). IIS Express unlike the built-in web server in visual studio will support SSL and url rewriting. From what I can tell it will do pretty much anything IIS 7 does. According to the Gu it will be released as an patch for Visual Studio 2010 later in the year. All versions of Visual Studio in the future will be shipped with IIS Express.

SQL Server Compact Edition 4 is another cool product that will work with Asp.Net MVC. SQL CE doesn't require any installation. It's as simple as dropping a few dlls in the bin of your application. When your application starts SQL CE is loaded into memory and when the application stops it is unloaded. Even better is the ability to easily upgrade from SQL CE to SQL server express, SQL server or  even SQL Azure. This means that you can start an application with SQL CE and then upgrade when your application grows beyond the limitations of SQL CE. Visual Studio 2010 will also feature support for SQL CE. It might just be me but Visual Studio is starting to become a one stop shop for everything, and I like it. Fortunately SQL CE does not support stored procedures. Stored procedures are evil so no big deal there. It's also important to mention that you do not have to change any code to work with SQL CE. It should be as easy as changing your connection string.

Monday, April 5, 2010

10038 Jolly Jumper Solution

Here's my Jolly Jumper solution. It was accepted by UVA online judge. It may not be the best solution but at least its readable.

My Algorithm is designed to fail quickly. As it calculates each sequence number it checks against three simple rules

  1. The sequence(n) number cannot be 0
  2. The sequence(n) number cannot be equal or greater than the input(numbers in my code). If there are 4 numbers then the sequence should contain the numbers 1,2,3
  3. There cannot be duplicates.
My solutions took 0.304 seconds to execute. Compared to the best, my solution is rather slow. The best solutions were written in C++ and ANSI C. Their run time was a flat 0. It would be rather interesting to see if  I could get an even faster run time. The only problem is that I'm using Java which is going to be slow from the get go. On the bright side I am one of 9546 users that have solved this problem.

My solution came as a result of refactoring. My original solution did not fail early. Instead it gathered all sequence numbers, sorted a list and then checked that it had the correct numbers. My original solution had an execution time of about 0.36 well my new solution executed at about 0.304. Although my solution isn't the fastest's I do enjoy its readability.

The problem can be found here

Sunday, April 4, 2010

Algorithms Book Club

Well the book club I am a member of is at it again. This time our book club is tackling Algorithms in all its fun and glory... The book we are reading is "The Algorithm Design Manual" by Stenven S. Skiena.

Our first session covered the wonders of big O notation (asymptotic Notation). I'm happy to say that complexity is growing linearly at O(n)... but some days I swear its like O(n!).

Our second session covered big O again...

Our third session uncovered the mysteries of data structures.

Our next session is perhaps more ambitious. We are going to step into the arena and knockout a few algorithms.

The Arena:

My Weapon of Choice: Java

The Problems:

Jolly Jumpers (Solved)

Where's Waldorf?(Unsolved)

Crypt Kicker(Unsolved)

Crypt Kicker II(Unsolved)