Monday, May 4, 2009

Rails is awesome ... too bad the creater and much of the community are total dickwads.

In a moment of genuine unintended irony, I decided to start learning Rails at the exact moment that a huge uproar happened over a conference presentation that contained pornographic images and the following "don't hamper my freedom from expression/to look at naked chicks" response from much of the Rails community. Worse yet, DHH, creator of Rails and partner in 37 Signals, condoned the talk.

Honestly, I've mostly been avoiding going in depth into it because I know how much it would piss me the fuck off and turn me off from Rails and feeling safe and comfortable asking questions and just generally participating in the community. {:thought_bubble => 'fuckers' }

But recently there was some discussion on Systers (thank goodness for Systers!). I still am not really ready to formulate thoughts on this ... partly because I don't really feel like I'm part of the Rails Community at all (fyi - this didn't help and doesn't really give me much hope that I ever will be). Instead I'll just link to other people's thoughts on it.

Scott Hanselman's Computer Zen - one of the first posts I saw on the subject

The ladies respond ... (contains slides and DHH's comments) (read the comments - she has some good stuff to say about women adopting ruby) (really great thoughts on negotiating gender and sexuality in a male-dominated field)* (really good thoughts on the affects of associations - subconscious or otherwise)** (good summary) (summary of women's thoughts. my fav "What about a presentation about writing code on deadline: 'Delivering Like a Birth Mom.'")

On both the up and down side, Mike Gunderloy resigned from Rails Activists. On the one hand, I'm really happy that there is an important male figure in the Rails community who thinks this is serious. On the other hand, I can only imagine the kind of private conversations he had with other members of the community causing him to believe that "the difference between their opinions and mine is so severe that I cannot in good conscience remain a public spokesman for Rails." On another up side, the comments on this post were really supportive and understanding.

Last but not least, DHH has a post on getting more women into Rails. I agree that " simply refraining from having saucy pictures of pole dancers is going to do the trick". But let's not pretend that it won't help.

Ok. I can't help. I'm commenting:
* A commentor said this:
"Ruby, like most/all (?) current software projects is male dominated. This may or may not be because of an essential difference in the interests/motivations of the sexes - but this isn’t important - the only factor is the competence and passion of the individual.

Open-source projects, in particular because of their distributed nature, have values based around contributions. If you’re able to make good contributions, then regardless of your identity, you’ll do well.

This has always been my experience - coders listen to people whose code they respect."

As much as I wish I could, I know I will never ever be able to convince some dude who believes that just how fucking wrong they are. The fact is priviledge is really really hard to see and until you have coded something awesome and gotten no credit or had a guy you worked with get/be given all the credit or say something in a meeting only to be totally ignored until some guys says the exact same thing and everyone is like 'totally that's such an incredibly brillant idea', you won't get it. But maybe, if you're one of those people who believe that your coding is all that matters (not to mention the barriers to entry to be any kind of coder let alone a good one), you could just try really hard to pay attention to how you are treated vs how the women in the room are treated.

** I've seen in a couple places Matt (the presenter's) response was: “I would have hoped that people who were likely to be offended would have simply chosen not to attend my talk or read my slides on the internet”. The extent to which that is un-fucking-acceptable kills me. Who is most likely to be offended by this talk? Could it be the people whose gender is naked in half the slides? So I shouldn't get a chance to learn a technology (that itself isn't offensive) at a conference I've paid to go to to learn, because you're a frat-boy who doesn't know how to behave appropriatley in public? Again, this is just another example of the ways in which things like this discourage women from technology.

Tuesday, April 14, 2009

Configuring WCF with BasicHttpBinding and SSL

Despite a variety of posts on this topic, I had to go through a bunch of articles just to get what seemed to be a simple task.

I started with this post How to setup a WCF service using basic Http bindings with SSL transport level security. The post gives a good explanation of how to get a ssl certificate and set up IIS to use the certificate. In my case, I just wanted to use SSL and not credentials. So I modified the web.config like this:

<binding name="basicHttps">
<security mode="Transport">
<transport clientCredentialType="None" />
<message />

Then I added a bindingConfiguration to the service configuration:

<service name="PartnerAPI.Service" behaviorConfiguration="PartnerAPI.ServiceBehavior">
<!-- Service Endpoints -->
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttps" contract="PartnerAPI.IService" >

Now after doing that, I went to my service at https://localhost/PartnerAPI/Service.svc?wsdl which gave me the error: "Could not find a base address that matches scheme http for the endpoint with binding MexHttpBinding. Registered base address schemes are [https]."

I also needed to tell the MexHttpBinding to use SSL. Fortunetly, .Net gives us SSL for MexHttpBindings so we don't need to configure it. Set the binding attribute to mexHttpsBinding instead of mexHttpBinding.

<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>

Since I had httpGet enabled for Metadata, we also need to set it to use SSL. Instead of setting httpGetEnabled="true", I set httpsGetEnabled="true".

<serviceMetadata httpsGetEnabled="true"/>

Finally, the wsdl displays correctly with https and I get a 403 error with http. I change the url in for my test client but when running unit tests, I get this exception "System.ServiceModel.Security.SecurityNegotiationException: Could not establish trust relationship for the SSL/TLS secure channel with authority."

This is happening because in dev, my SSL certificate is invalid. I need to override validation of the certificate in my test client.

//force acceptance of invalid ssl certificates (for dev)
ServicePointManager.ServerCertificateValidationCallback += ((sender, certificate, chain, sslPolicyErrors) => true);
//create the client
client = new PartnerAPITest.TutorAccountAPI.ServiceClient();

Note: I'm using an anonymous function that always returns true. You could also create a custom class that inherits ICertificatePolicy. Both approachs are explained here.

Tuesday, February 3, 2009

Getting random rows from Sql Server

I'm working on a project where I want to return related content. The sproc I wrote seems to work ok but because I was sorting by the insert date or the title, it would always return the same thing for all content closely associated.

So how do I get it to return only the closely related content AND randomize it?

Here is the what I did:

FROM #tmpRelated r
JOIN Content c ON r.ContentID = c.ContentID
ORDER BY r.TotalRelevance DESC, r.TotalMatches DESC, newid()

Ordering by newid() will return a random row in Sql Server. In testing this, it worked perfectly. Cool!

Here is the article I found on this. It gives ways to return random rows in Sql Server, MySql, PostegreSql, Oracle, and IBM D2.

Monday, January 26, 2009

Neat way to handle Nullable types ...

Ever since I read Rick Strahl's blog post on the C# ?? operator, I've been in love with the C# ?? operator. Mostly I use it as a clean way to test a ViewState variable for null in a property. For example,

protected string stringToPersistOnPostBack {
   get {
      return (ViewState[this.ClientID + "_stringToPersistOnPostBack"] ?? "").ToString();

Somewhere along the way, the real purpose of the ?? operator was forgotten though. It's true purpose is to give a default value to a Nullable type thus allowing you to use it as the type.

I started with this code:

bool doExpand = (IsPostBack && e.Node.Expanded);

which gave me an error: "Operator && cannot be applied to types 'bool' and 'bool?'"

While I often enjoy the use of Nullable types, they do introduce often annoying, sometimes unnecessary complexity to code. But thankfully, the nice folks at Microsoft came up with a rather nifty solution ... the ?? operator.

At first, I thought I'd have to use the ?? operator to give e.Node.Expanded a default value of false AND cast the object to bool. Instead, all I had to do was this:

bool doExpand = (IsPostBack && (e.Node.Expanded ?? false));

See? Neat!