Wednesday, April 24, 2013

Photos from Austin on Rails Apr 23, 2013

Just in case you wanted to know what the Austin on Rails group looks like in an IPhone panorama shot: 70 people listened as Matt Swain talked about Amazon's cloud solution and how to use Elastic Beanstalk, the Amazon tool for configuring virtual servers. (It took me way too long to get the Jack and The Beanstalk/Cloud connection).


 

Mike Myers from HomeAway gave a good overview of using a JRuby/Rails front end with a Java backend.

I talked with Jeff Hennigan, the main recruiter at KForce, before the meeting and he said a few interesting things: The Ruby job market is hot. Java and .Net are still good. This new generation of Ruby programmers is different than the Java/.Net crowd. Some of the startups use social media to communicate and don't even have a phone number.


My random jumble of notes:
AWS comes with Route53 for DNS and Cloudfront for CDN.
"eb" is a
Command Line Interpreter for Elastic Beanstalk; so you can do "eb init", "eb stop". It just abstracts our the
JSON file that really defines an AWS service.
Amazon offers a free virtual server for those wanting to try out the system. 750 hours per month free.
Amazon tunes the kernal in their own version of linux for different sized machines.
JRuby gives real Native Threads, while Ruby only has green threads.

Monday, April 08, 2013

Pictures from Austin .Net Meeting April 8th, 2013

Ryan Vice gave an interesting overview of Web API to 65 software professionals.




My brief jumbled notes:
AustinApi will be having it's first meeting Wednesday, April 24, 2013 for those interested in producing and comsuming web APIs.
The HTTP PUT verb is used for idempotent actions, otherwise use POST. "application/json" is the header for passing JSON.
Fiddler is a great tool to use for testing APIs.
Response.AddHeader("location", "http://example.com/Accounts/4")
The MVC4 model binder can grab values from the url, the body, or the headers.
Microsoft, to their credit, is using the open source JSON.NET serializer. You can customize the variables returned by using a custom ContractResolver. (return "first-choice", or "firstChoice" or "first_choice").
IAPIExplorer can document your APIs similar to a WSDL.
You can download the WebAPI "Help Pages" from nuget.
I liked Ryan's last comment about Web API bringing us closer to the "elusive dream of concentrating on business logic." (Not necessarily because I think Web API will do that for us, but it should be the focus of frameworks to remove all the mundane tasks that slow us down. Perhaps in 40 years we will get there.)

Friday, March 01, 2013

How To Create a simple .Net HttpHandler

I'm writing a heartbeat diagnostic page that will test all the database connections and make sure my application is up and running.   Since it produces a page that will be read by a monitor very frequently I chose to make it an  HttpHandler.  Normal .aspx pages go through like
12 events or so.  Since I don't need the full power, and resource consumption, of an aspx page, an HTTPHandler seemed like a good idea.
 
It's actually quite easy to create an HTTPHandler in .Net.  This shows how to integrate a single HTTPHandler into an existing .Net 4.5 project using VS2012.

The first step is to create a .cs class which implements IHttpHandler, mine is named Heartbeat.cs:

using System;
using System.Web;

namespace MyNamespace
{
    public class Heartbeat : IHttpHandler
    {
        public bool IsReusable
        {
            get { return true; }
        }
        public void ProcessRequest(HttpContext context)
        {
           context.Response.Write("Hi There!");
        }
    }
}

The second step is to create a .ashx page with one line.  Here's my Heartbeat.ashx page:

<% @ WebHandler language="C#" class="SurveyDirector.Heartbeat" codebehind="Heartbeat.cs" %>
And you are done.
 
Now entering the URL

http://127.0.0.1/MyProject/Heartbeat.ashx


I get

Hi There!


Done.

Wednesday, February 27, 2013

Corporations Should Not Drive National Politics

In addition to bringing back section 16 of the Glass-Steagall Act prohibiting investment banks from gambling with tax payer money, we need to bring back the Tillman Act of 1907 forbidding corporations from funding politics.
 
Teddy Roosevelt in his 1904 address to Congress said,
"All contributions by corporations to any political committee or for any political purpose should be forbidden by law; directors should not be permitted to use stockholders' money for such purposes;"


In 1907 Congress passed the Tillman Act which stated "... it shall be unlawful for any national bank, or any corporation organized by authority of any laws of Congress, to make a money contribution in connection with any election to any political office."
The part of corporations funding politics that bothers me is not the presidential election candidates, but to congressmen writing laws for corporations to follow.  It's too easy for a corporation to tell a congressman they would like her to support a bill, like extending copyright way beyond its usefulness to encouraging people to create works of art.  The congressman gets paid tens of thousands of dollars, and the corporation reaps millions of dollars profit at the expense of the American people.
 If she doesn't support the law, the corporation can threaten to fund her opponent.
That's just too much leverage against the interests of the people.

System.Net.WebException : Cannot handle redirect from HTTP/HTTPS protocols to other dissimilar ones.

Currently I am writing an integration test that enters a scenario into the database, then invokes a url on my web site, and then checks to make sure the database has been updated properly.   While doing this I ran across this error:
System.Net.WebException : Cannot handle redirect from HTTP/HTTPS protocols to other dissimilar ones.
My C# code looked like this:

string webPageText;
 using (WebClient client = new WebClient())
 {
    webPageText = client.DownloadString("http://www.myserver.com/appname/params");
 }

It took me too long to understand the error message.  The real problem is that my app was issuing a 302 redirect and my C# code doesn't know how to handle that.  It failed the unit test, which is what it should have done.  Once I corrected my input, the redirect to an error page was not raised, and my test passed.




Thursday, February 21, 2013

Upgrading from .Net 3.5 to 4.0

I'm upgrading an old ASP.Net app from .Net 3.5 to 4.0.  Here were some of my issues:
1.  Compile error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)
This is error is from the build machine using the old 3.5 libraries.  We have to tell it to use the 4.0 libraries in nant.  I added this to my nant build script:
<property name="nant.settings.currentframework" value="net-4.0" />

2. The automatic upgrade did not switch all the versions, I had to manually change the version number for many of my projects from:
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C5619000000"/>
to:
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C5619000000"/>

3.  Menu Items from Web.sitemap disappered
The orginal code looked like this:
if (SiteMap.CurrentNode != null && SiteMap.CurrentNode.IsDescendantOf(node))
                {
                    Repeater repeater = (Repeater)e.Item.FindControl("repeaterBar");
                    repeater.DataSource = node.ChildNodes;
                    repeater.DataBind();
                }

I added one new condition to see if the current node was the node:
                if ((SiteMap.CurrentNode != null)
                     && (SiteMap.CurrentNode.IsDescendantOf(node) ||
                    SiteMap.CurrentNode == node))
                {
                    Repeater repeater = (Repeater)e.Item.FindControl("repeaterBar");
                    repeater.DataSource = node.ChildNodes;
                    repeater.DataBind();
                }
            }
Then it worked like it did in 3.5.

4.  A form submission gave this error:  "A potentially dangerous Request.Form value was detected from the client"
This was fixed by adding  "<httpRuntime requestValidationMode="2.0" />" to the web.config under "<System.Web>"

Overall the upgrade was not too bad.

Tuesday, February 05, 2013

The Coming Collapse of Gold

Photo by Bjørn Christian Tørrissen
 Gold has been a store of value since the dawn of civilization, but that's about to change.  Gold prices are going to plummet in the future - permanently.  I can't give you  a date, but I can tell you how it will happen.

In all of human history we have managed to pan, blast, and pry about 176,000 metric tonnes of gold from mother earth.  While the oceans are estimated contain about 20 million tons of dissolved gold.  The gold is very low in concentration, about one milligram in a ton of sea water.

Although many people have tried to extract the gold from the sea, none have done so successfully.  The most famous was German chemist Fritz Haber who tried to pan the oceans for gold to repay Germany's war debt.  Many swindlers have tried to sell the idea, but only succeeded in mining gullible rich people.

Photo by US Mint
 But that will change in the future.  A few methods may be possible to rob Poseidon of his wealth.
1.  Microbes are known to take dissolved gold and produce solid gold.  Pedomicrobium 
is an example as is Delftia acidovorans . These could be genetically altered to increase their yield.

2.  Designing sheets of materials that have an affinity for gold and placing those in ocean currents.  The sheets are anchored to the sea floor and recovered months later after filtering the precious metal.  Japan has used a process like this to test the recovery of Uranium..  Uranium is much more abundant in ocean water, 4.5 billion metric ton, but the concept is the same.
3.  Plants like kelp could be genetically engineered to have an affinity for gold and then be harvested.  Although this solution has many obvious issues.  Otters with gold-capped teeth anyone?
Photo by Bullion Vault

As material science progresses, it is just a matter of time before we can start to pan the oceans for gold.  It may take 10 years, or 50, but eventually someone will crack the code.  When they do, vast new quantities will pour into the world's markets permanently depressing the gold market.