... all I'm offering is the truth. Nothing more. RSS 2.0
# Friday, October 26, 2007

I have doing a little too much work with legacy code (Visual Basic 6) recently, I was actually a better than good VB6 developer at one point but suddenly my mind cannot get around the fact that Strings in VB6 just simply do not have all the trappings (.Length, .Trim, .Remove, .Split etc) of their C# equivalents.

Anyway, I was tackling an issue that required me to remove all the unprintable characters (specifically the ASCII range 0-31) from a string in VB6 and this is what I came up with:

Dim lIndex as Integer
Dim sParseThis as String

sParse = GetDataWithWierdCharacters

For lIndex = 0 to 31
     sParse = Replace(sParse, Chr(lIndex), "")
Next

When I started thinking about this code in terms of C# my immediate desire was to make sure I am taking advantage of the glorious spackle that is the .NET Framework. Simply put I did not want to copy the above code, line for line in C#. So I thought I could take advantage of regular expressions.

string sParse;
sParse = GetDataWithWierdCharacters();
sParse = Regex.Replace(sParse, "[\x01-\x1F]", "");

Much better!

Friday, October 26, 2007 8:30:14 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] - Trackback
C# | Programming | Visual Basic
# Thursday, October 11, 2007

My brain seems to be freezing on DB related situations, any way I forgot how to check for the existence of a stored procedure before dropping it. I will be able to find the information quickly now!

IF EXISTS (select * from syscomments where id = object_id ('dbo.SPROC_NAME'))
BEGIN    
    DROP PROCEDURE dbo.SPROC_NAME
END

Technorati tags: ,
Thursday, October 11, 2007 8:27:03 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] - Trackback
Sql
# Monday, October 08, 2007

I had been saving this blog for a while gathering information on additional plug-ins, however, with the release of the source code of the .NET framework this article has lost some of its impetus but...

Lutz Roeder Reflector has been on the grid for some time that allows us to view code associated with any assembly (.NET Framework and your own). Now to be specific this is not the source code but it does represent the developer intent. With Reflector you are able to view the complete System tree and review examples of the code that went into making the Framework tick.

image 

Reflector is extensible and there are a series of plug-ins, developed by the community, that can be used in conjunction with it. The plug-in I am getting the most mileage out of is Assembly dif. Which allows me to to compare changes I have made to my source code head to head.

Just as an example of how Reflector interprets your source code, I wrote the following code. As you can see "x= i + x;" line is quite separate to the "MessageBox.Show line".

image 

When reflector sees this code it interprets the IL and shows this, we still have the for loop but the addition of i and x now occurs on the same line as the "MessageBox.Show". This kind of changes are common I have seen for loops become while loops and other benign changes.

image

This is for me the real reason why the release of the .NET framework source is so important. I no longer will have a interpretation of the System source code, I will have the real thing! Symbol files, source code, basically the full F11 support! Cannot wait to jump in!

Monday, October 08, 2007 8:26:24 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] - Trackback
Tools
# Wednesday, October 03, 2007

I am anticipating the new Zune firmware update will be here round about the same time that Zune 2 hardware begins to ship (November 13th). I found this video on YouTube showing off some of the features. For me the most exciting thing is the video offerings in the revamped Marketplace as well as the support for Podcast's.

The fact that I can get this update on a generation 1 Zune is huge for me, I may have jumped to the iPod ship if that were not the case!

Technorati tags:
Wednesday, October 03, 2007 8:25:53 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] - Trackback
Zune
# Monday, October 01, 2007

John Lech Johansen is a genius, as one of the more infamous hardware hackers in Europe (he may be State side now) he has been responsible for some of the major hacks in recent memory (specifically DVD encryption). So his comments on the effects of Apples recent update on his how famous iPhone hack (which you can use with any carrier) are ... interesting.

I was expecting that the iPhone firmware update would simply relock unlocked iPhones so that they could only be used with AT&T. I was wrong. As you may know by now, after an unlocked iPhone has been upgraded with the 1.1.1 firmware it will refuse to activate with any SIM. The technical evidence so far indicates that this was intentional by Apple. Although the iPhone is still alive, it’s completely useless. It’s essentially a brick.

Has Nokia or Sony Ericsson ever bricked or refused service on an unlocked phone? Not that I’ve heard of, and if they did, they would have been quickly sued in several countries where consumer rights are more strongly protected.

Did Sony ever brick PSPs over homebrew software? Did Microsoft ever overwrite someone’s BIOS with garbage because they detected an illegitimate Windows installation?

In light of other things Apple has done lately, such as adding an encrypted hash to the iPod database to lock out non-Apple software and disabling TV-out on the iPod unless the 3rd party accessory you’re using has an Apple authentication chip, it’s evident that Apple is well on its way to become one of the most consumer hostile tech companies.

Technorati tags: , ,
Monday, October 01, 2007 5:54:15 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] - Trackback
Electronics
# Sunday, September 30, 2007
Classic ASP is still one of those old realities I have to deal with, and I found myself struggling with this snippet of code I found on MSDN. I installed the asp file (file.asp) into the root of an asp based web server and it simply would not work. File.asp was simply designed to display a page by insert the image as a binary stream into the http header.
<%@ Language=VBScript %>
<%
Response.ContentType = "image/jpeg"
Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
' Point to an image file with adequate access permissions granted
objHTTP.open "GET", "https://" & Request.ServerVariables("SERVER_ADDRESS") & "/any/someimage.gif",false
objHTTP.send
Response.BinaryWrite objHTTP.ResponseBody
Set objHTTP = Nothing
%>
Let me set the background, I was accessing the address of the server using https, and the certificate was valid and I was accessing it using the name on the cert (e.g https:\\mysite.com).
The problem with the above situation was that the server variable defined by Request.ServerVariables("SERVER_ADDRESS") was giving me back a valid ip address it just did not match the name in the certificate!
I updated the server variable to Request.ServerVariables("SERVER_NAME") and bingo!! SERVER_NAME is designed to invoke the name of the server, specifically, the official name that the cert uses. Pretty much everything else in an ASP web site will work even when the cert does not match. Binary streaming, however, is extremely sensitive to any security snafu.
I have included a partial list of the Request.ServerVariables for future reference:
ServerVariables Sample
("APPL_PHYSICAL_PATH") D:\var\web
("LOCAL_ADDR") 123.22.23.113
("PATH_INFO") /test/examples/mystuff.asp
("REMOTE_ADDR") 92.21.8.6
("REMOTE_HOST")  92.21.8.6
("REQUEST_METHOD") GET
("SCRIPT_NAME") /test/examples/mystuff.asp
("SERVER_NAME") mytest.com
("SERVER_PORT") 80
("SERVER_PROTOCOL") HTTP/1.1
("URL") /test/examples/mystuff.asp
("HTTP_ACCEPT_LANGUAGE")  en-us
("HTTP_CONNECTION")  Keep-Alive
("HTTP_HOST")  mytest.com
("HTTP_USER_AGENT") Mozilla/4.0 (compatible; MSIE 7.0; Windows T 5.1; Mozilla/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)
("HTTP_UA_CPU") x86
("SERVER_SOFTWARE") Microsoft-IIS/5.0
("HTTP_ACCEPT_ENCODING") gzip, deflate

Sunday, September 30, 2007 8:21:41 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] - Trackback
Classic ASP
Blogroll
Statistics
Total Posts: 330
This Year: 18
This Month: 2
This Week: 0
Comments: 30
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Mark Downie
Sign In
All Content © 2010, Mark Downie
DasBlog theme 'Business' created by Christoph De Baene (delarou)