Garage Sale Code

Scott Hanselman has a great post about “Garage Sale Code”. I decided to do my part and provide a link to my “Garage Sale Code”.https://esterline.devguard.com/svn/code/If you have any questions about the code, please feel free to ask.

Advertisements

Ruby – Assigning a block to a variable

On Friday, Brian and I were discussing how to assign a block to a variable in Ruby. I knew how to pass a block as a method argument def method(&proc), but I could not remember how to just assign a block to a variable. I finally looked up the syntax.

block = lambda { |word| puts word }block.call("adam")

C# Multi-Type Generic Constraints

Today, I wanted to place constraints on a multi-type generic. Here is my starting point.public class MultiTypeGeneric<A,B>I wanted to put a constraint on A and B. I did several Google searches to find the syntax. There were suggestions, but none of them seemed to work. Here is the solution that finally worked.public class MultiTypeGeneric<A,B>where A : IComparablewhere B : IComparable

Converting String to byte[] and back again

I was working with some networking protocols in C# and I needed a way to convert from a string to byte[] and back again. It took a little time to find the answer, so I thought I would write it down for the next time that I would need it.The secret is in the System.Text namespace.byte[] bAdam = new ASCIIEncoding().GetBytes("Adam");string sAdam = new ASCIIEncoding().GetString(bAdam);byte[] bAdam = Encoding.ASCII.GetBytes("Adam");string sAdam = Encoding.ASCII.GetString(bAdam);

Thanks to James Manning for his suggestion on using the Encoding.ASCII property instead of creating a new ASCIIEnoding instance (as well as other mistakes he pointed out).