Jason Specland: Consultant, Comedian

Making it up as I go along. Always.

Tag: geek

Sexy Mad Science: My LED Body Suits for Yes! Yes! Yes! And…

The show was last night, and was a smashing success, and so it’s time to reveal the project that I’ve been working tirelessly on in the past week.

The idea of “Yes! Yes! Yes! And…” is kind of a sexy party improv show. (Notably, and importantly, I think, the improv itself is 100% clean, it’s just the “frame story” that’s all sexy.) The theme of this show was that it would be performed in total darkness, with the performers illuminated only by small LEDs that they carried with them.

With my knowledge of electronics, I figured I could do something pretty neat. My idea was that, as our hearts and our libidos are often in conflict, the suit will display the beating heart and the prominent… genitalia. (Due to the nature of the show, this post will be filled with the forced hesitant prudishness of the ellipsis.)

Here’s a video of the completed LED bodysuit.

So the first thing I did was I built a boatload of LED strands. Why not just buy LED rope lights? My thought was that I wanted to determine exactly what color and design I wanted (which I was right about) and that it wouldn’t be a big deal to solder them all together. About this last point I was wrong. Dead, dead, wrong. It took me three solid days to solder together two hearts, one male, and one female… piece. (There’s that ellipsis again.)

I ordered a bunch of colored LEDs and resistors from Mauser. Here’s some of the first designs, with my calculations of the resistance values for a 12-volt input.

20130217-142440.jpg

image

Here is the soldering station, just beginning the build of a strand of lights. Again, I spent three solid days doing this.

image

Here’s the first successful test of the “inner” heart ring.

image

And this is the outer.

image

Here is a pile of hand-soldered LED and resistor assemblies, ready to put into a cable that’s being built.

Soldering Station with Loose LED Assemblies

The heartbeat is controlled by a super-simple controller board. The 12v is routed through a 5v voltage regulator, which feeds the input of an ATtiny 85. (I programmed the ATtiny 85 through my Arduino. Much thanks to High-Low Tech at the MIT Media Lab for showing me how to do that.) The output pins 0 and 1 go to the base of two transistors, whose collectors are pointed at the 12v supply and whose emitters are pointed at the inner and outer heart rings.

The… bits… are directly wired in without a controller.

To make sure that we could turn the whole thing on and off at a moments notice, I wired a toggle switch for the whole shebang, and routed it into the left arm.

There were some important lessons learned. First, and most vitally important lesson is that I can NOT solder a million tiny connections in any reasonable amount of time.

Another lesson was that, while it’s nice to have guaranteed battery supply, having a 10 Amp-hour battery is not only probably overkill, but those batteries in NiMH weigh about 4 lbs. In the end, I couldn’t even get them to charge (my charger was defective, and is being returned). But even if I’d gotten them to charge, I never solved the problem about how someone would actually wear such a battery pack. I’ll most certainly use the two huge battery packs in some future project… I’d better… they were darn expensive! In the end, I just ended up using 8 long-lasting AA batteries to generate 12v.

Yet another lesson: Stripboard is much easier to work with than undifferentiated perfboard. At the very least it focuses the mind as to where your components should go. I’ve heard that custom printing PCBs isn’t terribly difficult or expensive, and I may need to look in to that.

On the brighter side of lessons learned: The fact that I don’t need to stick a whole Arduino into a project! It was extremely easy to built a breadboard to program the ATtiny 85 and upload my sketch to it. And the ATtinys are so cheap, I purchased 10. (And blew up two. Don’t forget to connect the ground wire to your 5v regulator, folks! Whoops!) But I will almost certainly be using ATtinys (or other Amtel chips I can program from the Arduino) in future projects.

My heart was having shorting problems, but it worked with a little bit of fiddling during the show, and finally died in the shows final few minutes, so I guess we got just about all I can ask of my meagar soldering and board-building skills.

In the end, it didn’t quite live up to my initial imagination. (I’d planned on having LEDs running down each arm and leg. That would have been an additional hundred LEDs to solder!) But it came out pretty awesome just the same. I’m super-proud of this, and while I don’t think that I’m going to be doing this all the time, it’ll be a neat thing to throw into my performances now and again.

Today’s xkcd is AMAZING, and NSFW

Submitted for your approval: Today’s xkcd. It is very NSFW. And by that I don’t mean that it’s pornographic or disturbing. I just mean that you shouldn’t click that link unless you want to spend hours and hours not getting anything else done.

Hyper-V VM Not Starting Due to Insufficient RAM, Even Though You Have Enough? Kill googlecrashhandler.exe

So this morning I start up my computer, and start up my SharePoint Development VM. I get a message saying that my VM won’t start. It says “Unable to allocate 6144 MB of RAM: Insufficient resources exist to complete the requested service. (0x800705AA).”

Well naturally I like to give my SharePoint VM lots of RAM, but 6144 is right around the amount that is actually free. So I lower it to 4096 MB. Task Manager tells me I have more than enough free RAM to do that. But I try to start it up… No dice. I lower it to 2048 MB. It starts all right, but running SharePoint + SQL Server + Visual Studio on 2 GB of RAM is not something I relish.

Finally, my Google-Fu was powerful enough to show me newly-posted answer on TechNet.

googlecrashhandler.exe? Really!? Well, seems silly, but anything’s worth a try. I kill the 2 processes and boom. My VM starts with 6 GB of RAM, just like always.

I’m writing this up for two reasons: Primarily, I’m putting this out there so Google can grab it and save my fellow devs from frustration. But secondarily, as a SharePoint developer, it’s not often that I have cause to direct WTF’s at a party other than Microsoft.

Hey, Google: WTF!?

Sharepoint: Updating Workflow Task Causes NullReferenceException (a fix)

I’ve got a workflow where a project manager approves a project (that’s one kind of task), or can send it out for technical review (another kind of task), or can request more information from the user (yet another task). Each of these tasks have their own Content Type, and their own custom task edit form in ASP.NET. (Because I hate InfoPath with a burning white hot hate.)

Whenever someone uses one of these custom edit forms, however, I get a NullReferenceException. The stack trace always puts it in the non-public SPListItem.PrepeareItemForUpdate method. It doesn’t matter how I change the task list item. Using SPWorkflowTask.AlterTask, or just SPContext.Current.ListItem followed by Update all threw the NullReferenceException.

To Google I go! However, most of the results said that it had to do with not having a definition in the Content Types. That wasn’t my problem, however, since not only did my Content Types have FieldRef’s, but they were very much full.

At my wits end, I broke out the .NET Reflector and decompiled the Microsoft.SharePoint assembly. Here’s what I found:

As you can see (well, kind of see… click on it to see more clearly), this would only happen in a WorkflowTask. If the list item’s “Completed” field is null, the cast to bool throws a NullReferenceException. This is probably the kind of thing that can’t happen in SharePoint Designer, but only would occur when someone is mucking about in Visual Studio.

To fix it, make sure you set the “Completed” field. I do this:

[sourcecode language=’c#’]
private void SetTaskStatus(string status, bool taskIsComplete) {
SPListItem taskItem = SPContext.Current.ListItem;

Hashtable taskData = new Hashtable();
taskData[SPBuiltInFieldId.TaskStatus] = status;
taskData[SPBuiltInFieldId.Completed] = taskIsComplete;
if (taskIsComplete) {
taskData[SPBuiltInFieldId.PercentComplete] = 1;
}

SPWorkflowTask.AlterTask(taskItem, taskData, true);
}
[/sourcecode]

Or, if you work for Microsoft, you could do us a favor and make sure that you null check that line and default to false. (It’s entirely possible that this has been fixed by SP1, but my production server doesn’t run that yet, so I can’t either.)

Unit Testing: Rhino Mocks, Ordered Mocks, and Events

Tired of all that improv show talk? Well, now it’s time for me to get my geek on. Non-computer geeks feel free to tune out. This is actually more along the lines of “put it out there for the sake of future Googlers” than a serious discussion.

I’ve had test-first religion for some time now, but deadlines have made me something of a lapsed tester. After finding a pretty bad-ass bug in my code, I got religion again, admitted I was a sinner, and went forward in Testing. I am redeeming myself by writing a few hundred unit tests of already existing code.

My preferred mock framework is Rhino Mocks. Now I’m all about the AAA (Arrange, Act, Assert) syntax. 99.9% of my tests (seriously, I’ve got over a thousand of them) are AAA. Most of my tests are unordered. I just want to test that something was called, and I don’t care what was called before or after it.

But you can’t do AAA syntax when you’re doing ordered tests. It hasn’t been a problem thus far, but I ran into a problem when I started testing objects that hooked up events in the constructor: So my code looked like this:

[sourcecode language=”c#”]
namespace RhinoMocksOrdredWithEvents {
public interface IOrderedThing {
void FirstThing();
void SecondThing();
void SomethingElse();
event EventHandler OnThingHappened;
}

public class MyTestClass {

private IOrderedThing MyOrderedThing { get; set; }

public MyTestClass(IOrderedThing orderedThing) {
MyOrderedThing = orderedThing;
MyOrderedThing.OnThingHappened += new EventHandler(MyOrderedThing_OnThingHappened);
MyOrderedThing.SomethingElse();
}

public void DoThingsInOrder() {

MyOrderedThing.SomethingElse();

MyOrderedThing.FirstThing();
MyOrderedThing.SecondThing();
}

private void MyOrderedThing_OnThingHappened(object sender, EventArgs e) {
return;
}

}
}
[/sourcecode]

And here’s the test to make sure that FirstThing() and SecondThing() are called in order:

[sourcecode language=”c#”]
namespace RhinoMocksOrdredWithEvents {
[TestClass]
public class OrderedMockTests {

[TestMethod]
public void TestThingsAreRunInOrder() {
// Arrange
MockRepository mocks = new MockRepository();

IOrderedThing mockOrderedThing = mocks.DynamicMock();

MyTestClass classUnderTest = new MyTestClass(mockOrderedThing);

using (mocks.Record()) {
using (mocks.Ordered()) {
mockOrderedThing.Expect(thing => thing.FirstThing());
mockOrderedThing.Expect(thing => thing.SecondThing());
}
}

mockOrderedThing.Replay();

// Act
classUnderTest.DoThingsInOrder();

// Assert
mockOrderedThing.VerifyAllExpectations();
}
}
}
[/sourcecode]

Be not fooled by my spurious use of the //Arange, //Act, and //Assert comments. This is most definitely not the AAA syntax.

So when I tried to run this test, I got the following error:


Test method
RhinoMocksOrdredWithEvents.OrderedMockTests.TestThingsAreRunInOrder
threw exception:
Rhino.Mocks.Exceptions.ExpectationViolationException:
IOrderedThing.add_OnThingHappened(System.EventHandler`1[System.EventArgs]);
Expected #1, Actual #0..

What what what!? I never told Rhino Mocks that I expected the event to be wired! And anyway, it is wired, right there in the constructor, see? Then I comment out the event hookup, and the test works! So off I sauntered to the Rhino Mocks mailing list all like, “Hey guys, I don’t mean to be all smug and stuff, but all y’all got a bug.”

Thankfully, Tim Barcz on the mailing list set me straight.

Yes, Virginia, you can do the AAA syntax in an ordered mock, and this is how you do it:

[sourcecode language=”c#”]
namespace RhinoMocksOrdredWithEvents {
[TestClass]
public class OrderedMockTests {

[TestMethod]
public void TestThingsAreRunInOrder() {
// Arrange
//MockRepository mocks = new MockRepository();

IOrderedThing mockOrderedThing = MockRepository.GenerateMock();

MyTestClass classUnderTest = new MyTestClass(mockOrderedThing);

mockOrderedThing.GetMockRepository().Ordered();

mockOrderedThing.Expect(thing => thing.FirstThing());
mockOrderedThing.Expect(thing => thing.SecondThing());

// Act
classUnderTest.DoThingsInOrder();

// Assert
mockOrderedThing.VerifyAllExpectations();

}
}
}
[/sourcecode]

Which works no matter what strange stuff you want to do in the constructor.

Much thanks to Tim Barcz for setting me straight. Here is the original thread on the Rhino Mocks mailing list.

Debugging WCF Services In Visual Studio 2008 in 32-bit Mode on a 64-bit Architecture

This is for my own reference, (and for the sake of anyone Googling) since this has been driving me crazy for months. Feel free to ignore if you’re not a geek. Feel free to correct it if you are.

When building a WCF project for the x86 architecture on an x64 machine/OS (like, say, Windows 7), you will get a BadFormatException when you try to debug it. This is because WcfSvcHost.exe will run in the mode defined by your architecture, regardless of your particular build environment. Microsoft says that this is working as intended. I say boloney, but I’m a VS version behind now. (I haven’t tested VS 2010 yet.)

Here is a link to part of the solution.


corflags /32BIT+ WcfSvcHost.exe

However, the signature of this assembly is now broken, and won’t load. So to bypass that:


sn -Vr WcfSvcHost.exe

to remove strong name signature verification.

DANGER:
Don’t do that unless you know what you’re doing! That opens up a huge security risk. Do not do that in a production environment! Only do it on your dev box!

Why not just build the app in x64 or (even better) Any CPU? Because I can’t get Oracle.DataAccess in 64-bit.

Programming Praxis: Goldbach’s Conjecture

Since I mentioned in my last post that I live in fear of the tech interview, I decided to do something about it rather than live in fear. To that end, I subscribed to a website called Programming Praxis, which publishes short programming problems to sharpen your saw on. (Well, I’d actually been a subscriber for a while, but it’s just now that I’ve actually took the time to do my own saw sharpening.)

Geek Content Ahead. Feel Free to Ignore.

Today’s Praxis is on the Goldbach Conjecture which states that any even number greater than 2 can be expressed as the sum of two primes. The challenge is to write a program that will take in an even number, and spit out the two primes that can be added together to make it.

I realize my solution is extremely naive, but it’s the first time in a long time that I’ve actually worked on programming problems other than “get data from database a, transform it somehow, and put it in database b.” Also, for extra difficulty (and speed, although my algorithm is the real speed hangup in this case) I wrote it in C.

For the one or two people still reading, here is my extremely naive solution, cobbled together while watching West Side Story on TCM.

[sourcecode language=”cpp”]
#include
#include

void show_usage();
unsigned long *create_sieve_to_number(unsigned long number);

int main (int argc, const char * argv[]) {

if (argc != 2) {
show_usage();
return -1;
}

unsigned long number = atol(argv[1]);

if ((number % 2) != 0) {
show_usage();
return -1;
}

unsigned long *sieve = create_sieve_to_number(number);

for (unsigned long i = 2; i < number; i++) { if (sieve[i] == 1) { for (unsigned long j = i; j < number; j++) { if (sieve[j] == 1) { if (i + j == number) { printf("Solution found: %d + %d\n", i, j); return 0; } } } } } printf("no solution found! pick up your Fields Medal!\n"); return 0; } void show_usage(void) { printf("usage: goldbach [even number]\n"); } unsigned long *create_sieve_to_number(unsigned long number) { unsigned long *sieve; sieve = (unsigned long *)malloc(sizeof(unsigned long) * (number + 1)); for (int i = 0; i < number; i++) { sieve[i] = 1; } for (unsigned long i = 2; i < number; i++) { if (sieve[i] == 1) { for (unsigned long j = i * i; j < number; j = j + i) { sieve[j] = 0; } } } return sieve; } [/sourcecode] Edit: See what happens when you’re watching TV when you’re doing your homework? The flags marking numbers as prime can be a bool (or even a bit) and most certainly does not have to be an unsigned long. Yay for massive, massive wastes of memory! (But hey, I was watching West Side Story…)

The Dreaded Technology Test

A recent post on Coding Horror about “Non-Programmer Programmers” kind of terrified me. Not because I think that my job is going away, and not because I think my skills aren’t up to snuff, but because the technical interview terrifies me like nothing else.

Jason, with performance anxiety? Yes, it’s true!

As a performer, I come from the world of improv, where the mantra is “Just make it up! What you say will always be correct!” Naturally, this level of bullshittery, while it might get you through a real interview, will never do in a technical interview where you will be eviscerated if you don’t know the systems you claim to know. (Or even some detail of a system you really do know, but had never previously used.) Now I’ve never put something on my résumé that I did not actually use, but in some cases, it’s just been a while and I need a few minutes with my friend Google to get back up to speed.

Part of the problem is that the tech interview is like flying an airplane. Once you stall once, it’s really hard not to crash and burn. You just get more and more flustered until you can’t even answer questions about things that you do know extensively.

I had an interview like that just before I interviewed for my current job. It was October/November 2001, and as you could imagine, New York City was on edge and not in a hiring mood, especially in the “dot-com” world which had gone bust. I interviewed downtown with a famous phone company for a unix administrator job. I can’t remember what question started the stall… I think it was something about rpc, or what port something listened on… But after that, I was dead in the water. They asked me a bog-simple RAID question that I totally blew. As they escorted me out of the building, one of the managers sypathetically said to me, “It must be hard getting a job in this economy…” Shellshocked, I agreed.

Reading that article on Coding Horror, and remembering that interview, kept me awake far too late last night. Again, I’m reasonably confident that my job’s not going anywhere, and I’m confident in my abilities, but one has to plan for these things.

Then today, sitting in the office that I’ve occupied for almost nine years now, I remembered a tech interview that was tough, but I knocked out of the park. (In particular, I remember totally killing a question about DNS.) Naturally, its the one that got me the job I have today. And they seem to like me after all these years, to the point where they actually let me write production code.

Scary though the tech interview may be, if I keep my skills up, keep my cool, and remember how to pull out of a stall, I should be okay. Besides, the “weed out” questions on that Coding Horror article are laughably easy. And if your tech interview feels like the Spanish Inquisition, did I really want to work for you in the first place?