The Case of the Missing Nintendo

My youngest son has wanted his very own Nintendo 3DS for a long time, so that he could play with his older brothers. After saving his money, after his sixth birthday, he finally had enough to buy his own. He was so proud to be able to buy it and so happy to be able to play Pokémon with his brothers; and I was proud of him for saving his money to be able to get it himself.

Unfortunately, maybe three months later, it went missing. My wife would ask my son if he wanted to bring his Nintendo on trips where he had to go but might otherwise be just sitting around, and he kept saying he didn't want to, that he just left it plugged in and charging. But after a couple weeks of this, he said he couldn't find it. (Whether he knew it was gone for those two weeks or not, we have no way of knowing.) We tried to backtrack to when it was last seen. There were a couple places he had taken it, but we were reasonably sure it had come home afterwards. We did call and revisit those places to be certain, and no one had seen it. We believe it was brought home and plugged into its charger in the family room. Then, one of his brothers had some friends over for a birthday party.

We have talked to the parents of the kids who were over, to see if their kids remembered seeing it and where it might have been moved to -- or, yes, if perhaps they happened to come home with something that wasn't theirs. So far, though, there has been no report.

It's been almost three months since then, and I'm actually pretty upset about it. He even got a new game for Christmas that he's never even had a chance to play. If it was in the house, I would have hoped that it would have turned up by now. Today, thinking about it, I got very frustrated on my son's behalf and turned the family room upside-down looking for it. It is, granted, not the first time that room has been searched, with the same results.

I have no way of knowing if someone did end up taking it. I would hope that parents would be observant and notice if their child had a pretty expensive video game system they didn't have before. But I'm not so sure. Last year, my wife was in charge of the Cub Scout Pinewood Derby, and she took a couple of my older sons' old cars (including one that one of my boys won 2nd place in the district with, something he was pretty proud of) as test cars. They were swiped at that event, and despite sending announcements to the parents and mentioning it at the following pack meeting, they have never been returned.

I don't know for sure where it is. It could've been misplaced in the house somewhere. My son could've taken it with him somewhere and lost it. It could've been stolen. There's no way to know. And while he seems to have let it go (he doesn't talk about it, even when all of his brothers are playing around him), it still makes me very upset for him. He set a goal for himself, he saved up his money, and he purchased his very own thing, and now, he doesn't get to have it.


Caffeine detox, days 1-3

I taught a lesson in church last Sunday on the subject of free agency, how God wants us to be free to make our own decisions (but not necessarily be free of the consequences of those decisions). One of the topics that came up was that of addiction, how being addicted to substances takes away our agency to do certain things. I admitted to being addicted to caffeine, how I have a hard time functioning if I don't have a daily soda, and how that limits my freedom by requiring that I have that drink before I can do anything I really want.

I figured I should probably fix that.

This isn't the first time I've tried to give up drinking soda. I did it a few years back, swearing off caffeinated drinks completely. Unfortunately, to compensate for the headaches, I started taking Excedrin (which contains caffeine), the only thing that seems to work on my toughest headaches (which, I know, sounds like the commercials, but is pretty accurate). After a couple months, I realized how ridiculous it was that I was avoiding soda but popping pills, and decided that just drinking the soda was the lesser of two evils.

Where I work, there is a fountain soda machine in the kitchen area. I thought a good way to kick this caffeine habit would be to take my 32oz water bottle and fill it with progressively less soda each day. Unfortunately, that didn't seem to be working out too well. Even just trying to dial it back an ounce or two, by Wednesday, I started to get a headache and popped a couple Excedrin. To make matters worse, on Thursday, the soda machine wasn't working, so I couldn't get my daily Coke anyway.

This Sunday, I decided to try again, but to give up on trying to make it complicated by fiddling with soda amounts. I decided to bite the bullet and go cold turkey. I didn't decide this right away — a busy morning left me soda-less before I realized it was time to go. I just decided, as I started to feel the pressure in my forehead, that I wasn't going to give in and take a caffeinated painkiller to make it go away. My wife asked me a couple times that day if I was sure I didn't want to take anything, but I had made up my mind. I was not going to be a slave to this chemical any more, and I was just going to have to suffer through it.

I wasn't feeling too well by Sunday night. I went to bed relatively early, with an ice pack on my head. I was tired enough to fall asleep fairly quickly, but I woke up about an hour before my alarm with my head buzzing. It wasn't easy getting out of bed — I'm not sure I opened my eyes much until I was already showered and dressed. Snow had fallen over the Denver area, and the roads were very slick, which meant I had to work extra hard to force my brain to ignore the pain trying to shut it down, and muster up the extra concentration required to drive safely. And, by the grace of God, I made it to work without incident (even though I passed several people who had not been so lucky).

Work was a chore. By the end of the day, the pain in my head was pretty intense, triggering feelings of nausea. Fortunately, the roads were in better condition for my drive home. Although I don't think of President's Day as a major holiday, the number of people on the road seemed rather light for a Monday rush hour. When I made it home, I immediately flopped down on the couch, while my wife got me ice packs from the freezer. I felt very tired, but I don't think I slept much more than maybe a 15-minute doze. I didn't feel well enough to eat dinner, but my wife had prepared a dessert of pound cake and fruit, and that was light enough for me to keep down. I finished off dinner with some ibuprofen, and acetaminophen (uncaffeinated) an hour later, and I was able to participate in our family bedtime scripture reading and prayer.

I would have gone to bed right then, but I had already signed up for a video game boosting session that night. (Basically, people who are having trouble getting certain Xbox achievements will sign up for a time to get together and help each other.) It would have been easy for me to just blow it off, but I didn't feel right, even if it would only affect people I have and probably never will actually meet in real life. Actually, having something to concentrate on did help me ignore the pain in my head, which by that time had moved from an all-over ache to a pinpoint stabbing behind one eye (though still not as painful as some I've had). By the end of the session, though, it was getting harder to concentrate, so I was thankful when it came to an end and I could put myself in bed. I went to bed with an ice pack on my head and tossed around a bit before I finally fell asleep.

The good news is, I woke up this morning without a headache at all. It was an encouraging start to this third day without caffeine. I didn't even feel the oppressing fatigue or headache pressure that usually drives me to have a soda or some Excedrin by lunch. About lunchtime, though, I could start to feel the pressure build up behind my eyes.


More MVC and JSON.Net - Exceptions

In my last episode with MVC, I was trying to reconcile MVC 5.0 with WebAPI 5.1 and the fact that the former used a broken JSON library, while the latter used the better Newtonsoft JSON library. I implemented a model binder and a value provider factory to get the two projects in sync, and all was right with the world.

As the project has gone on, we've come across instances where we've needed to call MVC controllers and get JSON responses back. We have created WebAPI controllers in some cases, but the way the project is structured, we've needed to post MVC models as JSON via AJAX back to MVC methods where we cannot reference them in the WebAPI project (otherwise we'd have a circular reference).

There are probably a few ways to restructure this to work. Ripping the view models out to a library that can be referenced by both MVC and WebAPI was one idea, for instance. But that would've been a lot of work and caused bigger deployment headaches that I don't want to get into here. (A smaller project might've gotten away with it, though.)

Returning JSON to the client is almost as easy as having your MVC controller return a JsonResult — the MVC Controller class has its own built-in Json() method to do just that. Except, of course, it uses the JSON serializer we never want to see again. In this case, I created my own JsonNetResult class (based on a StackOverflow question, naturally), and my controller just calls this.JsonNetResult(resultObj); to do the magic.

The remaining issue, though, is when it came to exceptions. While WebAPI, on a JSON request, returns an error response formatted in JSON (that jQuery's ajax method parses easily), MVC gives you that nice, big, friendly "yellow screen of death" with the error formatted in HTML (or a generic message when you get to production). Not too useful when you want your JavaScript to report back some detail about what went wrong.

The solution, here, was to use an exception filter. The JsonNetExceptionFilter class checks to see if the incoming request was specified as JSON (using very similar code to the model binder), and if so, it handles the error on its own. We were throwing HTTP error messages using two different types of objects, depending on whether the code was copied from WebAPI or MVC (since they each have their own namespaces for this kind of thing). I check for these types so that I can set the response code to something besides the default 500 (400 Bad Request is used quite a bit), and I set the content to a JsonNetResult object with the data being a message formatted in something similar to the WebAPI format (and thus parsed by the same JavaScript code).

I considered leaving it here, so that we would have to decorate every JSON method with this handler as well as specifying it returned a JsonNetResult (unless there's a way to find out programmatically in the filter whether the current controller method returns a JsonNetResult, but I failed to find that); but ultimately, I decided to just override the default error handler site-wide (since it falls back to the base class for non-JSON requests, it shouldn't be an issue). That was done by editing the MVC app's RegisterGlobalFilters method to read:

filters.add(new JsonNetExceptionFilter());

Now, whenever we want to return an exception back to a JSON request, all we have to do is throw an exception:

throw new System.Web.HttpException((int)System.Net. HttpStatusCode.BadRequest, "Bad request data.");

Processing the return message in jQuery is left as an exercise to the reader (though if you use WebAPI, you probably already know). ;)


How is escrow not a scam?

The concept of "escrow" already annoys me. As a requirement for my mortgage, I have to put aside money to pay for my homeowners insurance and property taxes, into a special account managed by the mortgage company, plus some extra depending on the mortgage company's demands. I can understand why they have a vested interest in making sure these things get paid, since technically they do own the house; but it seems it operates under the assumption that I would not take responsibility for these payments, and it gives me no opportunity to prove otherwise. Instead, the mortgage company gets to take the money and earn the interest, or dividends on the investments, and I have to just trust that they will make the tax and insurance payments (that I am responsible for) on time.

(To their credit, I have not yet had a mortgage company fail to pay either of these things on time.)

But recent events make me even more ticked off at the whole racket. I have a homeowners insurance claim in progress for storm damage (nothing too serious, mostly hail damage on the roof; we had the same thing five years ago). If the check is over a certain amount, the insurance company makes the check out to us and the mortgage company, requiring endorsement from all parties before the money can be used. I don't fully understand this. The insurance policy is a contract I have entered into with the insurance company. The mortgage company did not co-sign or endorse this contract, outside of requiring me to have a contract that meets whatever minimum requirements they had to allow me to get the mortgage. The mortgage company does not put any money into this contract — while they do make the payment of funds every year, they do so out of money they took from me. So why should they have a claim to the money on the insurance policy I paid for?

Still, before now, it was just a hurdle I had to jump before I could start repairing my home.

This time around, it's worse. Because the insurance payment was over a specific amount, my mortgage company demands I endorse the check and send it to them, and they will deposit it in a separate escrow account, and only give me money from it when I turn in receipts for repairs.

This is ridiculous. For one thing, it means I will be paying money out of pocket first. I don't have thousands of dollars sitting around that I can "float", paying for the repairs and waiting for the mortgage company to validate the receipts and give me my money back. That's the reason I have an insurance policy, so I don't have to pay out of pocket for catastrophes. For another, if my insurance company overestimated the damage amount, or if I am able to find a contractor willing to make the repairs for much less than the amount the insurance company gave me, how do I get that money when I don't have a big receipt to cover it? (The fact that the insurance company may have overpaid me is a discussion between me and them alone, since we are the ones that hold that contract.)

And this is just on top of my initial annoyance with escrow, that I'm not able to so much as put that money in an interest-bearing account to make a lousy 1‰ until I get the repairs done.

Of course, the answer is going to be so that they know that damage to their property is repaired, because otherwise the value of their property will be lessened by my negligence, while I could pocket the money and run. Still, this should be something I should prove first, let them sue me for negligence later. I get weary fast of having to pay for someone else's mistakes, and it seems like that's what is happing now: because irresponsible people exist, I cannot be trusted to do the right thing.


Attraction doesn't always mean action

So here's a really interesting story. It's a hard one to read or listen to, because it involves something that, I'd wager, most of us would rather not think about. It's about a young man who discovered he was sexually attracted to children, and how he's been struggling with this attraction all his life. A big part of his struggle is that pedophilia is something for which it is very difficult to get help. As the article states: "…they have no way to talk about these urges or how to prevent them from taking control of their lives without being considered a threat. Talk to a shrink? You risk being reported to the authorities. The scientific community is so afraid of the stigma attached to even researching pedophilia that it's barely been studied it at all." Which is why this young man has risked tarring and feathering to set up support groups, to help people who need help taking control of their lives instead of letting their urges define and control them. It's actually a pretty inspirational story about taking control and standing up for what's right, even when the wrongness is coming from your own self.

Now, here's where I'm about to get very unpopular.

Take that same story, but replace all references to sexual attraction to children, with sexual attraction to members of the same sex.

Suddenly, it goes from a story of inspiration and self-control to one worthy of derision because of its support of self-denial and giving in to homophobia.

I've seen many arguments that saying "anti-gay" is wrong because people can't change who they are, and they should be free to act on their feelings. It's the whole crux of the argument for allowing same-sex marriage: preventing discrimination based on what a person is. Yet if we were to apply the same logic to other sexual attractions that are (still) considered bad — pedophilia, bestiality, necrophilia, take your pick — we would be immediately shot down for trying to support the "sick" or "depraved" (if we weren't immediately shot for merely insinuating any kind of relationship between homosexuality and pedophilia).

So what's the difference? Attraction to children is something that, as a society, we all seem to agree is wrong — so it's ok to have laws against it and to not even think about granting legal protections and rights to those forms of relationships. And yet, it wasn't until just the past few years that the same could be said for same-sex attraction. Debate or blame whomever you wish for the existence of California's famous Proposition 8, but the fact that it passed means there was a significant number of people who, less than a decade ago, supported the idea that condoning same-sex attraction was wrong.

So, why? Why is this form of sexual attraction ok, and others aren't? What makes same-sex attraction part of a person's being, but underage attraction something that a person can and should suppress and live their lives in denial of? And what form of sexual attraction that we think is wrong today, will we be forced to bake cakes in celebration of ten years from now?


MVC, JSON, and DateTime (oh my)

It's been a while since I've had a programming issue that warrants a blog post, but here's an interesting one.
First, let me set up the situation. I have an MVC project (MVC version 5.0) that communicates to RESTful services using WebAPI (version 5.1). In one particular view, I write out an object in JSON with the intent that the client can make changes to it and POST it back to an MVC action to get an HTML table back. Here's the model:

public class PaymentScheduleRequestModel {
[JsonProperty(PropertyName = "effDt", NullValueHandling = NullValueHandling.Ignore)]
public DateTime EffectiveDate { get; set; }

[JsonProperty(PropertyName = "termId", NullValueHandling = NullValueHandling.Ignore)]
public Nullable<int> ContractTermId { get; set; }

[JsonProperty(PropertyName = "billDay", NullValueHandling = NullValueHandling.Ignore)]
public int BillingDayOfMonth { get; set; }

[JsonProperty(PropertyName = "freq", NullValueHandling = NullValueHandling.Ignore)]
public PaymentScheduleFrequencyId PaymentScheduleFrequencyId { get; set; }

[JsonProperty(PropertyName = "prem", NullValueHandling = NullValueHandling.Ignore)]
public decimal TotalPremium { get; set; }

(Note that the JsonProperty decorators exist because the same model is used to communicate to the WebAPI service -- we are using shorter property names to lighten the payload.)

And the MVC action that is set up to process it looks like this:

[HttpPost] public async Task<ActionResult> NewPaymentSchedule(PaymentScheduleRequestModel request) { … }

To put it in JavaScript, the view has this block of code:

window.ScriptModel = @Html.Raw(Json.Encode(new {
PaymentScheduleUrl = Url.Action("NewPaymentSchedule", "Contract"),
PaymentScheduleRequestModel = new PaymentScheduleRequestModel {
ContractTermId = Model.ContractTermId,
EffectiveDate = Model.StartDate ?? DateTime.Now,
TotalPremium = 200m

Unfortunately, Json.Encode doesn't work well with dates. This is the output that the browser sees (with line breaks added for legibility):


Notice two things about System.Web.Helpers.Json.Encode's output:

  1. The property names are the .Net property names. The same code could not be used to post what should be the same model to MVC or to WebAPI.
  2. The EffectiveDate field has been converted to a Date function, enclosed in a string. Even if the Date function would reveal the correct value, the fact that it's in a string means JavaScript will not see it as a Date.

If I don't do anything with this object and just post it back to the MVC app, the resulting object does not have a valid date — all other values carry over, but the EffectiveDate property is 01/01/0001. So not only does it look odd, not only is it inconvenient in that JavaScript can't use it as-is (without picking apart the string), but it doesn't even work for round-tripping data to and from the client.

In doing some research on this topic, I came across Scott Hanselman's blog post describing the problem, and stating that the release of WebAPI won't have the issue since it will use JSON.Net (a.k.a. Newtonsoft.Json). Since I'm using the same model in an WebAPI call further downstream, I can verify that it does work as intended. It uses the JsonProperty decorators to rename the properties, and it serializes and deserializes like magic.

To solve this problem in MVC, you have to alter how it deals with JSON on the way out and on the way in.

On the way out is easy in my case, since I am manually spitting out JSON into the HTML. I just exchanged Json.Encode with Newtonsoft's serializer:

window.ScriptModel = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(new {
PaymentScheduleUrl = Url.Action("NewPaymentSchedule", "Contract"),
PaymentScheduleRequestModel = new PaymentScheduleRequestModel {
ContractTermId = Model.ContractTermId,
EffectiveDate = Model.StartDate ?? DateTime.Now,
TotalPremium = 200m

And the browser sees:


This is better. Of course, the controller action doesn't understand this. It's still looking for the .Net property names, and, since they don't exist on the incoming object, all values come back empty. (In this simple example, not only is EffectiveDate 01/01/0001, but TotalPremium is 0.0.)

The trick here is to override MVC's default model binder, so that it, too, uses the Newtonsoft.Json library. It is also consistent to have MVC use a value provider factory that also uses JSON.Net.

Fortunately, people smarter than I figured out these two steps. I found a value provider factory on this blog: http://www.dalsoft.co.uk/blog/index.php/2012/01/10/asp-net-mvc-3-improved-jsonvalueproviderfactory-using-json-net/
and the important piece, the model binder, that will translate the JSON property names to their real .Net names, is detailed here: http://stackoverflow.com/questions/4164114/posting-json-data-to-asp-net-mvc

My implementation looks like this:

And this code gets called from Application_Start (I actually added it to my WebApiConfig class (which, for some reason, exists in my MVC app even though it's obviously not the same as WebAPI), since other configuration-type things were being done here):

ValueProviderFactories.Factories.Add(new JsonDotNetValueProviderFactory());

ModelBinders.Binders.DefaultBinder = new JsonDotNetDefaultModelBinder();

All this because, although Microsoft updated one of their web interfaces (WebAPI) to use the JSON.Net library that works, another one of their interfaces (MVC) uses their own, broken, JSON serialization library.


Consequences of free speech

A lot has been made recently of Los Angeles Clippers' owner Donald Sterling, being caught on tape saying some pretty racist things, bad enough for the NBA to ban him for life, fine him $2½ million, and force him to sell his team. From what I've heard, this result seems like a net positive for society as a whole, but how this whole thing has come about makes me very worried for the direction this country is headed.

According to the reports I've been reading, Sterling is not a very nice guy. Some say he has a long history of being racist. By the sound of things, the NBA will be better off without him. And yet, the NAACP gave him an award back in 2009 because (at least in part) he gave away a lot of tickets. The more cynical reports suggest he was given this award, with his racism overlooked, because he gave money to the right people. He was, in fact, due to receive another award this year from the NAACP, before recent events made the organization reconsider.

But what were the "recent events"? Did he use his power as an owner in real estate to deny housing to blacks or hispanics? Did he make an employment decision based on race? No, that was years ago (before, during, and after the NAACP was giving him his first lifetime achievement award). It happened because his girlfriend recorded a private conversation, coaxed him to say what he did, and sold the tape to the online tabloid TMZ.

I've read conflicting comments as to whether or not Sterling knew he was being recorded, but those that care to mention the girlfriend seem to agree that she really worked on Sterling to get him to make his damaging statements, leading him to say what he did and really dragging it out of him. Of course that brings a lot of rumor and speculation about how much, and from whom, she was getting paid to do this, and whether or not it was illegal (most likely if Sterling didn't know the tape was rolling).

Kareem Abdul-Jabbar wrote an excellent opinion of the issue for Time, which echoes a lot of the comments I've heard that led me to my conclusion above. It also comes to pretty much the same end — Sterling's eviction from the NBA is a good thing and long overdue, but how it happened is very, very wrong.

The big question, of course, is, did Sterling deserve his NBA exile, fine, and loss of ownership of his team for what he said? Maybe his speech just served to bring about awareness of what he was actually doing, but because he only got punished when he expressed his views in the privacy of his own home, it certainly looks like that's his sin. He said something that was unpopular, and now he must pay.

It is true that "freedom of speech" does not make you free of consequences. If you say something that someone doesn't like, that person is just as entitled to use their own freedom of speech to speak out against you, exercise their freedom of association to refuse to do business with you, and even freely encourage others to avoid you as well. But why does it seem like it's only the speech — or even the perceived interpretation of speech — that deserves to be punished, when actions can go unnoticed or be forgiven?

We've been sliding down this slope for a while. Paula Deen was condemned for using a racial slur in the past (including in a description of someone who had a gun to her head), despite having apparently changed her ways since. Phil Robertson lost his place on the show Duck Dynasty for daring to honestly answer an interview question asking what he considered a sin (only to be reinstated after enough public support). Brendan Eich found he was unable to do his new job as Netscape CEO due to all the protests that, six years prior, he gave a paltry (for him) sum for California Proposition 8 — a view that, even though is becoming less so now, was the popular view at the time (Prop 8 passed) and, at the time, was even supported by presidential candidate Barack Obama. Cliven Bundy was supported by many in the (mostly right-wing) media, before he expressed his political opinion that came off as racist (though that might be less actual racism and more poor word choice and selective editing by the media, depending on your point of view).

So now, it's not just what you say in public. It's not even what you said in public in the past, whether or not you've recanted since. But what you say in private, behind closed doors, can and will be used against you in the court of public opinion; and if your opinion goes against the prevailing wisdom, whichever way it happens to be blowing at the time, then God help you.