Posts

Showing posts with the label Programming

Benefits of Working with .NET ConcurrentQueue<T>

Image
* Working with a queue in .NET is an excellent experience and provides a great way to decouple execution paths. Once you start working with in memory queues your just a hope, skip, and a jump away from using "infrastructure" queues such as Service Bus, RabbitMQ, or even MSMQ on Windows Desktop. While it is quite possible to work with the standard .NET Queue<T> object if you find that you are in need of using a lock to ensure consistent results with putting things in the queue (i.e. Enqueue) and taking things off (i.e Dequeue or Peek) or even just to obtain a consistent reliable count, well then you should probably take a look at ConcurrentQueue<T> . There is a whole section of the .NET Framework with deals with concurrency concerns by creating specific objects for Dictionaries, Stacks, Queues and more that are considered thread safe. When I started working with ConcurrentQueues I found it helpful to put my own wrapper around the concurrent queue object and...

Things I need to remember... IIS Express ports for HTTPS and Configure WCF Rest endpoints for HTTPS

Image
As I have been writing consistently for a bit now I've already found myself referring back to things I've posted, which has prompted me to try and post items which have taken a bit of time to work out. It seems that the act of "writing it down" causes me to remember information better. Perhaps it's all the thought into attempting to write something useful. This post includes two details which took me more than a few hours to sort out so I hope to help others who have a similar need. Funny enough it could be me in the future after I've forgotten this information. First up is a little detail that I know I've forgotten and looked up more than once, and depending on the google/bing results I find sooner or later. Setting up IIS Express to host a site via HTTPS When configuring your site to run in IIS Express using Visual Studio it's fairly trivial to set the attribute to use SSL (i.e. HTTP over SSL which is HTTPS) as it's just an ...

.NET MSTest and DeploymentItem Attribute

Image
I was recently reminded that order of operation can byte you when trying to troubleshoot intermittent unit test failures. First, I’ll be the first to admit that if you want to avoid problems with unit testing it’s best to avoid any dependency outside of your actual code base, things like databases, API and even the file system are best avoided in execution of your unit tests. That last one, the file system, in some applications is really hard to avoid. If you happen to be using MSTest, a helpful attribute for your test is DeploymentItem. This particular attribute allows you to define a file within your unit test project assuming it’s marked as “Copy Always”. With this attribute in place you can then combine this with TestContext.DeploymentDirectory to find this sample file and then do what you need to do. In my particular case I was having an issue with the unit tests failing on the build machine but not locally. After stumbling around for a bit I finally feel back to t...

Talk to the Rubber Duck

Image
*See attribution of image at the bottom. One of the greatest tricks I have had the pleasure of participating in is that of helping someone solve a problem simply by listening. I'm sure there is a more accurate description of this phenomenon, but in the world of programming it's called Rubber Duck Debugging . I was first introduced to this idea from listening to Jeff Atwood podcasts/interviews as well as reading his blog under CodingHorror.com  he wrote about the topic under the title Ruber Duck Problem Solving . Why the term Rubber Duck? Really it has nothing to do with the rubber duck, the intent is to encourage someone to solve their own problems by working through the very difficult challenge of describing what the problem actually is. It is often surprising to people when they discover that simply the act of attempting to describe a problem helps them to find the answer they were looking for. So my approach to assist others is by asking questions that I often ask...

Example of using LazyInitializer.EnsureInitialized

Image
When looking at making systems more efficient it's helpful to think about being lazy. A helpful tool in the .NET tool belt is the static class under the System.Threading namespace LazyInitializer. In particular this class contains a method  EnsureInitialized This method is very simple to use and provides a convenient way to ensure that an initialization is called only once based on the value of the target property already being populated. For example, if you need to load a file as part of the setting of values in an application you can use the EnsureInitialized method. The following is a derived example of using the class to illustrate the usage pattern. If you are having trouble viewing the below code you can use this link to view the gist github. https://gist.github.com/briannipper/ac2778ccd0d15b4ab217083331419ae7 using System; using System.Collections.Generic; namespace Example.EnsureInitialized { class Program { static void Main(string[] args) ...

There is NEVER one person working on your code

Image
Alternate Title: Avoid “Black Boxes” and “Works on my Machine” Even when working on a project by yourself it is important to try and create a build script that will “fully” build your project with a single click. But, you may be asking, why would I bother with a build script if there is only one person working on the project? Well the reality is that there is NEVER one person that works on a project. There may only be one person working on a project at a given point in time, but if the project succeeds (a.k.a. it has additional releases in the future) there will be other developers involved. Either a future developer will work on the project on their own, or additional developers will join in. I’m of the opinion that the latter is far more likely if a build script already exists and those other developers will thank you (as would I) that they have some transparency into how the code should be orchestrated for a deployment or in other words avoid the “black box” problem. In a...

Don't leave your users hanging

Image
command prompt can show actions as they are taken If you create software one of the worst experiences you can create for your users is the "hanging" dialog. Recently I obtained a somewhat older MP3 player; to be specific it is a SanDisk Sansa Express 2GB. The device itself is on pair with most MP3 players that are not an iPod. One interesting feature is that you can record from the radio and it just so happen that the weekend past I had a need to record some audio from an FM station being used to broadcast at an assembly I was attending. To skip to the interesting point I found myself attempting to install new firmware to make it possible to listed to the WAV files created from the recording. After installing something to install something else (can you say inception) I found myself in a state of frustration because it "seemed" like the firmware update was going through just fine; however, the dialog box which indicates the progress had been "seemingly...

Perspective and Puzzles

Image
Reversible figures and vase. From Wikimedia Commons I recently remembered a ted talk from a while back about optical illusions and how our eyes can be heavily influenced by the context of what they see, or as mentioned in the talk, "the light that hits our eyes is not what is important, rather it is what we do with the information once it hits our brain that matters." To help illustrate this point the image here shows a famous "illusion" in that depending on your perspective the black area is the silhouette of two faces, or the white area forms a vase, in reality both are true and it is a mater of perspective on which view is "correct". FYI, I believe depending on how my day is going one or the other is true. :) I've also been rediscovering the fun I have playing Sudoku . It's interesting how organizing numbers into patterns according to rules fosters a sense of accomplishment. Probably informs my career choice of...

Why I HAD to install Linux

Image
Recently I've decided to pick up a new programming language. My reasons are mostly not wanting to be hacking away at legacy code for another 5 years. I've already started to realize that in my young programming career I'm already getting behind the curve in the programming world. In any case I decided to work with a few colleagues on a side project, not that we have a project per se, just a few general ideas and a desire to make things. Part of our goal with this project is to learn various aspects of newer technologies, Pearl, Python, GIT, Tornado, etc. At first I was under the impression that learning these various language/technologies would not require me to change my default OS Windows (currently split between windows 7 on my desktop and windows XP on my laptop). However, even being comfortable with the command line on windows I was finding that as I read various sites discussing approach and technique for these newer tools I was feeling like a second cla...