All posts in Coding

Alpha-Blending Colors in PowerShell

The other day I was given the task of converting a particularly poorly designed VisualBrush into a LinearGradientBrush. One of the problems I came across very quickly was the use of semi-transparent colors layered on top of each other, and, of course, I needed a “flattened” color for my GradientStop. Now, I could have used Paint.NET or GIMP or Photoshop to put out a couple layers of colors, set the transparencies and used the color dropper to get the result. Of course, since I’m not a designer, I don’t have any of those things installed on my work computer, so I decided to just find the equation to blend the channels myself. It didn’t take long, and Wikipedia delivered the goods. According to the article, the formula to merge two colors, C_a and C_b, into some output color, C_o, looks like this:

C_o = C_a\alpha_a+C_b\alpha_b(1-\alpha_a)

Since a color can be thought of as a three-tuple of its R, G, and B channels, the formula is easily distributed to each of these values.

At this point, I decided I could probably just pull out a calculator and crunch the numbers. But maybe, in about the same time, I could also whip something together, say in PowerShell, to do it for me. Since I’m still learning PowerShell, I figured the learning experience would be worth at least something. Read more


The Extension Method Pack

Since .NET 3.0 came out, I’ve been enjoying taking advantage of extension methods and the ability to create my own. The thing I’ve noticed is that a handful of them are useful to almost any application, above and beyond what Microsoft provides in System.Linq. So over the last few days I took the time to gather these methods together, unit test them, and run them through FXCop to make a high-quality package ready to go in any application with a little re-namespacing.

I’ve broken each code sample into independent blocks wherein all necessary dependencies are contained, so you can take any extension method a la carte or you can get everything from the attached zip file. My solution was built in .NET 4.0 in Visual Studio 2010, but everything should work just fine in .NET 3.5 with Visual Studio 2008.

Also included in the zip file are my unit tests, which may help you understand usage of some of the more esoteric extensions, such as ChainGet, and XML comments for your IntelliSense and XML documentation generator. Read more

Attached Files:


Single Instance ClickOnce

I’m currently working on a project where the client wants to be able to click on a link and bring up a WPF UI with relevant information and available actions. Furthermore, the client wants to be able to keep clicking links and continue to reuse the same instance of the WPF UI. We decided our best option would be to go with a ClickOnce deployment, but we were unsure of how to get the web page to talk to our application. Read more


The Qualifications for Writing Textbooks

It’s certainly true that there are many unqualified authors that the self-taught programmer has to look out for, but what about the textbooks we read at universities? I won’t argue for a second that tenured professors are the least bit unqualified to discuss the intricacies of algorithms and abstract data structures, but who writes the book on using real world implementations? Who is qualified to write the book on Java or SQL Server? I’d want to see someone who has been using the technology for several years or a good portion of the technology’s life if it’s relatively new. Unfortunately, I find this is rarely the case. Read more


The Definition of Computer Science

What is Computer Science?

It’s always interesting to see how different people answer the question. Especially people who have or plan to have degrees in it. Dictionary.com defines it as:

the science that deals with the theory and methods of processing information in digital computers, the design of computer hardware and software, and the applications of computers.

I see this broken down into:

  • Science
  • Theory
  • Design of hardware and software
  • Applications for computation

Normally, I’d say fighting the dictionary on definitions would be rather fruitless, but this is by far one of the most vague definitions I’ve ever seen. I think a good analog for CS is math and physics. In that much more mature field, mathematics provides laws that say x should exist. It is then up to the applied physicist to prove in a lab that the theory is true. Even then, it is up to a company and its engineers to productize and actually use the fruits of science. Computer Science, in stark contrast according to this definition, is all of those things rolled up into one. It’s no wonder why no one in this field knows what it means. Read more