Grails oddity

September 1, 2011 3:51 pm

I've been working on a bug for most of the day today.  From all of my understanding this bug shouldn't have been happening.  This is always a pain because it means something is, obviously, wrong with my understanding, but because of that I didn't know where to look.

The issue was that I was getting an unsaved transient object instance error when I tried to save updates to an object from a form.  My issue with it was that I wasn't creating any new objects in my Controller code.  If I'm not creating any new objects, how can there be a unsaved transient?  And thus I spent a few hours learning through fiery trial-and-error, because I couldn't find anything that would actually tell me what object was transient or where it came from.

The solution to this problem was in some of Grails' behind-the-scenes, automagic data-binding.  Normally you can data-bind an associated object using a field in your form with a name like "associatedObject.id" and then Grails will automatically setup the relationship for you when you bind the request parameters to your object.  What I've now discovered is that Grails will also attempt to look up an associated object if you have a field in your form with a name like "associatedObject" even if you don't use it for anything, and when it fails to find the object it creates a transient for you.

I needed to do something special with that field so I was using "associatedObject" instead of "associatedObject.id" and then in my data binding I was excluding that field from the binding:

bindData(objectInstance, params, [exclude:['associatedObject']])
objectInstance.save(flush:true)
-- unsaved transient exception

Again, the unsaved transient was an automatically created object that Grails created when it failed to lookup a match for the "associatedObject" field--this is regardless of the fact that I never actually tried to use that field for anything yet.

So I had to change the name of the field to something else, let's say 'assocObject'.  And once that's done it's perfectly happy to do what I want:

bindData(objectInstance, params)
objectInstance.save(flush:true)
// Saves successfully

Just thought I'd throw this out there since I spent several hours of my life discovering this little nuance and wasn't able to find any useful information on the Internet.  I just wouldn't have expected Grails to create a secret object behind the scenes like that when I never actually tried to use the value for anything.  Sure, if I attempted to bind it, great, work your magic; but if not, I wouldn't expect it to interfere.

Runnin' and Gunnin'

August 30, 2011 5:11 pm

Our friend Barry is the gun totin' type.  He made a bunch of targets and goes out shooting every so often.  He invited me to go with him on Saturday to do some shooting, but also to take some pictures and video.  We went with him and some others.  We drove out into the Central Valley to some Bureau of Land Management land where it's legal to shoot.  So it's pretty much a desolate set of hills and canyons which make nice backstops.

We set up a pistol and rifle course to run through.  I had not shot a pistol before this so I was fairly lousy with it, but I was a little better on the rifle.  Because of my lack of experience I did the course with a .22 pistol and a .22 rifle.  But later on I was able to fire an assault rifle, a .45 pistol, a 9mm pistol, and a .357 magnum revolver.  Those are pretty fun guns to shoot--the .357 really packs a punch.

Here are my favorite pictures and the video of my run through the course is at the end, you won't want to miss that, I'm sure.

Barry fires a shot
Barry fires a shot
A box of .22 rounds
A box of .22 rounds
Jess particularly appreciates this one
Jess particularly appreciates this one
Barry taking advantage of the bipod, notice the shell ejecting across his beard.
Barry taking advantage of the bipod, notice the shell ejecting across his beard.
Tad lines up his shot
Tad lines up his shot
And the aftermath
And the aftermath

We were out pretty much the whole day, we left town before sunrise and got back after sunset.  It was long and exhausting.  The high temperature out there was in the 97-99F range.  I did pretty well with the help of my Subway visor and my polarizing sunglasses, but by mid-afternoon I had a pounding headache behind my eyes.  I'm just not used to that much intense sunlight.

I also made a rookie mistake of taking ibuprofen (for said headache) on an empty stomach.  That made for a rather unpleasant experience of focusing on keeping my stomach calm while riding home, exacerbated by the fact that nausea is a symptom of severe dehydration and it wasn't immediately obvious whether it was the ibuprofen or if the 5L of water / Gatorade I drank wasn't enough to keep me hydrated.  But the nausea subsided half way home and I haven't experienced any additional issues, so I guess I'm alright.

And now the moment you've been waiting for: Kyle's run-n-gun, with the oh-so-manly .22 pistol and .22 rifle (which I managed to drop the magazine out of while swinging it off my back).  I don't think I did too badly having never fired a pistol until this day.  I did a lot better later after practicing and learning how to properly fire and suppress the instinct to compensate for kickback before the shot occurs (not that the .22 has much kickback, but those larger ones sure do).

You can download it too: 2011-08-27 - Kyle Run and Gun (small). Use "right click -> Save file as..." to download it.  The file is 30.1 MB so it may take a few of minutes to download (depending on your Internet connection speed).

Creating Evil Traps for Good People

August 15, 2011 2:08 pm

This is another post elicited from The Lucifer Effect by Philip Zimbardo.  First, a word about the book.  The first bit of the book is a walk-through of the events that occurred during the Stanford Prison Experiment.  He bases it off of the transcripts and recordings that were made and he keeps it accurate and scientific, but the transcripts of interactions between guards and prisoners is riddled with obscenities--just a word of warning to anyone planning to read it.  If that bothers you, you can just skip those chapters and move right into the discussion afterwards, but you may not fully appreciate the transformation of the participants.

This post comes from chapter 12, from a subsection entitled "Ten Lessons from the Milgram Studies: Creating Evil Traps for Good People" which begins on page 273.

Stanley Milgram ran a long series of experiments that involve participants believing that they are inducing increasingly powerful electro-shocks to another participant (a confederate acting the part of being shocked).  They do so under the guise of a memory-enhancement training program while being watched and ordered about by an official looking "scientist."  During the course of the experiment the participants must administer a shock each time the "learner" provides a wrong answer.  During the course of the experiment the confederate "learner" screams in pain, demands to be released (he's strapped down), complains about his heart hurting, and eventually stops responding (suggesting to the participant that the learner has become unconscious).

The participants almost always look to the "scientist" for guidance as things get bad, but the scientist always gives them reasons to continue with the experiment unless they simply get up and leave.  65% of participants followed the experiment all the way through the 30 levels of shocks.

Milgram ran this experiment over and over again all around the world making slight variations on the design to try and learn more about what factors contribute to participants' conformity.  It's really interesting.

I want to talk about the 10 methods of inducing compliance that are pulled from Milgram's experiments.  These techniques are used very successfully in myriad settings including: salespeople, cults, the military, governments, advertising, and others.  Each item has its own paragraph, so I'm going to summarize them briefly:

  1. Create a contractual obligation (verbal or written).
  2. Give participants a role to fill ("teacher" in the above).
  3. Dictate a set of rules to be followed which can then be used to coerce behavior.
  4. Replace potential unpleasant descriptions with positive descriptions ("shocking victims" to "helping a person learn").
  5. Tell participants that someone else will take responsibility for what happens.
  6. Use an initial innocuous-appearing step to elicit initial compliance.
  7. Use successive steps towards the end goal, each of which seems like a negligible change from the previous step.
  8. Have the authority figure slowly change from "just and reasonable" to "unjust and demanding."
  9. Make it difficult and expensive (in some form, not necessarily monetary) to exit the situation, but allow verbal dissent while demanding behavioral compliance.
  10. Provide some "greater good" for participants to believe in.

The last one is interesting.  Zimbardo elaborates discussing Erich Fromm's 1941 work Escape from Freedom.  In this work, Fromm discusses how throughout time the "greater good" used by dictators and tyrants in order to convince citizens to give up their freedoms is a promise of security.

I also can't help but read that list and think of how accurately it fits with how the TSA has operated since its creation.  Here's how I think the rules (except 2 and 5) easily apply to the TSA's behavior:

  1. Can't fly unless you agree to be screened.
  2. --
  3. Laptops out, liquids in baggy, shoes off, belts off, coats off, "step over here."
  4. We're not violating your civil rights, we're protecting you from terrorists!
  5. --
  6. Just step through the metal detector, it's quick, easy, and somewhat effective.
  7. Okay, now we just need you to take your shoes off.  And your belt.  And your coat.  And remove your computer.  Oh and just put your liquids in a baggy for us.  And stand in this chemical sniffer.  Also, if you wouldn't mind, just stand here while we bounce radiation off of you to create an image of your body.
  8. Any appeal to reason or logic is met with a stiff reference to the rules and to fall in line or you just might miss your flight.
  9. Don't want to be part of the TSA process?  Your only option is to not travel by plane (and soon by bus or rail if the TSA gets its way).  Have a complaint? You can file it with headquarters and we'll say "thanks for your concern" and then completely ignore it and tell you to get back in line.
  10. It's for your own protection.

If you're so inclined you can probably turn these around and see how they are used against the TSA agents to convince them that further abuse of passenger's civil rights is acceptable.

It's incredibly effective.  Just think of what the national reaction would have been if, when the TSA was instituted, they had rolled out the body imaging scanners and said these are now required for all flights.  People would have flipped out.  Instead it was one slow addition to the rules after another until people just accepted the new scanners.  Those that did complain were told that their comments were appreciated and then nothing changed.  Now the TSA talks about how few complaints they get about the scanners / pat-downs (only several hundred per year!) which is a useless figure because it ignores the thousands of people who will no longer fly to avoid the issue (like myself).  As of July  2011, Amtrak has had 20 consecutive months of record numbers of passengers, but surely that has nothing to do with how awful and demeaning airports have become.

Kyle says I should document my misadventures.

August 14, 2011 6:01 pm

So, I've heard that when you're pregnant, you shouldn't wear heels because the hormones that relax your tendons and ligaments all over cause your joints to become less reliable. But I like my heels, and I have a hard time finding flats that I feel are dressy enough for church, so I've still been wearing them. Specifically, today I was wearing these. Now, for the record, these are apparently devil shoes. They were fine the first few times I wore them, but then they started giving me blisters on my toes. I've been determined to either break them in or toughen up my feet, though, so I wore them this morning. They have upped the stakes now, though, by bucking me off.

I twisted my ankle pretty badly. Just walking down the hallway from sacrament meeting to Sunday school, of course—nothing fancy. I even had my arm around Kyle's waist at the time (fortunately), which kept me from actually falling. Well, that and the wall. But I completely rolled my left ankle off that shoe (all 3" of it!), and it's not in fabulous shape now. I haven't hurt my ankles that badly since I was dancing!

Fortunately, like I said, Kyle was there, and my friend Sarah. And then my visiting teacher walked by and hailed her husband to assist Kyle in getting me to the foyer (while Kyle pulled the car around) and then to the car. I iced it for a few hours after we got home, and the pain is a lot better. It's not very swollen, either, which is great. So hopefully I'll be able to walk normally again in a few days? Sarah says I can't wear heels anymore, though.