Mocking __iter__ with a magic mock in Python

Posted on Thu 29 March 2012 in Coding • Tagged with iteration, list comprehension, magic mock, Python

I just ran into a tiny little problem and thought I’d share the solution.

I was writing some tests in which I was mocking a dependency using Mock. My test code was roughly equivalent to the following (based on an example in the Mock documentation on magic methods):

>>> sub1 …

Continue reading

Nothing surprises me in VB.NET

Posted on Tue 27 March 2012 in Coding • Tagged with nothing, null, vb.net

I currently work in a VB.NET project with a customer, and what amazes me is that I over and over again get the feeling that the language is designed to be easy to work with, but at the same time there are so many aspects of it that behave …


Continue reading

NSubstitute vs Moq - a quick comparison

Posted on Mon 27 February 2012 in Coding • Tagged with mock, moq, nsubstitute, test

When you write unit tests, you occasionally need to mock away dependencies of the subject under test (SUT). By far the easiest way to do this is to use a mocking library, which has the added benefit that it allows you to verify the behavior of the SUT by inspecting …


Continue reading

Using Git locally within a Subversion branch

Posted on Thu 19 January 2012 in Tools • Tagged with git, subversion

I’m not a big fan of Subversion but I’m madly in love with Git! So much that when I have to use Subversion, I create a Git repository within my locally checked out Subversion branch. This is really easy to do, and only takes four simple steps:

  1. Navigate …

Continue reading

LVM recipe: determine which physical volume(s) a logical volume is located on

Posted on Thu 19 January 2012 in Sysadmin • Tagged with lvm, recipe

Run the lvs command as follows:

# lvs --segments -o +pe_ranges

The output should be something similar to this:

LV      VG   Attr   #Str Type   SSize   PE Ranges
data    data -wi-ao    1 linear   1.82t /dev/md4:0-476930
data    data -wi-ao    1 linear   1.36t /dev/md2:0-357701
homes   data -wi-a-    1 …

Continue reading

Node.js experimentation - a GitHub clone script

Posted on Thu 19 January 2012 in Coding • Tagged with async, git, node.js

Recently I wrote my first Node.js program! Yeah, yeah, I know! Late to the game and all that! But I thought it was time to catch up with the rest of the world. Better late than never, right? (Also, the program needed to parse JSON data, so JavaScript felt …


Continue reading

Strongly typed properties in Java vs C#

Posted on Thu 19 January 2012 in Coding • Tagged with delegate, generics, method group, csharp, java

The background for this post was that I needed to implement strongly typed properties in a C# project. With strongly typed property, I specifically mean a strongly typed version of public object GetProperty(string propertyName), where the property name is a constant (or name) of some sort, and the return …


Continue reading

Generic extension method with multiple constraints

Posted on Wed 18 January 2012 in Coding • Tagged with constraints, extension methods, generics

In a .NET project, I was coding an extension method for forms, and for various reasons I needed to call a form method which came from an interface. Instead of coding an ugly type check and subsequent type cast, I was happy to discover that I could simply create a …


Continue reading

Playing with Java annotation processing

Posted on Fri 06 January 2012 in Coding • Tagged with annotations, apt, Java, spi

I found Project Lombok via a Tweet, and was intrigued when I saw that a single annotation could trigger automatic code generation transparently during compilation of a source file. How do they do that?

Some digging lead me to discover Java’s annotation processing API, and how one can use …


Continue reading

Adventures in updating hard drive firmware

Posted on Fri 06 January 2012 in Sysadmin • Tagged with boot, firmware, iso, linux

I decided to update the firmware of two of my hard drives. The drives in question are both Seagate Barracuda 7200.11, model ST3500320AS, and smartctl gave me the following warning:

==> WARNING: There are known problems with these drives,
see the following Seagate web pages:

http://seagate.custkb.com/seagate …

Continue reading