2010-03-21

Visual Studio regions in XCode

One of the few features that I've liked in Visual Studio that XCode doesn't have is the ability to define regions for code folding. It's nice to have regions of code that are logically grouped that you can collapse when you're working on other parts of the same method. (Of course, regions also work across methods, but this hint won't address that.)

Fortunately, XCode allows for block folding (which the versions of Visual Studio I've used don't have), which allows you do to something like this:

//region I want to fold
{
...code...
}

This defines a statement block that you can fold. When folded it ends up looking like this:

//region I want to fold
{...}

One caveat here... don't define any variables in that block that you'll need elsewhere. The statement block defines a local scope for any variables declared. This might be want you want, but it may also cause scoping issues. The compiler will probably warn you about this, however.

2010-03-18

PowerShell Training

I've finished a training that I did at work around PowerShell... a great shell language from Microsoft.

Yes, I said it in public, I like something Microsoft did. :-)

Really, the designers of PowerShell did something revolutionary with the traditional command line, they made it object-oriented. The biggest leap forward was allowing objects to be pipelined throughout the shell. This makes the language feel very similar to ruby in the way that I use it.

Anyway, with little other comment, here's a link to my presentation, if you're curious:

2010-02-11

Vampires and the Anthropic Principle - a response

I read a number of Intelligent Design blogs, just to see what they have to say. I find it interesting to read what "the other side" thinks and how their arguments are structured. Over the years, the biggest frustration of mine is that they often use straw man arguments as they fail to grasp what evolutionary biologists are trying to say. Furthermore, they seem to misunderstand science in general and how it progresses. Anyway, this post isn't about that complain specifically, but I wanted to write about a post at a new blog I've been introduced to that brings Vampires into the Anthropic Principle to strengthen the argument... he says.

Go ahead and read what he has to say...
http://www.firstthings.com/blogs/firstthoughts/2010/02/10/vampires-and-the-anthropic-principle/#more-12597

This is going to be somewhat random, so here goes...

1) Claim: If Vampires existed, then their feeding patterns would overrun the human race within a few years.

The base of this claim is that a vampire converts a human into a new vampire each time it feeds, which means that there will be an exponential increase in the number of vampires and a corresponding decrease in the humber of humans. While I don't have any issues with the mathematics of this (even though he leaves out the possibility that some humans are killed without being turned and some vampires are going to be killed as well), the main problem is that - being a legend - there are great variations in the stores around vampires. In fact, in literature such as Anne Rice and Buffy the Vampire Slayer, the base assumption isn't valid. It's annoying when I disagree with the base assumptions, but what can you do.

At any rate, for the sake of making things sound formal, he continues with calling Vampires "V-class objects" in recognition that there could be other destructive agents in the universe.

Moving along, he states the Anthropic Principal in a negative way (so he says).

2) Claim: In order for humans to exist, there must be no V-class objects in existence.

To restate this, he's simply saying that in order for humans to exist, there must be nothing in existence that would kill off all the humans. When you state it this way, it almost sounds silly. It is, in fact, a tautology when stated like this. In my opinion, this shows that he lends no additional argument to what the anthropic principle already says, which is that the universe must be amicable to our existence simply because we exist.

He is trying to argue that the probabilities that the universe would be able to support life is calculated separately from the probability that the universe does not contain things that would kill off all life. Since these are logical inverses of each other, separating their meaning into two probability calculations seems unjustified.

Besides, the anthropic principle's purpose in life is to show that the probabilities are next to meaningless. To state it in my own way, it says that the fact we exist means that the necessary elements must have been in place. Anecdotally, to the person who won, the chances of winning the lottery are irrelevant... because they already won. Once an even occurs, we now have a given and no longer a chance calculation. It might be interesting to tell a millionaire that there was only a 0.0001% chance of him winning, but that won't change the fact that he won after only playing 14 times.

3) Claim: the likelihood of existence of a V-class object exists as an independent probability.

This claim is not directly in the post, but rather a base assumption that I see in the text. In order for any probability calculation like this to make sense we basically have to have independent events. As soon as there is causation between elements of the calculation, using a raw probability does not make sense.

As an aside, this seems to be the major issue with the tornado in the junkyard producing the 747 argument. Yes, the probability of that happening is low... so low as to assume it can't happen by chance. But biologists do not claim that random chance is responsible for the development of life on this planet. So, to use an analogy of a tornado is not a valid comparison. Period.

In the case of V-class objects, there is the implicit assumption that the development of such objects is independent of the development of humans. This isn't the case, however. Humans have, along with all other life on this planet, become successful while competing for the resources of the environment in which we life. This competition implies a couple of things.

First, there have been things that otherwise might have been V-class objects that died off due to some other reason. Maybe there was a superbug that would kill off humans, but it was isolated in a small town. Maybe there was a species of saber tooth cat that might have wiped out humans, but it failed in other ways. (Remember, just because something can kill us doesn't mean that it isn't vulnerable to other organisms. Maybe our V-class objects have been killed off by W-class objects.)

Secondly, and a bit of a continuation of the last point, maybe we are the V-class object. In the course of our evolution we have killed off numerous other species. Some incidentally, some directly... but the recurring theme is that we are still here and those aren't. Of course, it would be arrogant to assume that we are somehow more successful than other animals. The sharks and alligators seem to have done far better than us when it comes to staying power. Maybe we can play piano, but if success is measured by years in existence, we're just getting started. Maybe we just haven't met any V-class objects yet.

2009-11-18

Load Balancing with Safari - Part 1

When running a web site that has grown to the point that it has too much traffic for a single server, it is common practice to put a load balancer in front of the servers.

Unfortunately, there are all sorts of subtle problems that crop up that you may not notice at first. Most of them come down to sticky session issues (or lack thereof) and the fact that many web apps store session data in server memory. When a browser makes a request to a new server, it doesn't know anything about that browsers session, so a new session is created in memory and the user may experience weirdness: logged out, re-authenticated, losing their shopping cart, etc.

Most load balancers can be configured for various methods of sharing traffic: round robin, least connections, etc. Also, they can usually be configured to not move a client to a new server if it already has a session on one. This can be done via IP address or a custom cookie inserted into the

T
his is something I observed a long time ago for Safari (ie: around version 1). I'm not sure this is Safari, per se, but OpenSSL that is responsible for the behavior. I'm pretty sure Chrome does this and I've seen some Linux browsers do it.

What I have done at the last two companies I've worked for is recommend that our clients do not use SSL SessionID as the way of tracking sticky sessions on web servers, but instead using IP address. This works in nearly all cases and has few downsides. The other solution is to use some sort of session sharing on your web servers to mitigate the issue (which also means that your web servers aren't a point of failure for your users' sessions). (One of the products I supported had no session information stored on the web servers, so we could safely round-robin requests, the other product could be implemented with a Session State Server... but in most cases we just used IP address to load balance with). The other solution is to configure your load balancer to terminate the SSL tunnel. You get some other benefits from this, such as allowing your load balancer to reduce the number of actual connections to the web servers. I've seen many devices setup this way.

One thing to consider through this is that - due to the way internet standards work - this really can't be termed a bug on anyone's part. There is no guarantee in the SSL/TLS standards that a client will return the same SSL Session ID for each request and there is not requirement that subsequent requests will even use the same tunnel. Remember, HTTP is a stateless protocol. Each request is considered a new request by the web server and everything else is just trickery to try and get it to work the way you want. You can be annoyed at Safari's behavior, but it's been this way for over 5 years by my count, so I don't expect it to change.

2009-10-09

I like Ruby

I'm working on something at the office in which I have a client running in C# .net code and a web server running with Ruby On Rails. Occasionally, when switching between them, I'll sometimes think of a Ruby solution to some code I'm writing in C#.

Recently, I had a loop that looks like this:
bool matchedOne = false;
foreach ( ScalarMatch match in MatchSet.Matches )
{
if ( match.PerformMatch(check) )
{
matchedOne = true;
break;
}
}
if ( ! matchedOne )
return null;

And I realized that the Ruby method would look like this:
return nil if not matchSet.matches.all? {|m| m.performMatch(check) }

I like Ruby.

2009-01-21

Christmas Cards - better late than never

I suppose we could claim we're just really early for next year.  Oh, except that the date is on the pictures.  Oh well.

Yes, we got cards out about a month too late.  We were so on the ball at first.  We went to Sears Portrait Studio, let them talk us into getting their cards instead of making our own... and then it started to slowly and subtly fall apart.

First, it took us at least a week after the date we could have picked up the cards before we actually picked up the cards.  Sadly, we were at the mall at least twice before that... we just forgot.

The "the snow" happened.  I'm sure everyone knows what I mean by that, but just to make the point again, we had snow on the ground for something like 2 and a half weeks.  That delayed packages, it rescheduled a play that we were going to see (Wizard of Oz at the Children's Theater, very good, by the way) and it screwed with our sense of time.  (Our kids were out of school for three weeks instead of two and, for that first week were bouncing off the walls... we realized a week too late that the day care center was, in fact, open.  We just assumed they would be closed when the school district was closed.  Oops.)  Dawn and I both worked a bit more over the holidays than we might have otherwise, because of the weather and needing to have someone in the office.  I worked overnight twice, which really messes with your internal clock.

We actually got the cards home a few days before Christmas, if I remember correctly.  Then they got lost in the paper trap that we call a desk.  They remained there, forgotten, until the first week of January.  When we decided to take a look at the list of people to send to, it only took an extra hour of looking before I found the cards again and less than two hours after that we had them all addressed, stuffed and stamped.  Whew!

Then they sat in the car for two weeks...

2009-01-02

Christmas 2008

Christmas in 2008 was weird.  The snow here in Portland was so out of the ordinary that we didn't have things happen quite the way we expected them to.  A few presents that we intended to get were left out (I never got back to the store after I decided what I was going to get Dawn... and it's not like I left it until the last minute!).  Also, we ended up getting packages out to family late, and things sent to us arrived late as well.

Here are some pictures of Christmas Day.

In fact, we ended up having a "second" Christmas this year, on New Year's Eve.  It was good timing, actually, as we had gotten the package from my mom a couple days previously and, about a half hour after we opened those things, the package from my brother arrived.

Oh, and one more note: One of Bryana's presents came with a promotional DVD of space came.  Between that and the space helmut, Bryana has now decided that she wants to go to space camp earlier than she had wanted to before... so that may be only a year or two out as an adventure for her.