December 22, 2004
How I learned to hate and despise Microsoft's naming convensions!
How I learned to hate and despise Microsoft's naming conventions!
(I was trying for a "How I learned to stop worrying and love the bomb" type title -- and failed)
I've gotten big into Unit Testing lately and have been working with NUnit to do so (not directly a Microsoft product), and I decided to create some unit tests for a web app I've been writing.
Test 1: see if the web server is up! Should be a simple test, just grab a file through the web server. Note: I've actually had a case or two where the server was running fine, but IIS had blown a hose loose -- couldn't ping it, couldn't restart the service, had to reboot the computer.
OK, I'm sure there is a class to do just that, no problem. I JFGI (new acronym used by one of my colleges -- Just F**king Google It) for the page. I'll try a search term like ".NET C# web winforms download".
No luck.
I try again with different parameters. No luck.
Basically, all that I keep getting are references to ASP.NET development (actually creating a webform -- not what I'm trying to do here) and .NET domain names (like .org and .com)! Basically, any page that had anything to do with web development, c#, and happened to list a web page with a .net domain root -- it got picked up! Try it, just do a search on .NET, or .NET framework.
Next try System.Web -- I thought that would be a likely location for such a class. May the force be with you on that one.
Oh ya, there were also several thousand references to the Cassini web server! -- written in C# for displaying ASP.NET pages. Kind of cool...but NOT what I as looking for!
I search Microsoft.com. No luck there either. In some ways this was even worse.
Half a day later, I finally found what I was looking for: HttpWebRequest in the System.Net namespace. Gonna have to look into that namespace some more later. But right now, I gotta get some work done. I'm a little bit behind now.
In fact, here is the code, should anyone care. You need to include the following namespaces: using System.IO;
using System.Net;
using System.Text;
private string RetrieveWebPage(string url)
{
HttpWebRequest oRequest = (HttpWebRequest)WebRequest.Create(url);
oRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse oResponse = (HttpWebResponse)oRequest.GetResponse();
Stream oStream = oResponse.GetResponseStream();
// read the stream in the encoded "utf-8" format
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader oReader = new StreamReader(oStream);
string sPage = "";
while (oReader.Peek() > -1)
sPage += oReader.ReadLine() + "\n";
return sPage;
}
December 16, 2004
Getting web page text (winforms)
Like this:
private string RetrieveWebPage(string url)
{
HttpWebRequest oRequest = (HttpWebRequest)WebRequest.Create(url);
// if you are dealing with NTLM, you will need this line
oRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse oResponse = (HttpWebResponse)oRequest.GetResponse();
Stream oStream = oResponse.GetResponseStream();
// read the stream in the encoded "utf-8" format
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader oReader = new StreamReader(oStream);
string sPage = "";
while (oReader.Peek() > -1)
{
sPage += oReader.ReadLine() + "\n";
}
return sPage;
}
December 07, 2004
New Online Book: How a computer works
http://davidguy.brinkster.net/computer/
Have fun!
December 01, 2004
November 19, 2004
ASP.NET Export To Excel
using System;
using System.Web;
using System.Data;
using System.Data.OracleClient;
using System.Data.SqlClient;
using System.Text;
using System.Configuration;
using System.IO;
using System.Web.SessionState;
namespace DiamondB.TextApp
{
/// <summary>
/// Export a SQL query to excel from ASP.NET
/// </summary>
public class ExportToExcel: IHttpHandler, IRequiresSessionState
{
public ExportToExcel()
{
//
// TODO: Add constructor logic here
//
}
#region IHttpHandler Members
/// <summary>
/// This is the main entry point. You can read about this in other places
/// from more reliable sources than me. The context object contains
/// the session, user, and other objects you are used to.
/// </summary>
public void ProcessRequest(HttpContext context)
{
string sHtml = "";
try
{
string sSQL = CreateSQLQuery();
sHtml = RenderGrid(sSQL);
}
catch(Exception ex)
{
sHtml = "<body>There was a problem executing the query.<br>"+ex.Message+"</body>";
}
// return the results to the browser
context.Response.Clear();
context.Response.ContentType = "application/vnd.ms-excel";
context.Response.Charset = "";
context.Response.Write(sHtml);
context.Response.End();
}
/// <summary>
/// DESCRIPTION: This property defines whether another HTTP handler can
/// reuse this instance of the handler.
///
/// NOTE: false is always returned since this handler is synchronous
/// and is not pooled.
/// </summary>
public bool IsReusable
{
get { return false;}
}
#endregion
/// <summary>
/// I have specialized dynamic queries that I create on the fly. That is why I have
/// the query creation routine separate. For most cases this is probably not needed.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
private string CreateSQLQuery()
{
string sQuerySQL = "SELECT * FROM SCHEMA.TABLE"
return sQuerySQL;
}
/// <summary>
/// This code takes the SQL query, executes it, pumps the data into a data grid,
/// grabs the HTML out of the grid, and returns. Simple, right!
/// Also left in this code is some of my query logging code. Every time the query
/// is run I log the query, how long it took to execute, and how many rows were returned.
/// But that is just me.
/// </summary>
private string RenderGrid(string sql)
{
// I just put this here so something is outputted.
string sHTML = "<html><body><pre>" + sql + "</pre></body></html>";
int iRows = -1;
double dSeconds = 0.0;
DateTime dtStart;
try
{
string sConn = ConfigurationSettings.AppSettings["OracleConnectionString"];
OracleConnection oConn = new OracleConnection(sConn);
OracleCommand oCmd = new OracleCommand(sql, oConn);
oConn.Open();
try
{
dtStart = DateTime.Now; // get the current time
// get the data
DataSet ds = new DataSet();
OracleDataAdapter da = new OracleDataAdapter(oCmd);
da.Fill(ds);
// check how long the query took
TimeSpan ts = DateTime.Now - dtStart;
dSeconds = ts.TotalSeconds;
// setup and load the grid.
System.Web.UI.WebControls.DataGrid oGrid = new
System.Web.UI.WebControls.DataGrid();
oGrid.HeaderStyle.BackColor = System.Drawing.Color.Silver;
oGrid.HeaderStyle.ForeColor = System.Drawing.Color.Black;
oGrid.DataSource = ds;
oGrid.DataBind();
// get the html from the grid
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHTMLWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);
oGrid.RenderControl(oHTMLWriter);
sHTML = oStringWriter.ToString();
oHTMLWriter.Close();
oStringWriter.Close();
// get the number of rows returned
iRows = ds.Tables[0].Rows.Count;
}
finally
{
oConn.Close();
}
}
catch(Exception ex)
{
sHTML += ex.Message;
}
return sHTML;
}
}
}
November 16, 2004
Got my HotMail space...
Now the question is: does it matter? I've already got a 1 gig gmail account. (and 6 invites to anyone who needs one).
Well, let the spam begin.
November 10, 2004
What extension are you
This is what I came up with...
Which File Extension are You?
November 08, 2004
My living hell
Or one version of it....
This post is a little late in coming, I should have posted it about a week or two before Halloween.
What is the problem, my Christmas decorations are already up!!! And not that they are up recently, no this happened BEFORE Halloween (or Reformation Day for those inclined).
Thank the Lord I have a fake tree, but for the love of sanity, this is to much. This has to be the only time my house has beat the Mall for Christmas decorations.
This is the type of crap that happens when your wife gets pregnant. If any of you were wondering if that whole nesting thing really happens -- IT DOES!!! No amount of progressive women’s movement for the last 100 years can change thousands of years of God-wired instinct!
What is nesting, nesting is your wife/significant female other trying to get the house ready for baby, in any way, shape, or form. This includes Christmas decorations for a baby that isn't suppose to come until May!
I think I've lost some control again.
November 03, 2004
I'm back
I did the one thing that will give any good conservative heartburn: I went to
But while there for the weekend I saw every liberal propaganda sign there was on every corner. There were people lined up around the stadium for blocks with signs. Do note: I did see one "Veterans for Bush" supporter. We tried to give him a little support as we passed.
But all said, everything went fine. I can cant say we were accosted by anyone but panhandlers (we just don’t see those in
Now that was last weekend. This is Wednesday, Nov 3, 2004. One day after the election. Kerry just conceded the vote to Bush. Daschle is gone. Republicans hold majorities in all branches of government. Hopefully they can keep tabs on Bush's spending. Because now they have no-one else to blame.
October 15, 2004
C# TO GET EDIT&CONTINUE!!!!
C# is going to get Edit and Continue -- just like VB.
http://blogs.msdn.com/somasegar/archive/2004/10/15/242853.aspx
I know a lot (few) of people are going to grumble about this, but I do think this will be a HUGE productivity gain for developers.
UPDATE: more info has been posted at http://msdn.microsoft.com/vcsharp/default.aspx?pull=/library/en-us/dnvs05/html/edit_continue.asp
October 14, 2004
The new Must Have device
Welcome the OQO
http://www.oqo.com/
It is a laptop crammed into a space slightly bigger than a palm pilot.
It runs WinXP (look for a linux hack later), has 1 gh Transmeta proc, 256 MB ram, 20 gig HD, USB port, and a docking station is available (to plug the thing into a real monitor, keyboard, and mouse -- if you have need of such things)
Comes with wireless networking and bluetooth as well.
Cost: $1,900. -- hey what did you expect.
Drawback: not enough room to fit a CD drive, and the battery only lasts 2.5 hours.
That said, I think this is the device that could be a very good PC for a lot of people. If they can get firewire and a longer battery life into it I can definatly see me buying one of these.
Here is another article on the OQO.
September 28, 2004
Flex your WIKI
The license is very open, you can basically use it however you want.
Looks like the entire site is written in C#, but I'll be looking into how to use it later.
September 25, 2004
MSN add-in
http://www.msgplus.net/
Why do I think this is the greatest thing: it allows you to change the names of your contacts.
Be-it, you could do this with Jabber for the past couple of years...but everyone I talk to is on MSN Messenger service.
Why do I want to do this: because I have 3 Jim's, 2 Chris's, an Annie (not her name), 4 email addresses, and a niece that thinks it is cute to create names that look like (|)gUrL's*JuSt*wAnT*tO*hAvE*fUn*(L)
That, for me, is short for "smack me please".
September 17, 2004
Hungarian Notation considered harmful
Overall the presentation was fine, he have a lot of good information, tips, techniques, and so on. The one part that I took issue with was where he talked about Hungarian notation. He stated that for C# programmers, Hungarian notation should not be used. His premise was:
1. C# is strongly typed already
2. Visual Studio environment gives you all of the information anyway. All you have to do is hover over the variable.
3. There was also the reason that if the variable type has to change, you then have to change the variable prefix all over the place.
Here are my argument against his.
- Delphi, C, C++, VB, Java, and many other languages are also strongly typed, but it is still considered best practice for those languages. I really like C#, but I dont believe it has done anything to make Hungarian Notation obsolete.
- Great, so now if you print out the code, how is Visual Studio going to help you. Also, why should I have to move my mouse just to figure out what type a variable is, what it's scope is when I can just look at it. If I have to take my hands off of the keyboard, you are wasting my time. Also: I'm sorry, but you should not, under any circumstances, assume that everyone reading your code will be using Visual Studio, or any other environment for that matter. With the onset of Mono, SharpDevelop, and the new Delphi environment (which supports C#) that is dangerous argument. Programmers are fickle and prone to change quickly, tomorrows Visual Studio.NET might be Emacs (or VI -- cough).
Motive 2: If I'm having trouble with a procedure I've written, I'll bring in another developer to look at that procedure. I dont want him to have to inspect the entire class just to figure out where the variables are declared. Now you are wasting the time of two developers. - Haven't any of you people heard of "Search and Replace"? It has been a standard feature for years and has become very useful to the modern programmer. Changing a variables type is not a small matter anyway. Any time you change a type you should go through every place where that variable is used and make sure that it is still going to work. Think of it this way, one of the tips that Carl gave was that when you check in your code to your source code control (Source Safe, Vault, CVS, etc), you should inspect EVERY line you changed. When you change a variable type, you have affectively changed every line that variable is used on. What better way to make sure you look over every line than to change the variable name.
I work in a large enviroment with many developers. Typically, one developer will start a project, work on it for a while, then hand it off to another developer, who has to make more changes. That second developer will have code from many other developers in his hands at once and has to be able to read it all.
Now let's be frank. C# allows developers to write some pretty sloppy code. Variables can be declared anywhere, in any form. They might be prefixed with private or public, or they might not. You can declare a exception class as IgnoreMe instead of IgnoreMeException. Curly brackets can go anywhere. C# is not a structured language. It is up to the programmers to add structure, and frankly, not using Hungarian Notation is just adding one more inconsistency variable into the mix.
To sum up: Hungarian Notation makes code easier to read and understand for other developers, removes reliance on other development environments, and up to this point, every argument I've heard of for getting rid of it has been insubstantial and petty.
If anyone cares to prove me wrong, please do.
September 14, 2004
FireFox 1.0 Released
September 13, 2004
VB: Not too advanced
Worm speaks to Windows users
Here is a quote from the bottom of the article:
"It's the only (worm) I have found speech on, but it is not too advanced because it is written in Visual Basic."
That explains just about every Visual Basic program I have ever written. :)
Visual Studio .NET Professional 2003 Special Edition
This is a new version of Visual Studio 2003 (Pro edition) with SQL Server 2000 and Windows Server 2003 bundled in. Lists for $750 (or $550 Upgrade).
The one interesting bit is that it is bundling Windows Server 2003 Developer Edition. What is the Developer Edition? I dont know. This is the first I have ever heard of it, and there aren't too many details about it.
September 10, 2004
Enter the Tivo
So I did my research and desided on the Toshiba model with the built in DVD player. I already have a DVD player, but that is besides the point. The Toshiba comes with the Tivo Basic subscription plan. That is basically Tivo light (I can only see what is going to be playing 3 days ahead), but I dont have to pay a monthly subscription plan.
The test: I get home just in time to hook the thing up and have everything ready to watch the Colts verses the Patriots yesterday. No problem, so I missed some of the pregame show and possible wardrobe malfunctions. Mid way through the game my cousin calls up asking about a computer problem he is having. NO PROBLEM! I pause the game and fix his computer. Half an hour later I'm back to watching the game.
The machine is wonderfull
The problem: I used the TV Guide feature to tell the Tivo when to record and when to shut off. Football games are notorious for not ending right at the end of the hour. So 10:30 comes around and the game still has 2 minutes to go (about 20 minutes in real time) and the Tivo stops recording. I didn't realise what was happening, so I messed the last to minutes of the game.
Luckely for me, this was not another Heidy bowl, where all the point for the game were scored in the last 2 minutes. I guess the Patriots got the ball with 2 minutes left and just sat on it. Winning the game. So all I missed was watching the Patriots run the clock out. I feel better now, but still pensive for next time (Sunday)
But for next time: I'm just telling the machine when to start and when to stop recording. For football anyway. We shall see about other programs.
September 02, 2004
Mozilla ActiveX Project
http://www.iol.ie/~locka/mozilla/mozilla.htm
I've also seen that the
Gengis project, see (a la Chris Sells) is planning to do this. But until that is done...
Lost VS.NET Context Help
I found a solution on Dr. Ex's Weblog .
From Visual Studio.NET, go to the command window (Ctrl-Alt-a).
Execute this command: View.ShowWebBrowser ms-help://MS.VSCC.2003/VSCCCommon/cm/CollectionManager.htm
Check everything and hit OK. That basically refreshes your entire help documentation for .NET!
August 31, 2004
New version of FireFox too
http://www.mozilla.org/products/firefox
This exposed me to an odd bug caused by one of the plugins I have installed. I have a plugin that saves the tabs that I have open for the next time FireFox is loaded. In a separate window of FireFox I had one of those pages open that removes the menu, toolbar, and everything else from the FireFox window. So when Firefox reloaded, it reloaded that page, also without the toolbar, menus, sidebars, etc. To fix the problem, I had to uninstall FireFox, then go to the C:\documents and Settings\username\Application Data\FireFox directory and delete just about everything (I kept the bookmarks.html file).
I haven't unloaded the plugin yet, but I'm tempted.
New version on Context
Comes with many language highlighters, file compare, and tabbed windows (sort of like Opera and FireFox). Plus you can change the colors and fonts on a per language basis.
Best of all, it is free from http://www.fixedsys.com/context
Second best: it is either written in Delphi or C++ Builder.
Anyone have a better text file editor?
August 18, 2004
The Internet is down!!!
The worst part is I dont know if I can blame QWest, my DSL modem, or my hub. But if I reboot the hub, all the problems go away.
So I blame the ice cream man truck that runs through my neighbor hood playing "Are your ears too long" WAY too loud.
August 16, 2004
MSDN TOC Update
Now I use the MSDN libraries several times a week, I rairly find it usefull. That isn't because the TOC is bad, but the entire concept of using the TOC to find one document in amongst 3 million just doesn't work.
Once I find a document that is close, then I will sometimes use the TOC find related docs. But from experience, I know that one article by Dino Espisoto will have nothing to do with another articlue by Dino. Unless I'm just looking for interesting reading material.
Part of this has to do with what I'm looking for on MSDN. Typically I'm either looking for documentation on an API, or for the latest article. Now the RSS feed from MSDN does a good job of the latter, and the Search engine on MSDN does a bad job of the former. One search in 5 will return relavent information. From what I've heard from my developer friends, that is normal.
So please, make the search better (and for the record, I've heard Microsoft is), and make the TOC better. I hope it is more usefull that it has been, but I doubt it.
------------------------------------------------------
Since I'm on this topic (griping about MSDN), there is one other improvement I would like to see. Wiki'ize MSDN. Check out www.wikipedia.com if you dont know what I'm talking about.
Basically, allow users, like my self, help update the MSDN documentation. Maybe not all of it, but users should be able to send in small amount of sample code for an API, or give an alternate explanation of a function, give warnings about bugs, etc.
Between a better search engine and wiki, MSDN could be one of the most powerfull documenation centers on the web.
August 13, 2004
First Post
At least I can say that I got the first post on my own blog. Slashdot be darned to heck.