Kenny's Two Pennies

...and that's just about what it's worth
  Home |  Contact |   |  Login

Saturday, October 17, 2009

Pet Peeves: Shoddy Journalism and Shoddy Politics

Yes, it is hard to believe, but I have pet peeves. This article kills two of my pets with one stone...

I found a reference to this article (GPS Causing Truckers to Crash into Bridges) this morning. The title made me curious, becase it made no sense. How can radios tuned to satellite signals cause truckers to crash into bridges? So I read the story. Yep, the headline is inaccurate, if not downright slanderous. It insinnuates that GPS is at fault.

A more accurate description is that some truckers are following the recommendations of some certain software that uses GPS and a streets database to help route travellers to a desired destination and, as a result, are taking routes that are not meant for truckers. Then the truckers end up hitting the bottom of bridges that do not have clearance for their trucks. So the line of effect is trucker -> GPS-consuming-software -> GPS. The trucker is at fault here. The headline has it backwards, blaming GPS for the mishaps of truckers.

Why do I care? Why am I jumping to the side of GPS? Do I have some need to defend the GPS system? No!!! I don't care about that part. It is the media that has me riled up. The media has power to influence people's opinions. And when the media is being manipulative, someone needs to call them out.

Ok, in this case, I don't think the media (specifically, in this case, Fox News) is purposefully being manipulative with this headline / article. Well, actually maybe. The headline is meant to get you to read the article. This headline borders on the sensational. It manipulated me into reading the article, only to find that the headline is not true. So I'm crying foul.

On to my next pet peeve: knee-jerk politics and resultant bad laws.

The article states that Governor David Paterson of New York wants a new law that punishes truckers for using mapping software that is not meant specifically for truckers. Now, I admit that truckers who rely on software meant for automobiles are taking risks. But the result of the risk-gone-bad is that the trucker is illegally travelling on a restricted road. And that law already exists. Why is there a need for an additional law?

To me it is a bad law because it is meant to charge the offender twice for the same crime. They already broke the law when they were on the restricted road. They already broke the law when they crashed into the bridge. Now the governor wants to charge the offender for taking bad advice. Oh, and I'm not blaming the software for giving bad advice. The advice being given by the software is perfectly fine for certain audiences. But the act of taking bad advice should not be the crime. The crime occurs when the existing laws are broken.

The article says:

"The bill would increase penalties for illegally using parkways and require all large commercial trucks to use GPS devices that route them away from restricted roads. It would also stick trucking companies or their insurance carriers with the bill for repairs and cleanup after bridge strikes."

I'm ok with the bill as described, except for the part that requires the use of certain GPS devices. The commercial truck industry should be smart enough to take their own steps to avoid travelling in restricted areas.

And that's my two pennies' worth.

posted @ Saturday, October 17, 2009 8:48 AM | Feedback (0) |

Thursday, June 25, 2009

.Net COM object and app.config continued...

Well, I found that my previous post doesn't really work. I spent more time and learned the following:

  • I can't easily change the location of the app.config file. The way to do it involves setting up a new AppDomain.
  • The app.config file lives in the directory with the base executable. In the case of a COM object called from within a classic ASP page, this is the directory where w3wp.exe resides. On my computer (running 64-bit Vista), the directory is at C:\Windows\SysWOW64\inetsrv. So I created a w3wp.exe.config in that directory and voila!

That solves the problem of the config file.

My next issue was that I had to call code that wanted to get other file information from the operating directory.

By "operating directory", the code I was calling was using AppDomain.CurrentDomain.BaseDirectory

This gave me a problem, because when running under IIS, I didn't have permissions to scan a directory in c:\Windows. I couldn't even give permissions to the directory, I got an error dialog.

My solution was to change the "operating directory" to the location of the COM dll. To do this, I used the following:

Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", string.Empty)

Since I had directory scanning rights on that directory, it worked -- I can now call a COM object that in turn uses nHibernate to read data from a database.

Whew! 

posted @ Thursday, June 25, 2009 12:25 AM | Feedback (0) |

Wednesday, June 10, 2009

.Net COM object and App.config

I wrote a COM object in c# (a class library that is registered for COM interop), which compiles to a .dll.

I wanted the object to be able to read items from an app.config file (e.g. PmsInterfaceComObject.dll.config). Trouble is, COM interop dll files seem to be hosted by an Application Pool, or other type of .Net executable. Because of this, the configuration provider wants to use the host .Net executable's config file for settings. Not the COM dll's config file.

This is a known issue, this article describes the situation nicely.

I found a way to override the location of the config file at this site. I added some of my own code to discover the location of the running .dll. Here is the result:

AppConfigFilePath = Path
.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase)
.Replace("file:\\", string.Empty)
+ "\\" + Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase) + ".config";

// Force the location of my App.Config file:
  AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", AppConfigFilePath);

Nice, huh?

posted @ Wednesday, June 10, 2009 10:49 PM | Feedback (0) |

Why does is have to be so hard? (Part deux)

Here is another problem/solution:

I moved my COM object (see my previous article) to my client's server. My test classic-asp page failed when trying to do a CreateObject on the COM object. No explanation. No Event Log entry. No nothing. Just a HTTP error 500. Grrr.

I got a little bit more of a clue when I created a .vbs script that did the CreateObject, and ran it using cscript.exe. I got an error message "The system cannot find the file specified". Well, my COM object opens a config file, so I went down that route, with dead ends.

I did a registry search for my COM object.method, and found entries, but no path to where the dll actually lives. I even was able to delete my COM  .dll and got the same error. Hmmm, that's a clue.

A couple of Google searches later, I found my answer. I have to register my COM object (written in c#) using regasm *and* use the /CODEBASE argument, which causes the location of the COM .dll to be noted in the registry.  DOH!!!

I did that, and now it works.

Now, had I only been told that the error was coming from the .Net run-time, and that it was not finding the COM object dll, and maybe even a hint saying that /CODEBASE may be necessary if the assembly is not in the GAC, then my life would have been soooo much easier. Instead I just wasted a coupla more hours.

Seems I am on a rampage against terse (or none at all) error messages. Come on, people (Microsoft)!!!! It's 2009! Don't make my life as a software developer so dang hard!

 

posted @ Wednesday, June 10, 2009 8:24 PM | Feedback (0) |

Saturday, May 16, 2009

Why does it have to be so hard?

I just spent a whole day trying to figure out why I was getting the infamous "ActiveX component can't create object" error. Grrrrrr.

I wrote an COM object in c#. I followed all of the rules. I was able to late-bind to it and use it in vb6. It is a really simple COM object with just one method that returns the string "yep". I plan on getting more fancy with it later.

I figured since VB6 worked, I could access it from a classic ASP page.  Wrong.

Well, first, I have a 64-bit laptop running Vista. No, I'm not going to bash Vista. I actually don't mind it at all. Except the 64-bit part -- seems I'm always having to make adjustments because of something I happen to be doing in 32-bit mode. The fact is, the majority of code out there is still 32-bit.

Here is how my easter-egg hunt went:

  1. Write the COM object. That was a piece of cake.
  2. Write a a classic ASP page to call the COM object. Another piece of cake.
  3. Run the ASP page. Oops. Can't do that within Visual Studio 2008. Cassini doesn't do classic ASP
  4. Found out that Vista Home Premium has IIS, but you have to install it. Well, ok. done.
  5. Why does Microsoft have to keep rearranging the furniture. The IIS 7 UI is way different that IIS 6.
  6. Finally got to run my asp page. Got the ActiveX component can't create object error.
  7. Why Microsoft can't give more details than that completely amazes me. Found numerous google results of people with this problem, and responses of "try this", "try that". Well, I would know EXACTLY what to try if I know specifically what the dang problem is.
  8. Is my COM object ok? Wrote a VB6 app to instantiate and use it. No problem.
  9. Is it an IIS problem? Wrote a .vbs script, it also gets the error. Interesting.
  10. Went thru many detours. Including downloading and installing Microsoft's Debugging Tools For Windows. That looks interesting, if I only knew how to use it.
  11. Found this link. Interesting! The cscript utility has a syswow64 compatibility version. That worked! Am I on to something?
  12. Went into IIS, DefaultAppPool, changed advanced-option "Enable 32-bit applications" to true. Still no go. Actually it turns out that this is a necessary step, but not the only one. Again, WHY couldn't the error message say that the problem had to do with running the app in 64-bit mode? Huh? Huh? And WHY was it defaulted to false? When most apps are still 32-bit?
  13. Went back into IIS, DefaultAppPool, changed "Identity" from NetworkService to LocalSystem. WOOHOO! it worked. It was a permissions problem. Nice to know. Couldn't Microsoft tell me that in the first place?

Bottom line: Persistence pays off, but at the expense of hair loss.

And: Informative error messages would be nice. Not these terse, cryptic, useless ones like "ActiveX component can't create object". Come-on -- can't the largest operating system company in the world do better than that?

posted @ Saturday, May 16, 2009 2:34 PM | Feedback (0) |

Saturday, July 05, 2008

My first Silverlight App

Here is my first published Silverlight App: http://sudoku.kenhales.com.  It solves Sudoku puzzles. It isn't a finished product by a long shot.  Here is my take on Silverlight so far:

  • It is better than ASP.NET by quite a ways, but there is going to a learning curve I still need to get past.
  • I think I will be doing a lot more line-of-business work in Silverlight, including an inventory module for my company's Field Service system (at http://poolcarepro.com).
  • I hope it becomes a popular dev and execution environment -- I do not want to end up with legacy code that is out of the mainstream -- like Delphi or PowerBuilder.
  • I love c#, and definitely relish the idea of providing a rich user experience over a browser, but without having to use JavaScript.

My plans for this Sudoku solver program include:

  • Provide a better way of entering values.  I am thinking some kind of specialized combo box.  One that has an animation to expand a pop-up to show a 3x3 grid of the numbers 1-9, plus a 'clear' button.
  • Ability to save and load existing puzzles.
  • Experiement with Expression Blend (I simply did bare-bones XAML on this so far) to give it more pizzaz.

If anyone has any comments or suggestions, I'm all ears.

posted @ Saturday, July 05, 2008 9:45 AM | Feedback (0) |

Saturday, September 29, 2007

Regex problem / solution

My brother gave me a list of zip codes and their cities.  I needed this list to construct a query that gives revenue information by city, given a couple of tables -- one with account numbers and their zip code, and another with account numbers and revenue.

The revenue information query was easy.  The harder part was getting the danged list of zip codes / city pairs into a table.

Here is what I had to work with:

91605 Los Angeles
91606 Los Angeles
91607 Los Angeles
91630 Thousand Oaks
93115 Fillmore
93552 Palmdale
(etc)

There were only about 60 lines of this stuff, and I figured the easy way would be paste the list into SQL Server's Management Studio query window, do a search and replace to convert the list into a bunch of INSERT statments, and then execute, to actually insert the pairs into a table I already had in place.

Piece o' cake, huh?

I thought I had regular expressions down.  Turns out I pretty much did, but it was the replace string that kicked my butt.  Here was my matching string:

^{[0-9]+}:b+{.*}

It basically says, from the start of a line, match up a string of 1 or more digits and "tag" them for replacement.  Then expect 1 or more spaces or tabs, and then a string of character up to the end of the line.  Tag the string of characters as well.

And here is the replacement string:

insert into zipcities(zipcode, city) values('\1', '\2')

This creates a list of my "insert" commands.  the \1 substitutes the first "tagged" data (the 1 or more digits), and the \2 does the same with the city names.

Here is the result:

insert into zipcities(zipcode, city) values('91606', 'Los Angeles')
insert into zipcities(zipcode, city) values('91605', 'Los Angeles')
insert into zipcities(zipcode, city) values('91607', 'Los Angeles')
insert into zipcities(zipcode, city) values('91630', 'Thousand Oaks')
insert into zipcities(zipcode, city) values('93115', 'Fillmore')
insert into zipcities(zipcode, city) values('93552', 'Palmdale')

Nifty, huh?

The part that kicked my butt?  I naturally assumed that the replacement string followed regular expression rules (the parentheses needed to be escaped with a leading '\' character).  Turns out the replacement string does  not use any regular expression syntax at all.  It just uses the \1, \2, etc. for repacements.  I think this replacement syntax is not universal -- Management Studio does it this way but other engines may use another replacement syntax.  I'm not sure about that though.

There, I have documented this for future reference!

posted @ Saturday, September 29, 2007 9:42 AM | Feedback (0) |

Quote of the day...

So you've got a problem, and you want to use Regular Expressions to solve it. Now you've got two problems.

posted @ Saturday, September 29, 2007 9:02 AM | Feedback (0) |

Monday, September 24, 2007

Forever Seeking Software Architecture Nirvana

I consider myself a pretty experienced software developer -- I have been at it for over 30 years.

All along the way, I have found myself encountering new products and tools, and new ways of organizing code.  One of the (neat) aspects of software development is that there is always something new to learn.

And so now I find myself again immersing myself into new concepts that I had not been familiar with before.  Funny thing is, some of these concepts are not new.  They have been around since I first started programming.  Oh how I wish I had paid more attention to the PARC people!

My latest topics are these:

Throw in some data access stuff (LINQ and NHibernate), and I have a lot to think about.  I'll post some of my thinking on all this later.

btw I'm listening to Tom Harrell's new album "Light On".  Over and over.

posted @ Monday, September 24, 2007 5:33 PM | Feedback (1) |

Sunday, July 15, 2007

A whole new level...

After upgrading from the old .Text blog engine to its replacement SubText, I contacted Kent Chen to see if he planned on upgrading his .Text skin files.  He was unaware of SubText as well, and after switching to it, he sent me the upgraded skin.  Thanks Kent!

SmartCarOnSteroids

On Kent's blog he mentioned Live Writer, which I hadn't heard of before.  I downloaded and installed it, and, wow!  Now creating posts is a lot easier.

Plus, now I can insert pictures.  And wrap text to the side of it.  No, the car isn't mine.  I don't even wish it was.  I just found the picture to be screaming for a snide remark.  Like, who says you can't have fun while saving the planet by driving a Smart Car?

posted @ Sunday, July 15, 2007 9:20 AM | Feedback (0) |