Archive for the 'Old Blog' Category

04JanA good url regular expression ?

I have been looking for a good first layer of validating an url to see if it is valid.

For checking the format of the url it seems to me to be the most logical approach to use regular expressions. Up until now I always discarded them as being to “geeky”, meaning i don’t consider it my life’s biggest goal to be typing (/?[]\w) all day long (so why did i become a programmer, aaaah yes to make life easier for other people)

Anyway.. to find a good regular expression to that validates urls not url domains. One that doesn’t allow spaces in the domainname and where the domain can be suffixed with the port number.  Also I need support for the ~/ paths

This is what I came up with.. if somebody as a better idea… or finds a mistake please let me know.. Always happy to learn something new.

^(((ht|f)tps?\:\/\/)|~/|/)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5})(:[\d]{1,5})?)/?(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?

I was a bit quickly in using this regex. Simeon pilgrim indicated that the ftp urls won’t validate when you add a username and a password. 

I don’t really need to validate ftp so I should have removed the ftp protocol from the list of choices.  I need this just to validate urls for weblinks and the link element in an rss feed.  When I need them for ftp I will post the ftp version.. but for now I don’t have time to spend on elaborating the regex.

Anyway here is the right one : ^(http(s?)\:\/\/|~/|/)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?/?(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?

A full url validation would include resolving names through dns or making a webrequest to the provided url to see if we get a 200 response. The only way to be sure is to test if it is there in my opinion.

Thanks Simeon.

And for those who really want the ftp validation : ^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?/?(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?

I am not sure about numbers in the username but I believe you can have a username of numbers alone.

Comments don’t seem to work on this blog engine.. so just send me a mail through the contact form. thanks

Two days later …

I discovered there is still a problem with my regular expressions… folders don’t get parsed.
I’ve solved the path issue, so now it should be finding all url’s

Expression:
^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?

Should parse the url below
http://hh-1hallo.msn.blabla.com:80800/test/test/test.aspx?dd=dd&id=dki

But not :
http://hh-1hallo. msn.blablabla.com:80800/test/test.aspx?dd=dd&id=dki

 

04JanValidation of viewstate failed.

This happens when you want to enable your security to encrypt your password and enable password retrieval.

If you set your own machinekey.

My fix was in the web.config :

<

pages enableViewStateMac=true viewStateEncryptionMode=Always>pages>

<

membership defaultProvider=SqlMembershipProvider hashAlgorithmType=SHA1>
    <
providers>
   providers>
membership>

<

machineKey validation=SHA1 validationKey=8EF2706A98DAB8DFD9DED53180A02BD172A45586AACD63500D5290CF44BACCC1697F402AE0F5D734940BD19BB98A6EBBE788E943B7293E6356B25B00DF2891FB,IsolateApps decryption=AES decryptionKey=8F103358F65FD53132A2856C8BAC9273AA92493D5570945EC74C5856B626BB66,IsolateApps/>

04JanWebresource.axd. How do I use it ???

Ever since I got my hands on .NET 2.0 I noticed the handler webresource.axd which seemed to provide a similar function as what I was using handlers for. 

I used handlers in .NET 1.1 and before today also in .NET 2.0 to handle my javascript and css that I need in controls I developped.
I mark them before compiling as embedded resource and then later on read them out via reflection and they get served up by the browser.

I probably don’t have to explain that (as long as your parameters don’t change) this scripts get cached by the browser so they will only be downloaded once and re-used afterwards.

Well in asp.NET 2.0 there is a feature that uses webresource.axd to handle all kinds of embedded resources (images, pages, etc…)

Nikhil Kothari has a post on how to use them in his blog, and I just copy pasted the text below.

Using Web Resources
Imagine I am writing an HtmlEditor control and I want to use a stock bold button icon. Here’s what I’d do:

  1. Embed “Bold.gif” as a resource with the same name into my control’s assembly.
  2. Mark it as Web-accessible via the attribute:
        [assembly: WebResource("Bold.gif", ContentType.ImageGif)]
  3. Use the GetWebResourceUrl() method on Page to get a URL that can be rendered out to the client.
        boldButton.ImageUrl = Page.GetWebResourceUrl(typeof(HtmlEditor), "Bold.gif");

This results in a URL of the form:
    WebResource.axd?a=MyControls&r=Bold.gif&t=632059604175183419

04JanA clear explanation of generics in c# 2.0

http://www.ondotnet.com/pub/a/dotnet/2004/05/17/liberty.html?page=2

04JanMS Antispyware doesn’t do its job

I had a discussion with my friend Miel (Coolz0r) about spyware and their scanners for it. 6 months ago I did a test of several anti-spyware programs and MS antispyware became the winner. It found the most spyware and what I liked most about it was that it provide everything that Ad-aware and Spybot supplied all together. This and the spynet option.  But in 6 months a lot can change and now I have whenU on my machine together with some other heavy duty spyware.  More on the reasons for this you can find in the link below

http://blog.coolz0r.com/posted/microsoft-antispy-downgrades-claria-apps.html

So the search for a good, free spyware cleaner goes on … I’ll post more when I’ve found one.  If anybody has a recommendation please let me know, because spyware me-no-like.

04JanAtlas New RC build released

There is a new Atlas RC available for download. 
This one has got really cool new features.  If you haven’t looked at atlas before you should look at it now.

AJAX just became as simple as 1-2-3.

Nikhil Kothari blogs about the new features :

A quick tour of Atlas December CTP :
http://www.nikhilk.net/AtlasM1.aspx

The role and functionality of the Atlas Scriptmanager :
http://www.nikhilk.net/AtlasScriptManager.aspx

That should get your appetite for AJAX going :-D

04JanWebDav Exchange …

I live in new zealand.

I can successfully create appointments in exchange using webDAV.  But I can only create them in the timezone Z if I change the timezone to Y (which is mine) I always get bad request.

Do I say ok.. so not during string conversion but I just calculate the offset and add that to the date and create the appointment then that should be ok. Also not !!!

My conversion function is very basic but i didn’t find a way to get it properly formatted in .NET so this is my way. The function below ends with “Y“ and this doesn’t work, when I end it on Z it does work. Any suggestions ?

All sorted now.. instead of passing on the timezone I should replace the Y with the offset of the timezone to +13:00 in the new zealand case.

string

formatDate(DateTime input){

return input.ToString(“yyyy-MM-ddTHH:mm:ss.fffzzz”);
}

 

04JanDesign templates for websites from microsoft

http://msdn.microsoft.com/asp.net/reference/design/templates/default.aspx

04JanGetting subtotal in xslt

To get the subtotal of products in their own subcategory


  
        
               1234
               233
        

        
               1235
               23
        

  

  
        
               124
               298
        

  

<

xsl:template mode =”do-sum” match=”Products”>
<xsl:param name=”sum” select=”0″/>
<xsl:variable name=”running-sum” select=”number(translate($sum + number(number(Product_Verkoopbasis)*number(Product_Voorraad)),’.',”))”/>
<xsl:choose>
<xsl:when test=”following-sibling::Products”>
<xsl:apply-templates mode=”do-sum” select=”following-sibling::Products[1]“>
<xsl:with-param name=”sum” select=”$running-sum”/>
xsl:apply-templates>
xsl:when>
<xsl:otherwise>
<xsl:value-of select=”format-number( $running-sum, ‘#.##0,00′, ‘numfrmt’)”/>
xsl:otherwise>
xsl:choose>
xsl:template>
<xsl:template name=”getSubtotal”>
<fo:table-row>
<fo:table-cell background-color=”#CCCCCC” number-columns-spanned=”3″>fo:table-cell>
<fo:table-cell background-color=”#CCCCCC” text-align=”right”>
<fo:block>Subtotal :fo:block>
fo:table-cell>
<fo:table-cell background-color=”#CCCCCC” text-align=”right”>
<fo:block>
<xsl:apply-templates mode=”do-sum” select=”SubCategory[1]/Products[1]“/>
fo:block>
fo:table-cell>
fo:table-row>
xsl:template>

 

04JanRss Parsing

As mentioned earlier in this blog, I am building a rss program together with http://datafreakz.blogspot.com

Right now we have about 100000 feeds from this feeds I had before the weekend about 5000 that failed. Now most of these feeds were valid rss although my google sidebar doesn’t parse a lot of them either.

Then I’ve noticed that lots of people never took the time to read the specifications and dump whatever they like in an rss feed.
Furthermore there are a lot of people including w3c and ms that put stylesheets in their xml.  Up until last week (because I had a parser that seemed to parse a lot of it already), I was one of these people that thought that just using the System.Xml.XmlReader would be enough and that I would get everything on the first pass through my xml.

Now after the weekend I’ve figured out that it takes 3 passes, that is 3 different ways to get the xml in my program to parse almost everything. The next problem that shows up are feeds that do exist, but their hosts are pretty slow in resolving the domains etc.. so I will be needing some retry mechanism.  The idea behind our system is that we want to be able to parse every valid feed from the internet.

I’ve got the different encodings sorted now.

One of the feeds that bounces the first time :


http://presscenter.org/repository/rss/nl/Ext_102110_5.xml

And this one doesn’t want to parse yet :


http://www.musicalfan.be/rssfeed.xml

probably because of its description field in a few posts.  but I do read feeds with html in them that is what I find so strange.. I don’t know why this one doesn’t want to parse.. for now. ;-)

Always I will appreciate ideas…. I can’t show you my code for my parsers but it is based on the xml reader class, too which you pass an encoded textreader. at least the first try parser.  I parse more feeds than Rss.NET and I parse more than rssbandit or rssfeeder.net But I want to be able to say that I parse about 99,99% of the feeds out there.
I don’t want to use serialisation because of the performance overhead.. If you need to parse 100 000 – 300 000 feeds every bit counts ;)   And once we open up for the general public it will be even more feeds.

When everything will be finished online.. probably I will be providing a vs2k5 add in and outlook add in.

Recent Flickrs

    Blogroll

    Recent Listening

    Scrobbler