ShowUsYour<Blog>

Irregular expressions regularly

February 2004 - Posts

FindStr.exe an egrep-like tool

I've long thought of writing a little tool like grep (or egrep) which would allow me to quickly use regex to search for text within files. This weekend while reading an article about Standard I/O and Console Applications I discovered the Windows command-line tool FindStr.

FindStr.exe is a command-line tool which searches for patterns of text in files using regular expressions. Let's say I've got a folder full of documents and I want to search through and find any instance of the pattern "WebService" I can fire up a Command Prompt, change the path to my where my folder is and use FindStr.exe to perform the search:

cd c:\MyFolder
findstr /s /i WebService *.*

 

This displays a list of all lines in all files in which the search term was found. Another neat trick is that you can use the greater than operator - ">" - to redirect the results to a text file, like so:

cd c:\MyFolder
findstr /s /i WebService *.* >Results.txt

 

This redirects all results to a file named Results.txt. So there it is, an egrep-like utility already which is already baked into Windows OS - I never knew that!

Cross posted on http://weblogs.asp.net/DNeimke and http://blogs.regexadvice.com/DNeimke

Posted: Feb 29 2004, 05:46 PM by digory | with 14 comment(s)
Filed under: ,
Some new stuff I learnt about the Console

It's amazing how often related events seem to occur close to one another. Often I'll be working on a project and I'll need some code to do something I've never done before ( for example, writing an Ftp client ) and on the same day someone will post some cool code which does exactly what I need, or I'll stumble upon an article which does. It happened again this weekend.

First, Steve Smith posted a link on the C# list to an article about Standard I/O and Console Applications. This article was really, really cool. I never knew about any of that stuff - such as standard input/output and how cmd.exe allows you to pipe commands and redirecting standard output to a text file like so:

    C:\ dir >listoffiles.txt

 

So, within 20 minutes of reading that fine article I stumbled across this blog entry by Justin Rogers:

    Using piped output redirection on the Process/ProcessStartInfo classes...

Very neat!

Posted: Feb 29 2004, 05:25 PM by digory | with no comments
Filed under: ,
TDD - not yet infected

One of my major goals for this year was to improve the quality and efficiency of executing projects and tasks.  A significant part of this is intended to come about from the adoption of better practices... “habits“ if you like.  I started the year by trying Pair Programming and this week I've started to pay attention to Test Driven Development (TDD) for the first time.

I've been reading a TDD book and doing tutorials on my laptop on my way to and from work in the mornings this week.

For a methodology which has received so much hype and praise from well-known and respected people within the industry I must say that I'm still pretty flat on the idea.  It's not that I'm cynical - I'm not!  I would desperately love to discover that TDD is a missing cure; I'm so ready to be captivated by it and embrace it as a bold new way forward.  But, I'm finding that I really am not seeing significant benefits in what I've read to date.  I think that this may be because the author is doing such a mediocre job of selling the real winning points of TDD... alas, I shall have to wait until I've finished this book (at least) before I can hope to form any standalone opinions of my own.

Seattle here I come...
I booked my flights for the April MVP Conference in Seattle.  I'll be arriving in on Sat. 3rd and flying out the following Saturday afternoon - 10th.  I'm looking forward to my first MVP conference and also to catch up with many of the guys and gals that I met last year when I was over there.
Posted: Feb 26 2004, 09:57 PM by digory | with 5 comment(s)
Filed under:
New ContextMenu release - includes a working demo

The latest build of ContextMenu is now available on GotDotNet.com via this link:

    Get the code here

This download includes:

   - full support for Mozilla, IE and Opera
   - Working demo showing how to handle postbacks either client-side or server-side.

Posted: Feb 26 2004, 09:53 PM by digory | with no comments
Filed under: ,
New ContextMenu tutorials

I've added a 2 ContextMenu tutorials to my website:

VS.NET (using C# in codebehind)
http://www.flws.com.au/ContextMenu/VisualStudioTutorial.html

WebMatrix (using VB.NET for server-side code)
http://www.flws.com.au/ContextMenu/WebmatrixTutorial.html

Both tutorials come with a working downloadable project.

Posted: Feb 24 2004, 09:44 PM by digory | with 4 comment(s)
Filed under: ,
ContextMenu now supports Mozilla and Opera

I finished-off the changes required to make ContextMenu run in multiple-browsers and will be uploading the latest version of the control to GotDotNet tonight, so it should be available for download in 2-3 days - I'll blog a message when the new code is up and ready for download. So far I've tested it in:

  • Internet Explorer 6
  • Mozilla 0.7
  • Opera 7.11

There's a demo page for ContextMenu which you can use to test the menu on your own browser; I'd appreciate any feedback via my contact form if you encounter bugs, etc.

    View ContextMenu Demo

It was certainly interesting making the changes to support all 3 browsers and I walked away thinking to myself that XBrowser scripting is no where near as difficult as it used to be now that the major browsers all support such rich functionality and support so many of the same standards and such.


Here is a description of some of the major changes that I had to make to my initial code to get it working in all 3:

Couldn't use attributes to store arbitrary pieces of information:

In my original control I was storing the LinkCommandArgument data as an attribute of the ANCHOR like so:

    a commandArgument="1" href="javascript:void(0);" ...


Neither Opera nor Mozilla seemed to enjoy that because when I tried to reference that property like so:

    // clickedItem is an object reference to the ANCHOR element and the commandArgument
    // reference off of that refers to the arbitrary attribute
    var args = new MenuItemClickedEventArgs( clickedItem.commandArgument ) ;


... 'undefined' was returned.

Positioning logic was incorrect:

The PositionCanvass method was using posLeft and posTop to move the layers around. Opera and Mozilla didn't seem to like that so I've changed over to just using "left" and "top":

    this.Canvass.style.left = this.x ;
    this.Canvass.style.top = this.y ;


Slight Css alteration:

The Css for mozilla had to be changed so that I could get a thin black border around the outside of ContextMenu:

From
    border: 1 black solid ;


To
    border-width: 1px 1px 1px 1px;
    border-style: solid;
    border-color: black black black black;


There were also some miscellaneous errors which Internet Explorer had overlooked which had to be fixed - such as an extra comma which I had inserted into the jagged data arrays.

Oh you old fox you!

heh... it's been a while since I did any cross-browser scripting so, today I settled in for a solid session of pedantry.  Much was my surprise when I did a view-source on the first page I visited on the Mozilla site and found this comment for all to see:

      Note to Editors of this Document!
      
      I have meticulously repaired the indentation here. DO NOT OPEN THIS
      DOCUMENT IN A WYSIWYG EDITOR OR (in the words of Robert DeNiro) I 
      WILL BRING YOU DOWN! I WILL BRING YOU DOWN TO CHINATOWN!
      
      -Ben

http://www.mozilla.org/products/firefox/releases/

You tell 'em Ben! :-)

 

Posted: Feb 21 2004, 01:28 PM by digory | with 2 comment(s)
Filed under:
Adding cross-browser support for ContextMenu

This weekend I have to get the ContextMenu working in Opera and Mozilla browsers. This shouldn't be too hard as I've stuck close to the spec. on everything and already have a browser sniffer built in to the js code. I've already taken the precautions of separating the 4 main XBrowser fragile parts out into their own logic units:

  • Rendering
  • Layer creation
  • Positioning
  • Visibility

So, in my quest to master these browsers I've managed to uncover the javascript/dom support documentation for each of these browsers:

Opera
Supported Features and Specifications : http://www.opera.com/support/service/features/index.dml
Web specifications supported in Opera 7 : http://www.opera.com/docs/specs/ (contains a list of the DOM objects at the bottom of the page)

Mozilla
Scripting References : http://www.mozilla.org/docs/web-developer/#scripting

Internet Explorer
MS DHTML Reference : http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/dhtml.asp

Lie Loudest

One of my favourite quotes is this:

    We lie loudest when we lie to ourselves

... and I think that this quote can be readily applied when evaluating one's own career. An ambiguous statement perhaps but, let me attempt to drill in a little. I'm basically a guy who is motivated by food and shelter so, for me at least, there's 2 factors that I try to focus on when I think about my career:

  • What skills will I need to be doing the job that I'd like to be doing 7 years from now
  • What positives am I getting out of my current job which will help me attain item #1

Now, if I'm being honest - truly honest that is - with myself, I must accept that, logically, to answer point #2 I must have already answered point #1.

When answering point #1 I try to place skills into fairly high-level baskets like:

  • Managing staff
  • Managing resources
  • Manging budgets
  • Managing projects
  • Designing frameworks and architecture
  • Lower level coding

So, in my own case I already know that, there are certain things that I need to be learning today which will help me to get to where I want to be tomorrow. I know that I need exposure to managing things; I need exposure to different kinds of and different styles of architecture; and I also need exposure to solving some moderately hard problems. Now that I know more about what I need, I can start to look at how to go about getting it.

In my case, I believe that I should be getting 60+% of this goodness from my current job. That is, for me to be happy, my job will need to fulfill at least 60% of the things that I need to be doing today to get to where I want to go - otherwise, I'll just have to work too hard.

What if I feel that I'm getting < 60%?

If I'm getting < 60% then, I have to ask myself this... am I making the most of my opportunities to exert my skills and influence here? If the answer is "no" then I'd need to do a whole lot of planning around how to map my existing talents to the needs of my employer. If the answer is "yes" then, my entire focus would be on getting my CV in the best possible position to sell myself to my new employer :-)

But, when doing the math, make sure you remember the quote:

    We lie loudest when we lie to ourselves

More Posts Next page »