Posts in the Personal Category

Seeking JavaScript Help

Published 15 years, 11 months past

Even though it turned out that there is no simple solution for the math problem I posted, I learned a fair amount from the fantastic responses—thanks, everyone!—and eventually came up with a solution that worked for me.  (I’d like to say it was one of the iterative approaches posted, but none of them worked for me.  In the end, I brute-forced it.)  I’m hoping for a different outcome with my next question, which is about JavaScript.

Consider the following structure, which is a much-edited-down version of part of the HYDEsim code:

function Detonation(name,lat,lon,yield) {
    var scale = Math.pow(yield,1/3);
    var gz = new GLatLng(lat,lon);
    this.name = name;
    this.lon = lon;
    this.lat = lat;
    this.gz = gz;
    this.yield = yield;
    this.overpressure = {
        p30 : 0.108 * scale,
        p15 : 0.153 * scale,
        p10 : 0.185 * scale,
         p5 : 0.281 * scale,
         p1 : 0.725 * scale
    };
    this.psi30 = {
        radius: 0.108 * scale,
        overlay : {
            points: makePoints(this.gz,0.108 * scale)
        }
    };
    this.psi15 = {
        radius: 0.153 * scale,
        overlay : {
            points: makePoints(this.gz, 0.153 * scale)
        }
    };
    this.therm20 = {
        radius: thermDist(20,this.yield,0.33,conditions.visibility),
        overlay : {
            points: makePoints(
                this.gz,
                thermDist(20,this.yield,0.33,conditions.visibility)
            )
    };
    // ...and so on...
}

There are two things I’ve tried and failed to do.  And tried, and tried, and tried; and failed, and failed, and failed.

  1. Eliminate the redundant calculations of radii.  Note how I define a radius property in each case?  And then have to not use it when I create the overlay?  It seems like there must be a way to just define the value once for each subsection and then use it as many times as needed within that context.  How?
  2. How do I make it so that all those properties and overlays and such automatically recalculate any time one of the “upper-level” terms changes?  As in, once I’ve created a new Detonation object det, how can I set things up so declaring det.yield = 250; will trigger recalculation of all the other pieces of the object?  At present, I’m just blowing away the existing det and creating a whole new one, which just seems clumsy and silly.  I have to believe there’s a better way.  I just can’t find it.

Please note: tossing off comments like “oh, just instantiate a mixin constructor with an extra closure” will be of no help at all, because I don’t understand what those terms mean.  Hell, I’m not even sure I used the words “object” and “property” correctly in my explanation above.  Similarly, pointing me to tutorials that use those terms liberally is unlikely to be of help, since the text will just confuse me.  Sample code (whether posted or in a tutorial) will help a great deal, because it will give me something to poke and prod and dissect.  That’s how I’ve always learned to program.  Actually, it’s how I’ve always learned anything.

As well, I’m absolutely willing to believe that there are much, much better ways to structure the object, but right now I really need to learn how those two things are accomplished in the context of what I already have.  Once I get familiar with those and finish up some other work, I can start thinking about more fundamental overhauls of the code (which needs it, but not now).

I really appreciate any concrete help you can give me.

Addendum: if you leave code in a comment, please just wrap it in a code element and use whatever indentation you like.  The indentation won’t show up when the post goes up, but I’ll go in after and wrap the code in a pre and then everything will be fine.  Sorry to those who’ve already gone to the effort of posting with indents or nbsp entities to try to preserve indentation!  As soon as I can dig up the right preference panel or plugin to allow pre in comments, I’ll do that, but for now I’ll manually edit in the needed pres as comments are added.  THanks, and again, apologies to those who posted before I made this clear!


Seeking Math Help

Published 15 years, 11 months past

So I have this equation that’s great for finding one term.  Problem is, I need to solve for another term that’s scattered all across the right side.  I’m hoping someone here has the mad algebra skills I managed to lose in the two decades since I last took a math class and can help me out.

Here’s the original equation:

Q = (3.07 × F × Y × (1 + 1.4 × ((D/V) × e(-2 × D/V)))) / D2

I want to be able to solve for D, not Q; in other words, have a single D on the left and everything else on the right of the equation.  F, Y, and V are all variable terms; the e is the classic irrational constant.  I tried for quite a while to do this and ran very firmly aground.  The best I managed was this minor simplification:

Q = (3.07 × F × Y × (1 + 1.4 × (D / (V × e(2 × D/V)))) / D2

…and even that assumes that I did things correctly.  Here’s the original equation in pretty shoulda-done-it-in-MathML-but-oh-well form:

I can shuffle the chairs around, as it were, but never really get anywhere close to having a single D on the left.  “But it’s so easy!“, you may well be shouting.  That’s why you’re working for Google and I’m not.

I remember having questions just like this on tests back in college: “Given this equation, solve for blah”.  It’s been too long, though, and in all honesty I was never that great at this sort of thing in the first place. Help, please?

[Update 14 Jan 09]: several commenters have shown that what I’m trying to do is impossible.  Frustrating, but that’s math for you.  Looks like I’ll have to take another approach.


Adoption Day

Published 16 years, 3 weeks past

Yesterday afternoon, in a small office on the second floor of the Cuyahoga County Courthouse in downtown Cleveland, Ohio, Kat and Carolyn and I finalized our adoption of Rebecca.  There were a few witnesses to this: the social worker who has handled our case from the outset, as she did Carolyn’s; the lawyer who made sure all of our paperwork was correct; our friends Gini and Ferrett; and the magistrate who conducted the proceedings.

As I did with Carolyn, I’ve avoided mention of Rebecca’s being adopted, though anyone who’s been reading the site for the last several years would probably have inferred it from the fact that Carolyn was adopted.  And as with Carolyn, I avoided saying anything because the adoption wasn’t legally final until yesterday.  Up to that point, we were borrowing her from the agency, as it were: they were her legal guardians.  It was possible at any point for the agency to remove her from our home.  In the strictest legal sense, they didn’t even need a reason to do so.  Ditto the state.  Had we missed one of the six monthly post-placement meetings with our social worker, for example, or even not met the required schedule, custody would have been revoked.

Now, of course, that’s no longer possible.  Now she is ours as legally as she has been emotionally, now judicially recognized as the part of our family she’s long since become.  It was her sister who made it official: the magistrate had Carolyn stamp the legal decrees, so that it was she who made the adoption permanent and binding.  Most of the witnesses choked back tears.  I felt a few eye-prickles myself, but suppressed them to make sure I got the pictures I hope both girls will cherish as they grow older.

After a celebratory dinner with friends, as we got ready for bedtime, I took Rebecca into my arms and whispered, “Welcome to our family, little one.  Again.  And forever.”


Fixing Postcodes

Published 16 years, 1 month past

In case anyone’s interested, I finally updated the ZIP archive of all the countries and postcodes from the 2008 ALA survey.  The two files are sorted like before, but this time leading-zero postcodes haven’t had their leading zeroes stripped by Excel.  Oh, Excel.

I have learned way more about Excel’s “helpful” handling of CSV and text imports than I ever wanted to know.  The basic drill is, if you want to open a CSV or text file but don’t want Excel to be “helpful”, don’t drop the file onto Excel or double-click the file icon.  No no!  That would be too easy.

Instead, launch Excel, select “File > Open”, and then select the CSV or text file you want to open in the file browser.  Go through the Text Import Wizard carefully:

  1. Tell Excel that the file is delimited on the first screen.  (Or, if it isn’t, then don’t.  I bet it is, though.)
  2. Tell Excel what delimiter you’re using on the second screen.
  3. Then—this is the crucial bit—on the third Wizard screen, select the columns you don’t want Excel to “help” you with and set them to “Text”.  Be careful about setting all the columns as “Text”, though: if you have non-ASCII characters, Excel will “helpfully” replace their contents with octothorpes when you try to export the data later.  Such “help”!  It’s so “helpful”!

Yay!  An open file where the data is all in its original state!

Now you can save the file as an Excel workbook and it should (but please note my use of the word should) leave your data alone.  Ditto if you do “Save As…” to export to CSV or text again, which you might do if you run some calculations and want to capture the result in a basic, portable format.  But remember!  If you ever want to open those CSV/text files in Excel, you can’t just open them.  You have to go through the whole text-import process again.

So the survey files now contain actual useful data, especially for countries where postcodes can start with zeroes.  (Which is a lot of them.)  The files also have the usual bits of abuse that come along with daring to ask people to supply optional information, because I didn’t even try to filter that stuff out.  So, you know, naughty words ahead.

In part, I’m posting this to leave a record for anyone else who runs into the same problems I had, and also to remind myself of what has to be done next year.  Also to provide a heads-up to anyone who’d like to grab the fixed-up data and do fun mapping stuff with it, as did some commenters on the previous post.


Shock and Awe

Published 16 years, 2 months past

I almost feel like the Presidential election didn’t happen.

You see, for the entire second half of Election Day, from almost noon until after midnight, Eastern time, I was aboard a Continental flight to Tokyo.  We had video-on-demand systems but not live satellite television, so as we arced over Canada, Alaska, and the northern reaches of the Pacific Ocean, we flew in ignorance.  As Jeremy Keith put it regarding his own flight to Japan, we were aboard Schrödinger‘s Airplane.

For me, the wave collapsed as we began the initial descent toward Narita.  One of the flight attendants, having announced that they were starting the initial-descent procedures and would like us to check around our seats for any personal items we might like to start stowing, added:  “And for those of you interested in the results of the election, we have a new President: Barack Obama.”

There was a burst of applause from the economy section of the plane.  In business class, there was silence.

Well, not quite.  I was myself sitting in business class, thanks to a great big pile of reward miles and some lucky timing in calling the airline.  As I heard her say Obama’s name, I let out an involuntary “Wow“.  Because until that moment, deep down I had believed, truly believed, that Mr. Obama would not win the Presidency.  That was not the outcome I desired, but it was the outcome I expected.

I am in many ways ashamed of my doubts and fears, because I had thought less of my fellow Americans than they deserved.

Since then, from here in Tokyo, I’ve felt weirdly disconnected from what’s happened.  In time zone terms, I’m fourteen hours in my home’s future, half a day ahead of everyone back home.  But because I received word after it was all over and soon after slept through America’s Wednesday daylight hours, I feel like I’m a day behind.  Time and distance combine to create a feeling of disconnectedness from the end result, as though I’m getting word of election results in Germany or India or Australia: interesting, but something seen at a remove.

It’s odd.  I’m used to being an observer, but this is something else entirely.  I think it’s pure astonishment.


Survey Mapping

Published 16 years, 3 months past

An anonymized copy of the data collected in the 2008 Survey has been turned over to some professional statisticians, as we did last year, and we’re waiting to hear back from them before moving into writing the full report.  But there’s no reason we can’t have a little fun while we wait, right?

So, calling all mapping ninjas: here’s a 136KB zip archive containing two tab-separated text files listing the countries and postcodes supplied by takers of the survey.  Before anyone has a privacy-related aneurysm, though, let me explain how they’re structured.

One of the two files is sorted alphabetically by country, with the postcodes as the second “column of data” (it’s country name, tab, postcode).  The second is the reverse: it’s sorted alphabetically by postcode, with the country names following each postcode.  This sorting should break any association they might have with the released data set, given that we won’t be including the postcodes in the released set.  (More on that in a moment.)

A word of warning: though I cleaned out some of the more obvious cases of people heaping abuse on us for even daring to ask the question, I can’t guarantee that the data set is perfectly clean.  There may be drops of bile here and there along with the usual collection of mistyped postcodes.  I know there’s at least one bit of obvious humor that I chose to leave in, so enjoy that when you find it.

We have two reasons to release this data this way at this point.  The first is to see what people do with it—heatmaps, perhaps, or one of those proportion-distortion maps, or a list of top-ten global postcodes or cities (or both).  Hey, go crazy!  I’d love to see a number of Google Maps/Yahoo! Maps/OpenMap/whatever mashups with this data.  That would be awesome.

The second reason is to ask for help with an API challenge.  Like I said, we’re not including the postcodes into the released data set.  What I would like to do instead is translate the postcodes into administrative regions (states, provinces, etc.) and put those in the data set.  That way, we can include things like “Ohio” and “British Columbia” and “Oaxaca”—thus providing a little bit better granularity in terms of geography, which was area of weakness in the 2007 survey.

Thanks to reading a couple of articles, I know how to do this for a single postcode.  But how does one do it for 26,457 postcode-and-country combinations without having to submit every single postcode as a separate request?  I’ve yet to see an explanation, and maybe there isn’t one, but I’d like to know either way.  And please, if someone does come up with a way, please show the work instead of just spitting out the result!  I’m hoping to learn a few things from the solution, but I obviously can’t do that without seeing the code.

One note: in cases where a postcode isn’t recognized or some kind of an error is returned, I’d like to have a little dash or “ERR” or something put in the result file.  That way we can get a handle on what percentage of the responses were resolvable.  Thanks.

Anyway, map and enjoy!


People and Places

Published 16 years, 3 months past

I don’t know about you, but I find the results of the People magazine cover Ericsperiment (thanks for the term, Bob!) to be quite interesting.  The boiled-down version of the results is: just about everyone saw what I did, but nearly everyone drew the wrong conclusions about what I was saying.  (What?  I’ll explain.)

First, I want to address a couple of objections that were raised.  The first was: “It’s just a family photograph”.  No, it’s not.  It’s a magazine cover shoot.  Those things are planned, directed, and executed down to the tiniest detail.  If you think it’s just a family portrait, you’re either being willfully obdurate or else completely ignoring the context.  That’s a mistake, because context is everything.  I’ve been involved in a few portrait sessions of no public reach whatsoever, and the photographer is always telling people where to stand or sit, adjusting the angle of people’s arms, getting them to fractionally tilt heads one way or the other, shifting people an inch or two, and so on.  “Just a family photo” is when the magazine gets a real family photo, taken by an amateur using a consumer-grade camera during a vacation, and puts it on the cover in a white Polaroid-esque frame at a 15-degree angle.

The second was that the image is a Photoshop job, created either by assembling individual shots or altering a group photo.  Maybe, maybe not; either way, Photoshopping or a lack thereof is completely irrelevant to my point.  If it wasn’t Photoshopped, then the photographer is responsible for the arrangement of the shot; if it was, then it’s the Photoshopper who bears responsibility.  Either way, someone arranged the shot, and did so very badly.

So here’s what I saw: “large group” and “outsider”.  That was the immediate message.  Look at the cover again, paying attention to where the faces are.  There’s a blob of faces above the headline text, which is the group.  Then there’s a face to the left of the headline text, which is the outsider.

This is completely independent of the race, color, gender, creed, etc. of the people in the photo.  The visual message is “here’s a bunch of people, plus a hanger-on”.  Not because of color, which is what most people assumed I was talking about (and more on that in a minute).  Because of placement.

Though I think this unlikely, you may not quite be seeing it.  In that case, imagine a cover image with nine faces in the same places, only they’re of religious deities.  Or pop stars.  Or CEOs.  Or heads of state.  Or conference speakers.  Or browser-team leads; heck, even browser logos.  Whichever it is, imagine your favorite of each group is in the lower-left position, with all the others up above.  Feel good about that?  Even neutral?  Still think there’s no message being conveyed by that placement?

(And if you still aren’t seeing it, maybe a comparative example, courtesy George Butler, will provide some insight.)

Now, given that one of the people has been placed as an outsider, the natural next step is to wonder why they’ve been so placed.  And here, there are obvious visual differences that jump right out:  like being female, having darker skin, and being younger.  Already primed to ask “Why is this person an outsider?” we can find apparent reasons, and in this case they’re touchy ones.  If you know the background story of the family, then there’s a non-visual one as well: that she’s adopted.

But remember, I’m not saying Bridget (the young lady in that position) has been excluded for any of those reasons.  I’m saying that having been given a visual cue that she is excluded, we look for reasons to explain that exclusion.  That’s exactly what most of the people who responded to my post about the cover did.  All those people saw it, consciously or otherwise, and responded to the message… and then took that next step, trying to find reasons to explain the message.  Then, as per each individual’s feelings and experiences, they reacted, either accepting or rejecting what they thought I was saying.  Interesting, though, that so many people came to the same conclusion about what they thought I was saying.  That’s evidence of a strong message, whether or not said message was intended.

And that is the failure that occurred, one which I lay squarely at the doorstep of the magazine.  I might also toss in a head-slap to the campaign, if they saw the image and gave approval to use it—such pre-approval is sometimes, but not always, an option.  The problem with that composition should have been obvious from the outset, and avoided.  That it wasn’t makes me wonder a number of things about the magazine.  Taking a teenaged girl and putting her in the outsider spot?  Seriously?  How callous do you have to be to do that?

Oh, and special postscript to all the people who took the time to share their pitying sorrow over how “you Americans” are so race-aware:  I know it’s a tragedy, but remember, we’re still a young country and have not had the same lengthy maturation time you’ve enjoyed.  So please, try to remain patient with us while segregation, anti-immigrant violence, race riots, tribal warfare, and ethnic cleansing uniquely wrack our poor, blighted country, and continue to hope that one day we’ll join the rest of the world in the tranquil harmony that so characterizes your enlightened societies.


Placement

Published 16 years, 3 months past

I was in line to buy a few groceries and spotted the latest issue of People magazine in the point-of-sale magazine rack, the one with the McCain family on the cover.  Something about the cover just seemed a little bit… off.  Do you see it, too?

There’s a metaphor there, but I’m having trouble deciding exactly what it is, or perhaps more accurately to whom it applies.

Seriously, I’m not generally one to read messages into things—in fact, I probably lean too far the other direction—but on this?  Somebody needs to be fired for gross negligence, because there’s a message being sent here, intentionally or otherwise.  In fact, it’s worse if it’s unintentional.  The question is who was negligent.  The photographer for not seeing what the placement communicated?  The editor for approving use of the image on their cover?  The McCain campaign for approving the image in the first place?

Maybe all of the above.

I’ll be very interested in people’s responses on this one… and even more in People‘s response, should anyone ask them about it.


Browse the Archive

Earlier Entries

Later Entries