Random thoughts... I'll try to keep it mostly code-related: C#, SQL, ASP.NET, ASP.NET MVC, jQuery, etc.
Don't wanna be here? Send us removal request.
Photo

My MacBook Pro arrived today! I've set up all my dev tools including git, Xcode, Ruby, Rails, Sublime Text 2, homebrew, etc. Side note: The retina display is amazing. It's also nice seeing websites like GitHub and tumblr using high-res images (for the most part).
0 notes
Text
As I work with Ruby on Rails, I'm constantly amazed at how much ASP.NET MVC was clearly modeled after it. They really should have just called it "C# on Rails." They both have their strengths and weaknesses, obviously. I just thought this was interesting.
0 notes
Link
I find myself sometimes cursing the creator of some piece of software that I'm *trying* to use. Next time, I'll try to be nicer since somewhere in the world, someone might be cursing *me* for the software that they're trying to use.
0 notes
Text
I don't understand some people's irrational aversion to HTML tables. If you create a `
` and then style it like a `
` with rows and columns, you should have just used a table to begin with.
0 notes
Text
How 'git reflog' saved my life... twice.
A couple days ago I was getting ready to push some changes to GitHub. I was about 3 commits ahead on my local branch. I fetched from GitHub and started a rebase. I don't remember exactly what I did, but something went horribly wrong with the rebase. The next thing I knew, two of my commits were lost. Luckily, this same thing happened to me a couple months ago so I knew just what to do. When this happened a couple months ago, I did panic for a minute. _What was I going to do? Re-do all that work? Hours of work? Would I remember all the changes I made that had been lost?_ So I panicked for just a minute and then started thinking. I remembered learning that Git only adds data, so I knew there had to be some way to get my data back. After some Google searching, I learned what I needed to do. I ran `git reflog` to review the history of what happened. My output looked like this: 87b3a7e HEAD@{0}: commit: Fix merge issue 156cdb9 HEAD@{1}: reset: moving to 156cdb947d3f082958d8e656373685124ce73588 ac38e92 HEAD@{2}: checkout: moving from 156cdb947d3f082958d8e656373685124ce73588 to a_28381 156cdb9 HEAD@{3}: commit (amend): Refactored parts of xxxxx b449e7c HEAD@{4}: cherry-pick: Refactored parts of xxxxx b92ed00 HEAD@{5}: checkout: moving from a_28381 to b92ed00f00d4d1d55a226d5ddc0db871b61007f4 ac38e92 HEAD@{6}: checkout: moving from a_28381 to a_28381 ac38e92 HEAD@{7}: reset: moving to ac38e921c0e41f5af3bcc9d74b08f44a2d69b19d b8bc87e HEAD@{8}: checkout: moving from ac38e921c0e41f5af3bcc9d74b08f44a2d69b19d to a_28381 ac38e92 HEAD@{9}: cherry-pick: Implemented xxxx a2d2bc6 HEAD@{10}: cherry-pick: Minor changes/optimizations 6ead8ae HEAD@{11}: commit (cherry-pick): Refactored parts of xxxxx b92ed00 HEAD@{12}: checkout: moving from a_28381 to b92ed00f00d4d1d55a226d5ddc0db871b61007f4 b8bc87e HEAD@{13}: checkout: moving from a_28381 to a_28381 ... After reviewing the history, I determined that revision `ac38e92` was before the bad rebase. So then I just ran `git reset --hard ac38e92` and I had all my commits back. And if I had chosen the wrong commit, I could have just run `git reflog` again and reset to a different revision. This is why I love git. If something similar had happened with SVN, I would have been screwed.
0 notes
Text
Visual Studio 2012
We switched to Visual Studio 2012 last week at work. I volunteered to demonstrate some of the new features to our team at our weekly Engineering meeting. I learned about most of the new features from [this post](http://www.hanselman.com/blog/VisualStudio2012AndNETFramework45IsRELEASEDHeres5MinuteVideosToGetYouUpToSpeedQuick.aspx) by Scott Hanselman. There's a lot of cool new stuff, but I decided to just cover a few things that I thought the team would get the most use out of: HTML editor improvements, strongly-type data controls, model binding, and the Page Inspector.
0 notes
Conversation
This happens more than I'd like to admit...
John: hey, i don't see any changes committed for case xxx
Cory: hmm
Cory: pretty sure I pushed them
John: oh nvm, i just needed to fetch again
John: lol
0 notes
Text
Worst Practices Sample Code
I ran across this recently in some sample code. I won't say where it came from. Some names have been changed to protect... something. ... Application["ErrorString"] = errString; Application["InvalidUser"] = "true"; Response.Redirect("LoginError.aspx"); ... There are several things wrong with this. Foremost: Is there only going to be one client accessing this application at a time??? If you're going to store an error message to display on a separate page, _at least_ put it in per-user session state, not global application state. There was a lot of code I had to re-write in this sample application.
0 notes
Text
Mother Knows Best
Remember when your mother told you that you shouldn't use reflection to access private/protected/internal methods or properties? She explained that internal implementation details won't be guaranteed to exist in future versions. But you knew better. You went ahead and wrote some code to call some internal method in the .NET Framework. Then Microsoft changed it... your mother was right. I wrote a class to encrypt cookie values based on [this article](http://www.codeproject.com/Articles/13665/HttpSecureCookie-A-Way-to-Encrypt-Cookies-with-ASP). It uses reflection to call the internal `Encode()` and `Decode()` methods on `System.Web.Security.CookieProtectionHelper` (also internal). The method signature has apparently changed in .NET 4.5 and the code breaks with this exception: System.ArgumentException: Object of type 'System.Int32' cannot be converted to type 'System.Web.Security.Cryptography.Purpose'. The application doesn't even need to be set to target .NET 4.5. It starts breaking once .NET 4.5 is installed. Fortunately .NET 4.0 introduced the [`System.Web.Security.MachineKey`](http://msdn.microsoft.com/en-us/library/ee360261) class with public [`Encode()`](http://msdn.microsoft.com/en-us/library/system.web.security.machinekey.encode) and [`Decode()`](http://msdn.microsoft.com/en-us/library/system.web.security.machinekey.decode) methods which accomplish basically the same thing as the internal methods in the `CookieProtectionHelper`. I haven't tested it yet, but it's unlikely that cookies encrypted with `CookieProtectionHelper.Encode()` can be decrypted with `MachineKey.Decode()`. Also, in .NET 4.5, these methods are deprecated in favor of [`Protect()`](http://msdn.microsoft.com/en-us/library/system.web.security.machinekey.protect) and [`Unprotect()`](http://msdn.microsoft.com/en-us/library/system.web.security.machinekey.unprotect). So I'll have to update this code again very soon. These probably won't be compatible with `Encode()` and `Decode()` either. Always remember: _Mother knows best._
0 notes
Text
Crash Dump Detective Work
I recently had the misfortune pleasure of having to analyze a crash dump from one of our test servers. I fired up WinDbg, loaded the crash dump, and was able to quickly tell that a stack overflow was what was causing the w3wp.exe service to crash.
However, getting a managed call stack was way more complicated than it should have been because the version of .NET running on the server was different than what was on my machine (4.0.30319.239 vs 4.0.30319.269). I found this answer on StackOverflow (ironic?) and was finally able to get the managed call stack.
It turned out to be an issue with Html Agility Pack. We had never had any problems with it before, but could reproduce it with a certain HTML file. There are currently 8 open issues related to StackOverflowExceptions so we're not the only ones to have come across this. A bug in a library that will crash a whole process seems like kind of a big deal to me, so I'm surprised it hasn't been fixed yet.
We needed a quick work-around, so we modified the code to keep track of how deep its recursion was going and to throw an exception if it got above 4k. We may end up re-writing part of the library to not use recursion.
0 notes
Link
Some of these are really funny. Here are a couple of my favorites with examples that I've seen: ###"Yoda Conditions" if ("true" == Request.QueryString["Redirect"]) { ... } ### "Stringly Typed" public DataTable GetData(string sStart, string sEnd) { DateTime dtStart = DateTime.Parse(sStart); DateTime dtEnd = DateTime.Parse(sEnd); ... }
0 notes