Elegant ways to support equivalence (“equality”) in Python classes

Consider this simple problem: class Number: def __init__(self, number): self.number = number n1 = Number(1) n2 = Number(1) n1 == n2 # False — oops So, Python by default uses the object identifiers for comparison operations: id(n1) # 140400634555856 id(n2) # 140400634555920 Overriding the __eq__ function seems to solve the problem: def __eq__(self, other): “””Overrides … Read more

How to show loading spinner in jQuery?

There are a couple of ways. My preferred way is to attach a function to the ajaxStart/Stop events on the element itself. $(‘#loadingDiv’) .hide() // Hide it initially .ajaxStart(function() { $(this).show(); }) .ajaxStop(function() { $(this).hide(); }) ; The ajaxStart/Stop functions will fire whenever you do any Ajax calls. Update: As of jQuery 1.8, the documentation … Read more