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 ...
http://www.sarahmei.com/blog/?p=46 (contains slides and DHH's comments)
http://www.ultrasaurus.com/sarahblog/2009/04/gender-and-sex-at-gogaruco/ (read the comments - she has some good stuff to say about women adopting ruby)
http://dyepot-teapot.com/2009/04/25/dear-fellow-rubyists/ (really great thoughts on negotiating gender and sexuality in a male-dominated field)*
http://lizkeogh.com/2009/04/29/i-am-not-a-pr0n-star-avoiding-unavoidable-associations/ (really good thoughts on the affects of associations - subconscious or otherwise)**
http://www.blogher.com/tipping-point-women-tech-heres-hoping (good summary)
http://hackety.org/2009/04/29/aSelectionOfThoughtsFromActualWomen.html (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:

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

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:

SELECT *
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!

Thursday, October 9, 2008

Web Dev Best Practices

This has come up in various conversations recently and I was bored so I was googling for html best practices. I thought this article from Apple was quite good.

Tuesday, September 30, 2008

Forcing ASP .Net Validators and ValidationSummary to use CssClass

Here's something strange. If I create a validator using the following mark up:

<asp:requiredfieldvalidator id="rfv_txt" runat="server" errormessage="Required" CssClass="errorText" />

and my css class is:

errorText {
color: purple;
}

My validator still renders with red text. Checking the markup, I see that ASP .Net has added an inline style attribute (style="color: red"). Obviously, inline styles take precedence over class styles. But why is this inline style being applied at all?

I found this blog post that fixed the issue by setting the Forecolor to Color.Empty but it could only be done server-side. I figured there must be a way to set this client-side and after much annoyance, I found it:

<asp:requiredfieldvalidator id="rfv_txt" runat="server" errormessage="Required" CssClass="errorText" Forecolor="" />

So in order to set the color of validators or ValidationSummary via a CSS class you must set both the CssClass property and set the Forecolor property to an empty string. Why ASP .Net? Why?

Friday, August 1, 2008

WPF Data Binding Not Refreshing When Bound to Static Object

And the WPF Data Binding wierdness/frustration continues ...

I have a DataTemplate where DataType is defined. (In other words, WPF magic figures out when to use the template based on the type that is being bound). The Template includes a ComboBox which is bound to a static object in my UserControl class. The SelectedItem of the combobox is bound to a property of the DataTemplate's type (which, in this case, is a linq entity object).

It looks something like this:



My problem was that when I changed the DataContext of the UserControl which in turn changed the DataContext of this DataTemplate's parent control and the DataTemplate itself, the data in the ComboBox didn't change. In other words, while all the controls around it were being re-bound, this particular control wasn't.

Grrr.

After much googling, I found a cheap - but helpful - solution. Force the ComboBox to rebind every single time but adding a IValueConverter (which does nothing but return the value) to the binding.

Here is the article with the solution.

Seriously, these WPF Data Binding issues are ridiculous. I mean what exactly was Microsoft testing this shite for? It surely wasn't real-world examples or even with it's own new technology (Linq to SQL for example).