Author: Pete

Git

Get Your Git On

Can You Dig Git? (from http://blog.aquabirdconsulting.com/?p=262)As I stated in my 2011 technology resolutions, I really wanted to make an effort to learn Git this year. I started with learning some Git Immersion, which I documented as well.

Well, since I like to go big or go home, I decided to start using Git at work full time. We have a big project that we started last week that requires us to branch our code and maintain this “catastrophically different” branch and our “hotfix” branch so that we can still get any bug fixes or emergency features to production in the meantime.

As many of you who have worked with it know, doing a long running branch in TFS (our old VCS) SUCKS hard. The merge would have not been fun. On top of that, switching between the branches to perform bug fixes wouldn’t have been fun either. We would have had to maintain separate directories, which means remapping local IIS routes for testing, etc. Disaster city.

However, when I saw that when you jump between branches in Git and your directories and files just “magically” transform into what you expect them to be in place, I was sold. We had to have that wizardry. Since Chris already knows him some Git, I felt like I was working with a safety net, so we went for it.

Chris used spraints’ git-tfs to migrate our TFS source (with history!) into Git so that we literally lost nothing in the transition. One note of warning was that it had trouble with a very large binary file that we had checked into source due to some memory constraints. We hard deleted it from TFS and the migration went much more smoothly from that point, though Chris still had to work some magic. Maybe he’ll blog it???

We’re officially about a week and a half in with Git and we actually haven’t had as many problems as I had feared. We had a little scare last week when a deployment went wrong, but it turned out that we ended up with a weird WCF issue that forced us to need to reproxy in every project that consumed that service. I had worried that Git had messed up our very large file, but we did some experiments and proved that it behaved exactly as it was supposed to. (Good thing, too, or that “three” I shot in pulling the trigger on the Git switch might have cost me an earful.)

Next blog, I’ll show everyone what “magic” really impressed me with Git. People who are old had at Git will maybe scoff at what I thought was mind-blowing, but I imagine some VSS/TFS-only users may have their face melt off and children will weep over their exploded bodies. (update: I’ve blogged the example here)

Rails

Rails for Zombies

Rails for ZombiesOn Thursday of this past week, Chris and I did a brown bag “lunch and learn” at work. Our original plans fell through, so we decided to hit up Rails for Zombies and see what it is about.

I really like the format of the tutorial and the way that the labs are constructed. If you follow the process exactly, you create an account so that they can track your progress so you can return at any time and pick up right where you left off. Then you watch several 5-10 minute videos and then complete an interactive session in your browser after each one.

Here is a screenshot of the first video’s title screen. It definitely helps you get a feel for how *in* to this the good folks at Envy Labs are.

Lab One Video

The goal of the project is that we are building a “Twitter for Zombies” so that they can be all social and stuff. All of the code that is written is around that goal. Here’s what it looks like when you get into the lab.

Lab One Exercise

You can see that after I write my code and submit it, I get instant actual IRB-like feedback. If I were to have made a syntax error, I’d get that back, as well. It seems to be doing true evaluation, as Chris entered some alternative, more advanced ways of performing the labs and it was all evaluated correctly, too.

Lab One Exercise Solved

There is definitely a benefit to not having to set up Ruby and Rails on your machine before you get some exposure to Rails. Just like if I was trying to pick this up by pairing with someone, you don’t start at the beginning with this project. There is no project creation, scaffold generation, database setup, etc. You start in on a project that is kind of already underway.

Several things you do are never really explained and some things you do are explained at the very end (like generating links in the view based on named routes). I supposed I could have suspended belief a little until I got to lab five to learn it, but I ended up asking Chris a lot of questions as we went along.

As I said, I really like this format for teaching and conveying new programming topics to people. I’m really impressed at the work that Envy Labs put in. At the same time, you could complete this entire lab and not know how to even begin your own Rails project. However, if you couple this training with all of the existing Rails tutorials that try to get you up and running in 10 minutes and I think that you could have the knowledge you need to get pretty far into making your own Rails app from your own concepts.

Git

Git Immersion

Got GitI’ve begun tackling my 2011 technology resolutions. It was as if the good folks at EdgeCase read my blog and deigned to help a brotha out. They’ve recently launched Git Immersion, which does for Git what their Koans did for the masses. That is, it offers a simple, step-by-step way for someone to learn a technology.

I already learned something. Doing Lab 3, it says to issue this command

git commit -m 'First Commit'

When I do, I get this error

error: pathspec 'Commit'' did not match any file(s) known to git.

A little of my Google-Fu and I find that my windows command prompt is anti me using the ‘ here. I change the command to

git commit -m "First Commit"

and I get the right result

[master (root-commit) d23d927] First Commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 hello.rb

Another thing I learned. When I typed “git commit” with no -m (Lab 8), it brought up VIM. Guess what? I’m such a n00b that I couldn’t figure out how to save my freaking file. Thank goodness for StackOverflow here to tell me to hit Esc then type :wq and then the enter key.

That’s it of my revelations so far. As I’m writing this, I am through the first 10 labs and will do some more after I post this. I’m really looking forward to learning Git because I like the way that it encourages you to work. On to some more learning…

Goals

2011 Technology Resolutions

ResolutionsI try to learn at least one new thing every year in the technology field. In 2010, I learned (and build a production application from) Asp.Net MVC 2.0. I also learned Windows Phone 7 development and even got an app in the Marketplace called Nerd News. You can see a little more about it here or by searching for Nerd News in the Marketplace.

In 2011, I’m beginning the year with the goal of learning more about Node.js, Socket.IO, and Git. I had hoped that CodeMash might have some Node stuff this year, but it doesn’t. Maybe I can find or start an open space about it…

Do any of you try to learn a new technology every year? If so, what are yours for 2011?

Project Euler

Project Euler Problem 4

TACOCAT is a palindrome!Continuing on from my previous adventures in Euler, we now come to problem 4. Problem 4 asks you to find the largest palindrome that is the product of two 3 digit numbers.

My solution is brute force, and originally, I started two loops both at 999 and counted down, figuring the first palindrome found would be the largest. I was wrong, however, and was required (sticking to brute force) to check all products for palindromes and just keep the largest. The “count backwards” code returned “Using 995 and 583, the max palindrome is 580085”, which is incorrect. My correct code is as follows:

using System;

namespace ProjectEuler
{
	/// <summary>
	/// A palindromic number reads the same both ways. The largest
	/// palindrome made from the product of two 2-digit numbers is 
	///  9009 = 91 x 99.
	/// Find the largest palindrome made from the product of two 3-digit numbers.
	///  http://projecteuler.net/index.php?section=problems&id=43
	///
	/// The answer is 906609
	/// </summary>
	public class Problem4
	{
		public static void Main(string[] args)
		{
			var max = 0;
			var theI = 0;
			var theK = 0;
			
			for (var i = 100; i <= 999; i++)
			{
				for (var k=100; k <= 999; k++)
				{
					var product = i * k;
					if (IsPalindrome(product) && product > max)
					{
						theI = i;
						theK = k;
						max = product;
					}
				}
			}

			Console.WriteLine("Using {0} and {1}, the max palindrome is {2}", theI, theK, max);
		}

		public static bool IsPalindrome(int number)
		{
			var forward = number.ToString();
			var reverse = forward.ToCharArray();
			Array.Reverse(reverse);

			return forward == new string(reverse);
		}
	}
}

That returns “Using 913 and 993, the max palindrome is 906609”.

After you put in the correct answer on the Project Euler site, you are allowed to then view the forums to discuss your answers. I found some interesting math inside that made other algorithms much more efficient. Here is what I gleaned:

A six digit palindrome would be in the format abccba. If we take our real answer of 906609, that could also be written as 9(100000) + 0(10000) + 6(1000) + 6(100) + 0(10) + 9(1). The same way, our generic answer can be written as 100000a+10000b+1000c+100c+10b+1a. Simplified again, that is 100001a+10010b+1100c. You can factor 11 out of that, leaving you with 11(9091a + 910b + 100c). That means that the product would have to be easily divisible by 11 (saving you the lengthy – by comparison – palindrome check). My original algorithm ran in 9.219022 seconds on my Mac Mini running Mono. When I add in the “divide by 11 check” to short-circuit every palindrome comparison, the algorithm now runs in 1.63679 seconds. That is a HECK of an improvement. Math… I think this might just catch on!