Thomas’ Developer Blog

July 23, 2008

Allow programs at start up on Vista (Prevent Windows Defender from Blocking)

Filed under: Server — Tags: , , , , , , , — sanzon @ 10:06 am

Yes it’s been ages since I’ve updated. Anyway I came across a very annoying part of window’s defender. Now this can be a problem with anyone who uses any startup program that defender blocks. Yes you can disable defender, but honestly I’d prefer to keep security if i can. Helps a lot with a server. lol

Anyway the solution requires some minor “hacking.” I don’t really like to call it that since you’re just using what you have free access to anyway. 

To begin you have to start by removing that program from start up.

1) Run > msconfig
2) Click the Startup Tab
3) Scroll down until you find that pesky program giving you issues
4) Note the location and see if it is HKLM or HKCU

Open up regedit
1) Run > regedit
2) If it is HKLM go to HKey_Local_Machine otherwise it should be HKey_Current_User
3) Go to HKLM/HKCU > Software > Windows > Current Version > Run
4) Find that pesky program, right click, and delete that string value (the ab icon thing)

After that you need to go to task scheduler
1) go to: Start > Program Files > Accessories > System Tools > Task Scheduler
2) Under actions context at the top click “create task…”

Under create task
1) Give it a name (I choose the name of the program
2) Make sure you select run only when user is logged on
3) Check “Run with highest privileges
4) Go to the triggers tab
5) Click New
6) From the drop down select at log on
7) Make sure everything is unchecked EXCEPT “enabled” and click OK
8 ) Click Actions tab
9) Click New
10) Select Start a Program from the dropdownlist
11) Browse for the program you want to start
12) Click OK
13) Click Settings Tab
14) Check Allow task to be run on demand
15) Check Run task asap after a scheduled start is missed
16) Uncheck “Stop the task if it runs longer than:”
17) Uncheck “If the task is not scheduled to run again…”  (note that you can check this if you want, but only if you don’t plan to run the program again after a set time)
18 ) Make sure “Do not start a new instance” is selected from the drop down list at the bottom
19) Click OK
20) Restart and it should be working just fine

June 27, 2008

ISO 639-3 Language Codes (XML Cheat Sheet)

Filed under: HTML, sql, xml — Tags: , , , , , , , — sanzon @ 5:22 am

For those who know anything about languages it can be a pain in the but trying to organize them.  I’m not talking about creating different langauges on your site. I’m simply talking about storing those ISO codes into a database so you can retrieve them later.

After a few hours of work I managed to thread through a pretty long list of codes and input them into a database for later use!

Now due to the size of the list and the pain of writing everything down I’m going to direct link you to a XML file. This XML file will make it far easier to update your database. Now I’m only go share this file. It is up to you to write the code to input it. Which isn’t hard for anyone who has some basic database knowledge along with asp.net’s ADO.net practices.

Anyway it is my great great hope that this will help you out a LOT.

I know a lot of sites, Veoh for example, use ISO 639-1. I feel that while you can get away with it, I prefer to be up to date. This XML file is for June of 2008 and the lastest update for ISO 639-3. Also I went ahead and combined a few of the duplicate codes together so you can input them as a unique code. If you run through it, it took me about 5 to 10 minutes on local host of waiting for it to all input.

You can find the XML file at:

http://www.2shared.com/file/3504750/bd97c19e/ISO639_3.html

Be sure to share it if possible. Since I know it’s a pain to find it online.

June 6, 2008

Forcing Server Side Error in VB.Net

Filed under: Asp.Net Framework 2.0, vb.net — sanzon @ 7:26 pm

It’s been a long time since I’ve updated. Mainly because I haven’t had anything new come up to post about and I’ve been on vacation. So today I have something new!.. for a change lol

There are times when you may want to force an error within a serverside script.

These errors will only be useful to the developer so that they are not going insane trying to figure out what is going wrong with the script.

Well I’ve been racking my brain over this one for a long time. Of course I just kind of ignored it for a while, until I came accross a script that did exactly what I wanted it to! So now I have the solution and it’s really simple.

Simply add:

Throw New Exception(”Thumbnail size must be aat least 1% of the original size”)

Where the invalid argument is.

So for example you may have:

If myvar = “” Then
     Throw New Exception(”Thumbnail size must be aat least 1% of the original size”)
End If

So there are a lot of times when this can be useful. For example if you work with strings and have to make sure the string is in the proper format. You simply use a regular expression to check to see if the string is valid. If not throw an exception  to the developer letting them now: hey! You screwed up here! Fix it!

It’s funny how these things are always so simple yet no one knows the answer, or makes it out to be 10 times more complex then it ever had to be.

May 11, 2008

Asp.Net AJAX updatepanel postback trick with reCaptcha!

Filed under: AJAX, Asp.Net Framework 2.0, javascript, vb.net — Tags: , , , , , , — sanzon @ 7:54 am

You would have no idea how stressful this was trying to figure out!  Finally after a lot of hardwork I was able to figure out a semi hack around the problem.

Here’s the issue.  Everytime you run a partial postback through an updatepanel you run through a script only for that panel, but what if you want to have a clause in that code where you can do a full postpost so that you can maintain your viewstate and keep form data.

In this case we have a recaptcha device and the following .aspx source code:

  <div onkeypress="return no_enter(event,this,'none');" style="width:550px;">
   <recaptcha:RecaptchaControl
    ID="recaptcha"
    runat="server"
    PublicKey="xxxxxxxxxxxx"           
    PrivateKey="xxxxxxxxxxxx"
    theme="clean" />
   <asp:UpdatePanel ID="upnlTAB5" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
     <asp:Label ID="lblResult" runat="server" />
     <br /><br />
     I confirm that all information provided is correct under my best knowledge and that by
     intentionally providing inaccurate information
     will result in the termination and potential denial of service from this site.<br /><br />
     <div style="text-align:center;">
      <asp:button text="Confirm and Complete Registration" skinID="button" id="btnSubmit"
               onclick="TAB5_Submit" runat="server" /><br /><br />
      <input type="button" id="btnConfirmation_Disagree" OnClick="javascript:NewUser_Disagree();"
              class="buttoninput" style="height:20px;" runat="server"
              value="Disagree & Cancel My Registration" /><br /><br />
     </div>
     <span class="infospan">Please only submit this form once!  This process may take 1 to 2
          minutes to complete depending on site traffic. 
          If this page fails you may attempt to login and choose to resend your verification email.</span>
    </ContentTemplate>
   </asp:UpdatePanel>
  </div>

Now here is the issue.  You can’t place the recaptcha into the update panel or else it will not load correctly..  Thus if a user attempts do a partial postback on the updatepanel you will loose the recaptcha control.  So what you do is remove it from the update panel.  Seems easy right?  Not always the case.  What if it is incorrect?  Then you still have the exact same recaptcha.  What you will need to do is referesh the page!  Seems easy hey?

Remember they just filled out this long form!  They will have to retype everything else well.  I wish .Net had an easy solution, but sadly there isn’t.  To solve this what you have to do is create a hidden .Net button within a div with the style display none.

Here is the source for the button:

  <div style="display:none;"><asp:button id="btnRefresh" onclick="refresh" text="test" runat="server" /></div>

Now all we have to do is simply go ahead and use some java to trick the button into being submited.  So on our server side code we have:

 Sub TAB5_Submit(ByVal sender As System.Object, ByVal e As System.EventArgs)
  If Page.IsValid Then
   ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Tab5InvalidFields", "alert('PASS');", true)
  Else
   ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Tab5InvalidFields", _
         "alert('Confirmation: Invalid CAPTCHA, please try again.');document.getElementById('" _
         & btnRefresh.clientID.tostring & "').click();", true)
  End If
 End Sub

We use the scriptmanager to register a startup script to call a small javascript code.  In this case we alert the user that the information was incorrect for the CAPTCHA.  Now this is the trick!

We use javascript to click that hidden button!  That button will reload on the serverside and the viewstate will handle the rest!  So once the button is clicked we run the code:

 Sub refresh(ByVal sender As System.Object, ByVal e As System.EventArgs)
  tbxNewPassword.Attributes.Add("Value", tbxNewPassword.text)
  tbxConfirmNewPassword.Attributes.Add("Value", tbxConfirmNewPassword.text)
 End Sub

This sub reloads the page.  it can be blank if you wish, but you should take the time to refill the password boxes manually.  You simply create an attribute to reset the password values!  It works really well.

Now you are have to square one and they just have to reenter the captcha code!

Hope this helps, happy coding.

May 7, 2008

VB timer function conflict in .Net 3.5

Filed under: .Net Framework 3.5, vb.net, vbscript — Tags: , , , , , — sanzon @ 9:53 pm

Well I finally took the time to do a quick.. or not so quick.. update to 3.5

Anyway the transition is really simple, the only major issue I had was configuring the web.config file for 3.5

If you’re like me and don’t use visual studio, you can manually enter the web.config information for .net 3.5

The best place to go for the code is: http://www.4guysfromrolla.com/articles/121207-1.aspx

Once you have the .config file setup it should be smooth sailing.. unless you fun into a fun little conflict with asp.net!

The new AJAX timer control is really nice and useful!  BUT vbscript also have a timer control!  This can be an issue, but luckily it’s really easy to fix.. once you take an hour to figure it out. lol

Just replace timer with: DateAndTime.Timer()

This solution is really simple!  Hope this helps!

May 4, 2008

Delimiter List Trimming VBScript

Filed under: Asp.Net Framework 2.0, vb.net, vbscript — Tags: , , , , , , , — sanzon @ 11:03 pm

Yes, as you notice if you read my post… I’m doing a ton of string modifying, so you’ll be seeing a lot of really simple examples, but I figure it’ll be good to help those who might have these  issues in the future.

Alright, continuing with the theme of the last two post!  I’m going to show you another trim method!  This method will go ahead and trim a comma list, or any other type of delimiter list.

The method is easy, you take a string seperated by a delimiter such as:

Hobbies:
“  Coding ,Gaming, Anime,Bowling, Pool,Business ,Finance,  “

Now you will notice that there is a problem with the above code.  All of those spaces before and after the comma and at the end of the list.  Plus there is a comma at the end of the list, this is just a mess!

Well what we need to do is trim the edges of whitespace, remove the commas at the end, and check for spaces before and after the commas to make sure everything is all neat and tiddy!  Best part of this is, the user never notices!  Which is how you want it.  Make it easy for them, let them mess up the string as much as the like, we just have to go back in and fix it up before we take the list split it up and insert it into a database.

Well here is the next fun function to do just that!

   Public Function DelimiterListTrim(ByVal mySrc As String,Optional ByVal myDelimiter As String = “,”) As String
    If mySrc = “” Then
     return nothing
     exit function
    End If

    Dim myStr As String = mySrc

    Dim myChar As String = myDelimiter & chrW(32)

    myStr = Replace(myStr,chrW(13),”")

    do while Regex.IsMatch(myStr,myDelimiter & ” “)
     myStr = Replace(myStr,myChar,myDelimiter)
    loop
    
    do while Regex.IsMatch(myStr,” ” & myDelimiter)
     myStr = Replace(myStr,StrReverse(myChar),myDelimiter)
    loop

    do while Regex.IsMatch(Left(myStr,1),myDelimiter)
     myStr = mid(myStr,2)
    loop

    do while Regex.IsMatch(Right(myStr,1),myDelimiter)
     myStr = mid(myStr,1,len(myStr)-1)
    loop

    return myStr
   End Function

The code is fairly easy, it’s just what we did before, all I did this time was combine them!

First we create our string we want to test, which is the delimiter and any spaces.  Notice that the delimiter is optional and the default is comma.  This is the most common practice.  Well first we check for occurances of “, ” and swap it out with “,” and we do a loop because they may have “,  ” so we need to go through several times.  Again we do the same in reverse for checking for ” ,” once we have done that we simply go through and loop through to clean the edges of any excess delimiters towards the begining or end.

Now that string will come out neat and tidy as:

“ Coding,Gaming, Anime,Bowling,Pool,Business,Finance”

And you can go use the split method to go ahead and add it to a database!  Well hope this helps, happy coding!

Inline Trimming in VBScript

Filed under: vb.net, vbscript — Tags: , , , , — sanzon @ 9:09 pm

This post continues from:

http://sanzon.wordpress.com/2008/05/04/trimming-white-spaces-and-linebreaks-from-strings/

In the last post I went over how to remove linebreaks from the begining and end of a multiline string and at the same time forcing paragraph style post with double linebreaks.

Now in this post I’m going to take it another step with inlinetrimming.  What this means is if you have a post like:

“Hi mom,

   Today there was a    …..”

The problem is that big dent at the begining and end of the paragraph.  Now in HTML this normally will turn out to a single line space, unless you preserve spacing by converting chrW(32) into &nbsp;

To remove this excess we simple use a simular method for our inline trimming method.
   Public Function InlineTrim(ByVal mySrc As String) As String
    If mySrc = “” Then
     return nothing
     exit function
    End If

    Dim myStr As String = mySrc

    Dim myChar As String = chrW(10) & chrW(32)

    myStr = Replace(myStr,chrW(13),”")

    do while Regex.IsMatch(myStr,”\n “)
     myStr = Replace(myStr,myChar,chrW(10))
    loop
    
    do while Regex.IsMatch(myStr,” \n”)
     myStr = Replace(myStr,StrReverse(myChar),chrW(10))
    loop

    return myStr
   End Function

 This function is very simple.  First you go ahead and remove all returns in the string and than search for instances of “\n ” and ” \n” and return it as “\n” and continue to repeat this until all spaces are remove.  The ending result is a nice clean block text format with not indents at the begining or end.

Anyway be expecting alot of these post coming up as I redo my class library on my site… the horror of string formating X_x;

well happy coding!

Trimming white spaces and linebreaks from strings

Filed under: Asp.Net Framework 2.0, vb.net, vbscript — Tags: , , , , , , — sanzon @ 7:32 pm

I’m sure most of you already know the trim() function in VBScript.  This is a highly useful function for removing whitespace from the edges of a string, but the problem is that this function fails to remove linebreaks as well.

This can be very useful with preventing spam on a website such as:

OMGZ lookit as thi AWOMZ LINKZ:

 

 

ILIKESPAMZCUZITS1337z.com

 

LOOK AT IT TODAY!

 

Without saying anything you know for a fact that is annoying as all can get out of!  We would love to get rid of it.. but for this post I’m only going into how to make it look somewhat more presentable…

The solution to this problem is actually really simple using a small regular expression in VB.  In this case I created two functions, since I included them into my class library and it was more functional to seperate them.

The first function is fairly simple using two loops and uses a small regular expression:

   Public Function TrimEmptySpace(ByVal mySrc As String) As String

    If mySrc = “” Then
     return nothing
     exit function
    End If

    Dim myStr As String = mySrc

    do while Regex.IsMatch(Left(myStr,1),”[\s]“)
     myStr = mid(myStr,2)
    loop

    do while Regex.IsMatch(Right(myStr,1),”[\s]“)
     myStr = mid(myStr,1,len(myStr)-1)
    loop

    return myStr
   End Function

As you can tell it’s a very simple script that loops through and looks for any space or linebreak with the /s special character in VBScript regular expressions.  If it notices any of those characters, we’ll go ahead and trim it!  We loop through the left then we go ahead and loop through the right, and return the formated string.

The second function is also fairly simple, but takes a bit of an extra road trip to get there.
   Public Function ParagraphSetter(ByVal mySrc As String) As String

    If mySrc = “” Then
     return nothing
     exit function
    End If

    Dim myStr As String = mySrc
    Dim myChar As String = chrW(10) & chrW(10)

    myStr = Replace(myStr,chrW(13),”")

    do while Regex.IsMatch(myStr,”\n\n”)
     myStr = Replace(myStr,myChar,chrW(10))
    loop

    myStr = Replace(myStr,chrW(10),myChar)

    return myStr
   End Function

ParagraphSetter is used to turn any line break into a double line break, and remove anything over two linebreaks in a row.  This is useful for areas where you need the post to be formal, and clear of clutter.  In my case it’s perfect for the comment section in news post and in new database entries for video synopsis, where I don’t want people getting “creative” in their post.

The first step of the function i to remove any return characters which is chrW(13).  This is needed for IE browsers since they use chrW(10) chrW(13) whenever the return key is pressed.  Firefox and others use only chrW(10).  One of the annoyances of IE, but they have been getting a lot better with IE7 and hopefully IE8 is all they make it out to be.

Anyway after you remove that pesky uneeded chrW(13) we go ahead and use a loop to look for double occurances of chrW(10) which is your normal line break.  We go ahead and then turn all of those doubles into single occurances.  Obviously we can’t have single linebreaks else we’ll have a post like:

Today in the news:
A man named…
Was trapped…

So once we format the string to only having single linebreaks, we go back again and double those.  Which makes it look like:

Todays News:

A man named….

Was trapped…

Which looks a lot cleaner.. and that previous post will turn into…

“OMGZ lookit as thi AWOMZ LINKZ:

 ILIKESPAMZCUZITS1337z.com

 LOOK AT IT TODAY!”

 

Ok.. granted that still is horrid.. but it’s a lot better than it was!  You can use spam filters to finish the job for looking for occurances of access caps and looking for key words like… 1337,.com, and many other common annoyances.  I have yet to work on a spam filter yet.  Though due to security reasons I most likely will not post the solution, but will give a basic idea of the theory so you can create your own.  Never let users know how you filter comments! Just a small bit of advice.

Well hope that helps!  Happy coding

May 1, 2008

Neat little HTML encoding trick in javascript

Filed under: AJAX, HTML, javascript — Tags: , , , , — sanzon @ 4:00 am

I came across a really neat trick in javascript lately that actually goes ahead and kind of cheats in a very effective manor!

Here’s the problem with javascript, everytime you send information from a form to a server side script, such as with AJAX, with HTML brackets it will return an error.  You can either manually fix this, or use a really neat trick called “escape”

 function escapeHTMLEncode(str) {
  var div = document.createElement(’div’);
  var text = document.createTextNode(str);
  div.appendChild(text);
  return div.innerHTML;
 }

 What this simple little function does is take the internal HTML conversion code from your browser and returns a string converted to HTML.  It’s an awsome trick with how simple it is.

See, you have to note that whenever a browser creates an element in javascript, and a text node is created, the browser will go ahead and make sure that string comes out as raw code, and not as HTML, thus the term textnode and not innerHTML.

Now if they only had a way to reverse it that was that easy. lol

April 29, 2008

Advanced Usage of Robots.txt w/ Querystrings

Filed under: robots.txt, search engines — Tags: , , , — sanzon @ 1:53 am

When you first learn robots.txt you think it’s fairly simple, allow, disallow.  Well while robots.txt sadly does not support regular expresions, which would be so awsome if it did, it does support the HIGHLY useful wildcard.

The problem is google and other search engines is they have no clue how to handle querystrings.  It confuses them to death, and as a result we get poor results.  What if they create a link on the search engine with user informaiton, such as UserID, or SessionID, or something else that just becomes annoying.  We want to maximize our results!

The solution to this problem just involves a semi-complex solution with advance usage of wildcards.  In this case, on my site I have a search page that uses querystrings to sort results by genre, content rating, appearance, and a lot of other options.  Plus I have a querystring for page number, page size.. it’s just a long mess of querystring values.

Well I don’t want to block all of the querystrings, because some are useful for a search engine, such as page number and query value.  An example would be:

/search/?q=a&pg=2

This works great!  Shows all the results under A that are in page number 2!  Perfect!  But what if it gets more complex…

/search/?t=1&g=29&go=1&cr=10&cro=1&s=6&ps=20&v=1&q=a

That is an actual result from one of my pages!  I dont want google to index that, because can you image how many combinations it would have!! It would be choas, google would spit it out and get PO’d and potentially think it is a long as mess of spam.  And trust me I use querystrings a lot in the search, and there are over 500 links on certain results, so it can become a HUGE mess.

Well I love the idea of having the querystring values pg and q since they are useful.  So to figure this out we use the following solution in robots.txt:

Disallow: /search/?*
Disallow: /search/?pg=*&*
Disallow: /search/?pg=*&q=*&*
Disallow: /search/?pg=*&*&q=*
Disallow: /search/?q=*&*
Disallow: /search/?q=*&pg=*&*
Disallow: /search/?q=*&*&pg=*

Allow: /search/?pg=*
Allow: /search/?pg=*&q=*
Allow: /search/?q=*
Allow: /search/?q=*&pg=*

 

This may look a bit complex at first, but the solution is simple.  First we go ahead and disallow all querystrings: /search/?*

Then we go ahead and ban a few others!

In this case I go and ban anything with a querystring value after pg, and also anything after a combination of pg and q and q alone, along with q followed by pg.

Generally I ban everything that isn’t pg or q in a row.  This also includes anything that may appear between them with:

Disallow: /search/?pg=*&*&q=*

The &* added will block anything between the two.

Then we go ahead and allow the specific values that are ?pg=* or ?q=*

As well we allow anything of the two followed by each other.

As you can tell while robot.txt seems simple, it can get a bit complex in some cases.  While this is nothing near as bad of something of the stuff I’ve been through since it was quick 15 min solution.

Here’s also something to remember when a search engine uses robots.txt it will go through all potential cases.  In this case I disallowed /?* but also put in an allow, which allowed the engine to index ?pg=*, but not all ?pg=* is approved, since in some cases it is blocked.  In the case of wildcards google will go ahead and check all potential allows and disallows.  With wildcards, the last one through will win.

For example if you have /?q=1&g=9&q=1 the robots.txt will allow ?q=*&pg=*, but because within the second wildcard there can be another querystring value, google will test that section of the querystring in the disallow part of robots.txt, and in this case it will block it since disallow: ?q=*&*&pg=* because the part “&* falls within the second querystring of the allow, which because it is a more fulfilled value, google will go ahead and block it.

It sounds complex, but if you think of it, it’s actually very logical.  Which is also why you don’t have to worry about how you group or order robots.txt the allow and disallows can be in any order at any place and not make a difference.

Hopefully that helps you understand robots.txt a bit more and if I remember I’ll be sure to tell you how it turned out on google.  hopefully my ranking goes up once all of the older stuff is washed out.

Older Posts »

Blog at WordPress.com.