Category: Programming

The Rise and Fall of Waterfall

Sadly, I still think there are a lot of companies that still just think,code, guess, code, guess some more and maybe eventually come up with something. We need a repeatable process that should be fairly iterative.

Browser Redirection – Yahoo Answers

I am having problems getting mozilla firefox to display my website correctly. It works fine on Internet Explorer. So I was thinking of making a mirror of the website that is made specifically for firefox browsers. Is it possible to code a website so that it detects what browser a visitor is using and them sends them to the correct mirror ?(i.e. index_firefox.html or index_ie.html)

Background Information
At the root of this question, there lies a huge problem that really never would have occured if browser creators followed the w3c recommendations. Microsoft and Netscape fought the original browser wars in the 1990s and throughout this time both created proprietary nonstandard tags and didn’t always follow the w3c recommendations. Eventually, Microsoft’s Internet Explorer won the war and Netscape disappeared into the oblivion to eventually become the Mozilla Project.

Mozilla Firefox, Opera, Safari and Chrome basically render almost exactly (99% of the time) the current w3c recommendations for css,html, and javscript and most of the draft recommendations are followed in the current builds of these browsers. Internet Explorer on the other hand, barely follows any of the w3c recommendations from even the year 2000. IE’s terrible rendering results in us having to perform significant testing and spend significant amounts of time doing IE6, IE7, and probably now IE8 hacks.

Problems With Potential Solution
I believe that redirecting based on a browser is a terrible idea, and should be avoided at all costs because of the potential doubling or trippling of work with regards to content.

Also, what happens if the browser doesn’t have javascript support of a user has turned it off? Chrome, Firefox,Opera, and Safari users would continue to be dished out a crap website that only works on some version of IE.

My Solution
Avoid the use of redirections for different browsers and instead developing a website that is 100% standards compliant and than start to add IE hacks as necessary.

Open Source Week 2009

I am so excited to say that I finally booked everything I need to attend the Toronto Open Source Week. In a couple of weeks time, I will be spending a couple of days in Toronto while attending the many conferences, workshops and presentations on open source software (GNU Linux, PHP, etc.)

I am hoping to do some serious networking for my consulting business, along with getting more experience with web programming and the rest of the LAMP stack which seem to be creating an IT revolution.

I hope to see you at some of the events!

Books I’ve Read

Sometimes, when I have applied for full time employment in the past I have seen job ads or received responses from companies asking what books I’ve read. Nearly every time, I have heard this question I was so shocked because I didn’t ever keep track of what I had read or where I had gleamed those little bits of valuable information.

This list will be updated at least monthly, although when I have an abundance of extra time I might be able to read an additonal book or two. Please note that this list only contains books I am interested in professionally and in no specific order.

Books Finished:

  • ASP.NET 2.0 Unleashed
  • Beginning Ubuntu Linux
  • C# How to Program
  • Code Craft: The Practice of Writing Excellent Code
  • Don’t Make Me Think: A Common Sense Approach to Web Usability
  • jQuery In Action
  • Network+ Guide to Networks
  • Learn to Program With C++
  • Practical Web 2.0 Applications with PHP
  • Systems Analysis and Design in a Changing World
  • Teach Yourself HTML 4 in 24 Hours
  • Visual Basic 6 Complete
  • Web Style Guide: Basic Design Principles for Creating Web Sites

Currently Reading:

  • Operating System Concepts

Although the list is getting pretty extensive, please understand that these are books I can verify as of September 7th 2009. The title suggests this is only books, so please remember that I definitely have visited many websites along the way.

Read a Whole Textfile Into a String

At work, I’ve been working on an auto html emailer.   I’ve been receiving files from our Latin American office that are completely in spanish and trying to sift through the HTML and recreate the email taking into account size and the fact that Outlook 2007 still doesn’t accept background images and most CSS.

Anyway, one of the files they sent originally that the old software produced didn’t work. And to prove this, I had to somehow figure out how to loop through this text file they’ve been sending and prove this to my boss. I eventually found a function, that would let me avoid the looping, the steam writer and just do it.

System.IO.File.ReadAllText(String fileName)

Mouse Overs For ASP.NET

Have you ever wanted to have the ability for the colour of a row to change when your user moves the mouse over top of a particular row, and then change the colour back whenever the cursor is moved back off?

Well, this process isn’t very difficult in fact using some knowledge of JavaScript & the Document Object Model (DOM) we can dynamically change the background colour.

We need to override the Render class and then add some attributes to each GridViewRow before the page is finally output to the browser.

In this example, I have called the gridview we are adding the mouseovers and mouseouts “gvClients” because it displays a list of my fictional company’s clients. Wherever you see gvClients you need to make sure that you change this to your respective gridview’s name.

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
   /*Using a simple foreach we iterate through the Rows and use the row.Attributes.Add() and pass in the javascript property we want to output as    html, along with the function we will use and then because asp.net usually dynmically creates the names for each item we need to use    the row.ClientID as this will exist only on the client side.
*/
foreach (GridViewRow row in gvClients.Rows)
{
  row.Attributes.Add(“onmouseout”, “ColorGridForMouseOut(‘” + row.ClientID + “‘);”);
  row.Attributes.Add(“onmouseover”, “ColorGridForMouseOver(‘” + row.ClientID + “‘);”);
}

//We finally just pass in the html that’s now been created.
base.Render(writer);
}

— Sample javascript

//Change Color of Gridview on MouseOut
function ColorGridForMouseOver(id) {
var el = document.getElementById(id);

if(el.currentStyle) // for msie
{
if (el.style.backgroundColor !=’orange’)
{
el.style.backgroundColor=’lightblue’;
el.style.cursor=’hand’;
}
}
else // for real browsers 😉
{
if (el.style.backgroundColor != ‘Orange’)
{
el.style.backgroundColor = ‘lightblue’;
el.style.cursor = ‘pointer’;
}
}
}

function ColorGridForMouseOut(id)
{
var el = document.getElementById(id);

if(el.currentStyle) // for msie
{
if (el.style.backgroundColor !=’orange’)
{
el.style.backgroundColor=’White’;
el.style.textDecoration=’none’;
}
}
else // for real browsers 😉
{
if (el.style.backgroundColor != ‘Orange’)
{
el.style.backgroundColor = ‘White’;
el.style.textDecoration=’none’;
}
}
}

Thank you for taking the time to visit.

Creating a Simple RSS Feed

RSS is an acronym for Really Simple Syndication and is an XML specification published by the W3C. RSS became a standardized specification around June 2000. This is meant to be a very simple primer on developing an RSS feed. Please note that this is not meant to replace a detailed book or the specification created by W3C. When I first created an RSS feed for a client the specification was the only way to learn RSS.

There are required elements to meet the specification as well as some optional. Some of the elements that are option really should be included logically.

Each RSS feed begins with a tag describing what XML specification the document meets. For example:

<?xml version=”1.0″?>

After the XML Version, we need to know which version of the RSS specification this document will meet. The rss document will also have a closing </rss> tag at the end.

So far, we have:
<?xml version=”1.0″?>
<rss version=”2.0″>
</rss>

The next tag we have is for a channel. A channel is a reverse-chronological list of links to stories that includes a title, and some sort of description.

The channel has a couple of required elements that are mostly self explanatory. The first one is a title (the name of the channel, usually just the website name), a link (to the website) and a description of the service.

So, we now have:
<?xml version=”1.0″?>
<rss version=”2.0″>
<channel>
<title>Brian R. Cline’s News Feed</title>
<link>http://www.brcline.com</link>

<description>Programming Blog for a Programmer Analyst in Niagara Falls, Ontario, Canada.</description>
</channel>
</rss>

There’s many optional elements to include within the channel, but I don’t feel that most are needed to produce a great and strictly valid RSS feed.

For example, there’s image which lets you specify a GIF,JPEG, or PNG to associate with the channel but not all RSS aggregators can show it.

The bulk of the RSS feed is created by using “items” which represent the story and usually include a title, link, and description. All elements of an item are actually optional, but you should include at least a title and description.

An item is fairly simple, here is an example:

<item>
<title>New Blog Post</title>
<link>http://www.brcline.com/blog/page?=13</link>

<description>Brian R. Cline posted about how to create an RSS feed.</description>
</item>

RSS channel’s usually include more than one item and are updated fairly regularly. I’ve included a couple of different items in the final example.

<?xml version=”1.0″?>
<rss version=”2.0″>
<channel>
<title>Brian R. Cline’s News Feed</title>
<link>http://www.brcline.com</link>

<description>Programming Blog for a Programmer Analyst in Niagara Falls, Ontario, Canada.</description>

<item>

<title>New Blog Post</title>

<link>http://www.brcline.com/blog/page?=13</link>

<description>Brian R. Cline posted about how to create an RSS feed.</description>

</item>

<item>

<title>New Blog Post – Welcome</title>

<link>http://www.brcline.com/blog/page?=1</link>

<description>Brian R. Cline posted a new blog welcoming users to the blog.</description>

</item>

<item>

<title>Blog Created</title>

<link>http://www.brcline.com/blog/ </link>

<description>Brian R. Cline adds wordpress to his website.</description>

</item>
</channel>
</rss>

Programming Excel Using Visual Basic 6

Microsoft provides the ability to programmatically created spreadsheets using Excel. The process isn’t overly complex, but the twist is that the intelisense is almost nonexistent in Visual Studio 6.0.

First we need to add a reference Microsoft Excel Object Library, on my particular Windows Computer it’s called the “Microsoft Excel 10.0 Object Library.” To be safe, we should also add the Microsoft Office Object Library; again on my particular Windows Computer it’s called “Microsoft Office 10.0 Object Library.”

We add the reference by clicking Project, and then References. Find the two object libraries mentioned and click their respective checkboxes and then click ok.

In this example, we’ll just programmatically add a couple of values to some cells, and do some basic formatting.

In the Code Window, we need to create the excel object and an excel workbook.

Dim Excl As New Excel.Application

Dim NewBook As Excel.Workbook

Dim lastRowNum as Integer ‘used to display lastRow

With Excl

Set NewBook = .Workbooks.Add

‘DisplayAlert and ScreenUpdating are two of the most useful features ‘when debugging excel, because they allow you to show excel and to hide ‘it if you don’t want the client to see if an instance of excel is running

.DisplayAlerts = False

.ScreenUpdating = False

End With

‘This next step is where we’re just going to add some data to a couple of cells

‘The format is Excel.Cells(rownumber, columnumber) . Rows and Columns ‘actually start with 1 being the first row.

With Excl

.Cells(1,1) = 5 ‘I wrote the number 5 in the first row, and first column

.Cells(1,2) = 6 ‘I wrote the number 6 in the first row, and 2nd column

.Cells(2,1) = 7 ‘I wrote the number 7 in the 2nd row, and 1st column

End With

‘Say I want to add two values using cell references

Excl.Cells(1,3). Formula = “A1+A2”

‘Let’s make the cell we just input the formula have a bold font.

‘Setting most of the front properties is as simple as selecting the cell and then ‘using .Font and finding the particular property you want to use

Excl.Cells(1,3).Font.Bold = true

‘Let’s change the Font Size to 12

Excl.Cells(1,3).Font.Size = 12

‘Saving a copy of the Excel document we have created is fairly simple

NewBook.SaveCopyAs App.Path & “test.xls”

‘Always make sure that you close the instance of Excel you opened because the ‘user will not know it is open and it can be a significant memory user.

NewBook.Close

Excl.Quit

Set NewBook = nothing

Set Excl = nothing

let me know if this was helpful!