Mental Jetsam

By Peter Finch

  •  

    December 2009
    M T W T F S S
    « Oct    
     123456
    78910111213
    14151617181920
    21222324252627
    28293031  
  • My del.icio.us links

  • Flickr Photos

    S5001187

    S5001169

    S5001136

    More Photos
  • Wordpress Stuff

Teaching children about how to save money

Posted by pcfinch on October 24, 2009

A mate of mine recently wrote an great article on a simple “kid friendly” way to help children learn to save money and how to use it responsibly. I particularly like the “Give” section, as it’s not all about saving just for ourselves. If you have kids (or know someone who does) then this is a great idea and you should check it out here Money Boxes Pocket Money System For Kids.

Personally, I think we can all learn a lot from this article…

Posted in Personal | Leave a Comment »

Hyperlinks on Google Charts

Posted by pcfinch on May 1, 2009

I love Google Charts! If you have ever needed to present information on a web page in a chart form, then Google Charts is really worth looking at. Once you have the chart on your webpage you may want to click on a entry of the legend (the little box that tells you what-is-what on the chart) to take you to more information on that section of the chart. Sadly, the API does not currently have a way to add links to a chart.

This is a simple way to add hyperlinks (or hotspots) to a Google chart using an image USEMAP.

<img src="http://chart.apis.google.com/chart?cht=lc&chd=s:Uf9a,a3fG&chs=250x100&chl=1|2|3|4&chco=000000,0000FF&chma=0,30,30,30&chdl=Desktops|Laptops"
   usemap="#chart" border=0>
<map name="chart">
<area shape="rect" coords="199,31,249,49" href="javascript:alert('More information on Desktops')">
<area shape="rect" coords="199,50,249,69" href="javascript:alert('More information on Laptops')">
</map>

The above HTML ends up looking like this. If you were [on a normal webpage] to click on the “Desktops”, or “Laptops” sections of the graphics you will see the javascript popup. Sadly, the USEMAP does not work on WordPress (this website) web pages, but you get the idea. You can of-course replace the javascript with a link to another page if you like, or even another chart!

The down side of this approach is that it works great as long as the legend does not move or the size of the chart does not change. It seems to work pretty well with line and bar charts, so select your chart type carefully and play around and see what happens.

Posted in HTML | Leave a Comment »

C# SQL Server result in XML

Posted by pcfinch on April 5, 2009

Formatting the output of a SQL query in XML using SQL Server is really simple and
very powerful if you want to deal with XML in the applications instead of normal
Record sets. The following is a simple SQL Query to
produce the results in XML. The XML essentially comes back to the application
as if it were one column of a result set with one row.

SELECT username AS '@username', password AS 'password'
FROM [dbo].users
WHERE username = @USERNAME
FOR XML PATH('User'), ROOT('Users'), TYPE ;

The PATH(‘User’) option creates an XML ‘User’ element for each row in the
result set and the ROOT(‘Users’) option wraps all the results in the ‘Users’ element.
For each of the columns in the result set simple specify the element name you want
the data to appear in (e.g. ‘password’) or put a ‘@’ at the start of the name
to place the contents of the column in an attribute of the row element
(e.g. ‘@username’). The output of the query is as follows.

<Users>
 <User username="fmcske">
  <password>password</password>
 </User>
</Users>

If your using C#, the following example code can be used to read the
results of the query and create a DOM object.

using (SqlConnection connection = new SqlConnection(sConnectString))
{
    connection.Open();
    using (SqlCommand command = connection.CreateCommand())
    {
        DateTime startTime = DateTime.Now;
        command.CommandText = sSqlQuery ;
        command.Parameters.Add("@USERNAME", SqlDbType.VarChar, 32) ;
        command.Prepare();
        command.Parameters["@USERNAME"].Value = sUsername ;
        using (XmlReader reader = command.ExecuteXmlReader())
        {
            XmlDocument dom = new XmlDocument();
            dom.Load(reader);
            /* ... */
        }
    }
}

Posted in C#.NET | Leave a Comment »

Firefox HTTPS error ssl_error_rx_record_too_long

Posted by pcfinch on March 11, 2009

I just had an interesting problem when accessing a HTTPS (SSL) service in Firefox. I got the following error message.

SSL received a record that exceeded the maximum permissible length.
(Error code: ssl_error_rx_record_too_long)

It turned out the the HTTPS service (on port 443) was not actually a HTTPS service and it was configured as a normal HTTP service. The initial connection from the browser was communicating in HTTPS, and expecting a security certificate, but instead it was getting back the normal HTTP “Bad Request” HTML. A confusing error message, but an easy problem to fix.

Posted in Web | 3 Comments »