Circuit City Sucks [rant]

Warning: off topic rant, sorry.

If you are going to buy anything from Circuit City be warned that you will be dealing with either lying

or ignorant and lazy sales people and rude customer service.

Recently on two different occasions I bought a product based on what the sales

person told me and both times they were completely wrong.

The first

time was regarding a Sony handy-cam, they had two models, one was the DCR-SR82 (with a 60 Gig drive) and a DCR-SR42

(with a 30 Gig drive). The sales staff claimed they were the same

except for the drive size, which is completely false. I found this out

after getting home, and reading the manual. It turns out Sony

also has a DCR-SR62

which is the same as the 82 with a smaller drive. One huge difference, among many,

is that the 42 doesn’t record in wide screen format. So I took it back

and had to get the manager of the store to issue a refund. Which he

finally did after talking to the head camera guy who confirmed my

claims. End result: bought the SR62 elsewhere (online).

I’ve shopped at Circuit City a lot in the past, and so I thought, maybe the sales

person was just new or something. So, I wanted some speaker mounts for my front

speakers and I gave Circuit City another shot. When asked if I need

help, I ask if the speaker mounts I’m looking at will fit

my speakers and proceeded to show the sales guy which speakers I have

(bought from them). He say confidently that they will work with those

speakers. I get home and surprise they don’t. So today I took them back

with the intention of getting the right ones. When I returned them, I

told the CSR

that these don’t fit my speakers, even after showing the sales guy which speakers

I own. He says “That sucks. You should yell at him.” in a very

sarcastic, I don’t give a shit, way. I was shocked to be treated so

poorly. So, I’m done with Circuit City. It’s right on it’s way to being

the next CompUSA.

Too bad really, because at one point they were much better then Best Buy

(the worse electronics store ever), and I bought a lot from them then.

Circuit City sucks, don’t buy from them.

IoC smell: Having IContainerAccessor as a dependency.

Looking back, it should have been an obvious thing to not do, but it wasn’t. I wanted to get access to the container and so I made IContainerAccessor a dependency for my class. The I added that to the container. The Main problem was that the IContainerAccessor interface was implemented on the class that also created the container. So, after startup I had two containers, one I created for the application and one that container created when the IContainerAccessor was created.

Okay, there are other ways to implement the IContainerAccessor, but is that what I really needed? No, I really needed a way to create a specific kind of component. Maybe like a factory of some sort. Oh, yea the factory pattern is already sitting around waiting to be used. And it was a good solution here.

That makes me think, for most cases where you want the container directly, there is a better solution waiting to be used.

Prefer Equals over operator== because generic types will not behave how you expect

I stumbled across this unit testing some Immutable model objects. I’m overriding equals on these object and as so thought, how about I create a generic method to test equality? Sounded like a good idea, got rid of some duplicate code, made sure I’m testing all the variations on each object. Then my tests Failed! WTF? It turns out that using == on Generic Type objects is a bad idea, even it you’ve provided you own operator==! Even if you’ve implemented the IEquatable interface!

This is bad:

private static void TestGeneric<T>(T first1, T second1) where T:class 
Console.WriteLine("{0} == {1} is {2}", first1, second1, IsTrue(first1 == second1));

The compiler will emit IL that does two odd things, IMO. First, box’s the args first1 and first2. That’s a waste as they are constrained to be classes. Second it’s calling the IL method ceq (check equals). Why doesn’t it call Equals()? I’m guessing there are reasons for this, as it’s the same behavior in 3.5. Maybe if you meant to call Equals you should have?

This is good:

private static void TestGeneric<T>(T first1, T second1) where T:class 
Console.WriteLine("{0} Equals {1} is {2}", first1, second1, IsTrue(first1.Equals(second1)));

The above code won’t box the objects and it will call your overridden Equals method as expected. I know it’s been said before, but alway use the Equals method!

One more interesting thing with the class constraint you can’t use the == syntax. I guess because once the box and class ceq it will break operator== for value types.

Worse is that if your type constraint is a specific class it will allow and call the operator== method but only on that class so any subclass that are passed in will use the base classes operator== for the compare.

Full code to see this in action is attached:

Program1.cs (2.38 KB)

Getting Finance::Quote installed and working on windows for GnuCash

A little off the coding topic. I use the windows version of GnuCash as such I wanted it to be able to get stock and fund updates automatically. This took a bit more work then I expected so I hope this helps someone else.

  1. Install active state perl
  2. Install OpenSSL Win32
  3. Install nmake following these directions
  4. Run the Perl Package Manager from the start menu and install the Crypt-SSLeay package
  5. From a command prompt in C:\program files\gnucash\bin run perl -w gnc-fq-update

That should be it. One think to note, as far as I can tell you have to call update from the command prompt while your GNU file is Not open. As described here.

ThreadPool + Async methods + ManualResetEvent = Bad

Okay, today it was re enforced that the ThreadPool is not good for long running tasks, specifically those that might use the ThreadPool or use async methods or ResetEvents. I didn’t really track down the root cause, but generally it locked while waiting for a set event. Regardless, the solution as is usually the case was to simplify the code. First by not using a ResetEvent and ThreadPooling for queuing the workload. In place of that a simple QueueRunner class was created using the Monitor class. Using the Monitor.Wait and Monitor.Pulse was new to me, but works well and seems to be very fast. There is a great article here about threading in c#. I’m not going to re-explain what already been said there, but below is the code. It could be enhanced for other uses and performance.

public class QueueRunnerTest
private int _count = 0;

public void Test100ExpectSuccess()
Queue<int> queue = new Queue<int>();
for (int i = 0; i < 100; i++)

_count = 0;

QueueRunner<int> runner = new QueueRunner<int>(Work, queue);

Assert.That(_count, Is.EqualTo(100));

private void Work(object obj)
Console.WriteLine("Working " + obj);
Interlocked.Increment(ref _count);

class QueueRunner<T>
private readonly object _syncLock = new object();
private readonly Queue<T> _queue = new Queue<T>();
private int _running = 0;
private readonly int _maxThreads;
private readonly ParameterizedThreadStart _workerDelegate;
private int _toBeCompleted = 0;

public QueueRunner(ParameterizedThreadStart workerDelegate, Queue<T> queue)
: this(workerDelegate, queue, 5)

public QueueRunner(ParameterizedThreadStart workerDelegate, Queue<T> queue, int maxThreads)
_workerDelegate = workerDelegate;
_maxThreads = maxThreads;
_queue = queue;
_toBeCompleted = _queue.Count;

public void RunAndWait()
new Thread(Start).Start();

private void Start()
lock (_syncLock)
while (_queue.Count > 0)
while (_running < _maxThreads)
new Thread(DelegateWrapper).Start(_queue.Dequeue());
Interlocked.Increment(ref _running);

private void DelegateWrapper(object state)

private void Wait()
lock (_syncLock)
while (_toBeCompleted > 0)

private void DecrementCount()
Interlocked.Decrement(ref _running);
Interlocked.Decrement(ref _toBeCompleted);
lock (_syncLock)

Threading in C# - Joseph Albahari
Delegate BeginInvoke and ManualResetEvent.WaitOne()

Deleting multiple objects with NHibernate using a query

I needed to delete a bunch of objects based on some parameters of those objects. It fairly obvious that one of the Delete overloads on ISession would work, but a couple of things throw me. First you need a full select query, not too hard to figure out. But second, where are IType’s defined? In NHibernateUtil (thanks to this). Anyway, here is some sample code. I’m guessing there might be a more efficient way, but this should work for most cases.

session.Delete(“select b from Bar as b where b.Instrument = :instrument and b.BarMinutes = :barMinutes”,
new object[] {instrument, barMinutes},
new IType[]
NHibernateUtil.Entity(typeof (Instrument)),
NHibernateUtil.Enum(typeof (BarMinutes))

Update on the AIM bot, new Amazon web services S3 Library


I’m still working on the AIM Bot, converting from boo to c#. I really liked working in boo, but just don’t feel like I have enough comfort in it to continue working in it. Anyway, I’ve decided to use the Amazon web service S3 for my data storage and have created an open source project, AwsS3Library, to connect to it.

It’s pretty basic so far, listing buckets, and object, and getting, putting, and deleting buckets and objects. The usage isn’t too hard to follow, I’d suggest looking at the unit tests if your stuck. You will need to use your own AWS key and AWS Secret key.

AwsBucket awsBucket = new AwsBucket("bucketName");
AwsS3Service service = new AwsS3Service("AwsKey", "AwsSecret")
awsBucket = service.Put(awsBucket);

There is an intermediate issue with putting objects, which results in a timeout. I think it has to do with trying to put an object right after creating a new bucket. I’m not sure how or if this should be addressed by the library. I’m going to change the tests to create a bucket for the objects and one for testing the bucket functionality. I think that should help.

It’s released under the BSD License to feel free to use and submit fixes.

Brutalist Framework