Deprecated: Assigning the return value of new by reference is deprecated in /home/gathadam/public_html/wp-settings.php on line 520

Deprecated: Assigning the return value of new by reference is deprecated in /home/gathadam/public_html/wp-settings.php on line 535

Deprecated: Assigning the return value of new by reference is deprecated in /home/gathadam/public_html/wp-settings.php on line 542

Deprecated: Assigning the return value of new by reference is deprecated in /home/gathadam/public_html/wp-settings.php on line 578

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/gathadam/public_html/wp-settings.php on line 18
Uncategorized

Quick SQL Server Tuning Tip

Tuning SQL Server can be a real pain - everyone knows the basics; return the minimum rows, use indexes etc - but sometimes you need to get some hard stats.

Before we begin, I am going to assume you are running in Query Analyzer, or some tool that allows you to change the connection parameters.

Execute:


SET STATISTICS IO ON
SET STATISTICS TIME   ON

This gives you useful info on how many pages were read in your query (both from the cache and from disk)   and how long it takes.

Eg, after running a query, here are the stats:

Table 'DG_UserProperties'. Scan count 0, logical reads 2154, physical reads 10, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table ‘DG_Users’. Scan count 1, logical reads 1083, physical reads 27, read-ahead reads 1, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.


SQL Server Execution Times:
CPU time = 16 ms,   elapsed time = 213 ms.

It is important to reduce the ‘reads’ and the CPU time. Elapsed time can vary depending on server load, so isn’t as important when comparing queries.

After each set of statistics, clear the cache otherwise the next query will use it & give an incorrect comparison.


DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE

This post brought to you by WeGotDomain.com - Over 10,000 Aged domains for sale!

Related posts:

  1. Convert MySQL to MS Sql Server

How to access HttpServerUtility.MapPath in a Thread

Usually, when you want the root directory of your website, it is easy to call:

HttpContext.Current.Server.MapPath

or just

Server.MapPath

from a page.

But if you are running your code in a thread or timer, then HttpContext.Current is null (giving you a NullReferenceException), and you are out of luck. :(

However, as long as you are not using virtual directories, there is an easy fix:

AppDomain.CurrentDomain.BaseDirectory

will give you the same result, and doesn’t depend on a current HTTP context.

This post brought to you by WeGotDomain.com - Over 10,000 Aged domains for sale!

Related posts:

  1. We Got Domain - over 10,000 aged domains for sale
  2. See how your website looks in over 60 browsers - in minutes

Remove Name Mangling from ASP.Net Master Pages (get your ID back!)

If you have been programming using ASP.Net Master Pages and javascript then you have no doubt come across the problem where you try to access an element in javascript using:

var sValue = document.getElementById(’TextBox1′).value;

And you keep getting an error that the element cannot be found. If you check the HTML source for the page, you see that asp.net has “helpfully” added something like ‘ctl00_ContentPlaceHolder1_’ to the front of the control ID, so you have to use:

var sValue = document.getElementById(’ctl00_ContentPlaceHolder1_TextBox1′).value;

I’m not going to try & sugar coat it - this totally sucks.

The solution that I have been using overwrites the .getElementById method, allowing you to search for the element just using the normal ID.


<script type='text/javascript'>
document.newGetElementById = document.getElementById;
document.getElementById = function(sElementID)
{
var oFirstTry;

oFirstTry = document.newGetElementById(sElementID);
if (oFirstTry)
	return oFirstTry;
else
	return document.newGetElementById('ctl00_ContentPlaceHolder1_' + sElementID);
}
</script>

Thanks to Scooby Doo for pointing out the earlier error, it has now been corrected

Add this code to the top of your asp.net page or .js file, and then you can go back to using:

var sValue = document.getElementById(’TextBox1′).value;

without caring if it is in a content page or not.

Note: The above code won’t work if you change the name of your ContentPlaceHolder control from the standard ‘ContentPlaceHolder1′. If you do like to have unique names then change

return document.getElementById(’ctl00_ContentPlaceHolder1_’ + sElementID);

to

return document.newGetElementById(’<%=me.Form.Controls(1).ClientID %><%=Me.ClientIDSeparator %>’ + sElementID);

The code must now always be placed in your asp.net page (not an external .js file). However, calls to .getElementById can still be in external .js files.

Finally: A common solution to the problem is to use the ClientID property:

var sValue = document.getElementById(’<% =TextBox1.ClientID %>’).value;

but this method requires that all calls to getElementById be in the asp.net page, which is not as flexible as the solution given.

This post brought to you by WeGotDomain.com - Over 10,000 Aged domains for sale!

Related posts:

  1. Remove HTML tags and Javascript from pages

Add GeoLocation to your site in less time than it takes to Drink a Beer

This is what a regular programmer looks like
Adding Geolocation to your website is so easy these days that I’ve decided that not only can we do it within 5 minutes, but to make it interesting I’ll bet that you’ve finished it before you can finish a beer.

OK? Got your beer? Lets go.

  1. Crack open the beer and start a new vb.net project. Call it ‘GEOTest’. Take a well deserved drink.
  2. Download the MaxMind Geo database and vb.net wrapper code from MaxMind (Complete list of supported languages - thanks again to MaxMind for doing all the work). Have some more beer while it downloads (thanks to my spankinglyfast ADSL2+ connection, no beer for me).
  3. Open the zip file into your project directory. Another sip. Add the files   ‘testCountryLookUp.aspx’, ‘testCountryLookUp.aspx.vb’ and ‘CountryLookup.vb’ to your project.
  4. Thirsty? More beer.
  5. Set the page ‘testCountryLookUp.aspx’ as your startup page, and then run the project. At this point it should run, but you may get a ‘Parser Error’ in the ‘testCountryLookUp.aspx’ file. To fix it, change:
    Inherits="testCountryLookUp"
    to
    Inherits="GEOTest.testCountryLookUp"
    in the   ‘testCountryLookUp.aspx’ file.
  6. Thats it! Done! You’ve probably still got plenty of beer left, so lets make some of our own code to get the country from IP Address.


Function CountryFromIP(ByVal Address As String) As String
     Dim oCountryLookup As CountryLookup = New CountryLookup(Server.MapPath("data/GeoIP.dat"))

     CountryFromIP = oCountryLookup.LookupCountryName(Address)
End Function

To call it, just use:
CountryName = CountryFromIP(Request.UserHostAddress)
Doesn’t work? Maybe too much beer…Passing your UserHostAddress won’t work from your local machine. To test, grab your IP address from somewhere like whatismyipaddress.com.

Still doesn’t work? Definitely time for another beer…

This post brought to you by WeGotDomain.com - Over 10,000 Aged domains for sale!

No related posts.

Opening a new browser window with POST data

Every now and again I want to have a link that opens a new browser window, and passes some values in. It’s easy when you just need to pass in GET data:

http://dummydomain.com?value1=just&value2=a&value3=test

But it becomes harder when you want to pass in POST values.

Maybe not that hard…How about opening the new window, adding the POST variables to the form, and then posting it to the relevant domain. That would work :)

This code gives you a button which will open a new window and automatically log in to your WordPress blog.


<html>
<head>

        <script type='text/javascript'>
        function LoginToWordPressBlog()
        {
        var sData;
        var sUserName = "YourUserName";
        var sPassword = "YourPassword";
        var sDomain = "http://YourDomain.com";

        sData = "<form name='loginform' id='loginform' action='" + sDomain + "/wp-login.php' method='post'>";
        sData = sData + "<input type='text' name='log' id='user_login' class='input' value='" + sUserName + "' />";
        sData = sData + "<input type='password' name='pwd' id='user_pass' class='input' value='" + sPassword + "' />";
        sData = sData + "<input type='submit' name='wp-submit' id='wp-submit' value='Login »' />";
        sData = sData + "<input type='hidden' name='redirect_to' value='/wp-admin/' />";
        sData = sData + "<input type='hidden' id='wordpress_test_cookie' name='wordpress_test_cookie' value='WP Cookie check' />";
        sData = sData + "</form>";
        sData = sData + "<script type='text/javascript'>";
        sData = sData + "document.cookie='wordpress_test_cookie=home; expires=Fri, 11 Jul 2009 05:23:14 +0000; path=/';";
        sData = sData + "document.loginform.submit();</sc" + "ript>";
        OpenWindow=window.open("", "newwin");
        OpenWindow.document.write(sData);
        OpenWindow.document.close()
        }
        </script>
</head>
<body>
        <form id="form1">
                 <input id="Button1" type="button" value="Login To Wordpress" onclick='LoginToWordPressBlog()' />
        </form>
</body>
</html>

The method above is in javascript, so it should work for pretty much everybody. The steps are:

  1. Create a new window
  2. Use document.write to write the HTML POST data tags to the new window.
  3. Submit the new window.

The only tough part now is finding out which POST tags you need - and the best tool for that is Fiddler. It even shows you the cookie values that you need.

This post brought to you by WeGotDomain.com - Over 10,000 Aged domains for sale!

Related posts:

  1. MySpace API
  2. Copying cookies across domains in ASP.Net
  3. MySpace API - Automate your Blog posts
  4. Hiding the Digg button from Diggers
  5. Easy Cross Domain Cookies (Sharing cookies between domains)

Using Random.org to Generate Truly Random Numbers in .Net

Random numbers can be a pain if you have to generate new sequences each day. The normal ‘randomize()’ statement is seeded from the system timer so if you are running the generator at the same time, then there is a chance you will get the same sequence.

Over at   Random.org, Mads Haahr has been generating random numbers using atmospheric noise since 1998, and his method has the pseudo-random number generators build into VB.Net beat.

Here is the VB.Net wrapper to call random.org and get your numbers:


Imports System.Net

Public Class clsRandom
        Public Sub RandomizeReseed()
                Dim iSeed(0) As Integer

                iSeed = RandomIntegers(-1000000000, 1000000000, 1)
                Randomize(iSeed(0))
        End Sub

        Public Function RandomIntegers(ByVal MinValue As Integer, _
                ByVal MaxValue As Integer, _
                ByVal NumberCount As Integer) As Integer()

                Dim iC As Integer
                Dim iRetInts As Integer()
                Dim sRetIntsAsStr As String()
                Dim sURL As String

                If Math.Abs(MinValue) > 1000000000 Then
                        Dim ex As New Exception("MinValue cannot be greater than 1,000,000,000 or less than -1,000,000,000")
                        Throw ex
                End If

                If Math.Abs(MaxValue) > 1000000000 Then
                        Dim ex As New Exception("MaxValue cannot be greater than 1,000,000,000 or less than -1,000,000,000")
                        Throw ex
                End If

                If MinValue > MaxValue Then
                        Dim ex As New Exception("MinValue cannot be greater than MaxValue")
                        Throw ex
                End If

                If NumberCount > 10000 Then
                        Dim ex As New Exception("NumberCount cannot be greater than 10,000")
                        Throw ex
                End If

                sURL = "http://www.random.org/integers/?"
                sURL = sURL & "num=" & NumberCount
                sURL = sURL & "&min=" & MinValue
                sURL = sURL & "&max=" & MaxValue
                sURL = sURL & "&col=1&base=10&format=plain&rnd=new"

                sRetIntsAsStr = CallRandomDotOrg(sURL)
                ReDim iRetInts(sRetIntsAsStr.GetUpperBound(0))
                For iC = 0 To sRetIntsAsStr.GetUpperBound(0)
                        iRetInts(iC) = sRetIntsAsStr(iC)
                Next

                RandomIntegers = iRetInts
        End Function

        Private Function CallRandomDotOrg(ByVal sGetURL As String) As String()
                Dim objWebClient As New WebClient()

                Dim sResponse As String
                Dim sReturnInts() As String

                sResponse = objWebClient.DownloadString(sGetURL)
                If Right$(sResponse, 1) = vbLf Then
                        sResponse = Left$(sResponse, Len(sResponse) - 1)
                End If

                sReturnInts = sResponse.Split(vbLf)

                CallRandomDotOrg = sReturnInts
        End Function
End Class

Using the class is pretty simple. You can get an array of integers using the function:
RandomIntegers(MinValue, MaxValue, Count)

or you can seed the built-in random number generator with a truly random number by calling
RandomizeReseed()

This post brought to you by WeGotDomain.com - Over 10,000 Aged domains for sale!

Related posts:

  1. SEOMoz Linkscape API wrapper in VB.Net
  2. Getting Flights info from the Kayak API in ASP.Net
  3. Create a Website Comparison Widget using GoogleTrends

Going away for the weekend

Kym & I are going away for the weekend for a much needed break. Where? you ask - look no further than here for great Daylesford Accommodation.

See you next week!

Free Memberships and Supporting Memberships at Sudoku.com.au

So what is going on?

It has always been a big concern to me that sudoku.com.au remains as warm and welcoming to visitors as possible. I have always thought that I have been very lucky to attract the sort of visitors so that the site gives out this feeling.

As with any large site, though, it has also attracted its share of spammers and people that are more interested in insulting others than anything else. I have put in place posting guidelines and various technical filters, but these are all avoidable if you are determined. Getting past the filters is made a lot easier by not having to log in before you post a comment or start a chat session - which is why I have introduced the free membership. The Free Membership (FM) is a new addition to the site and has coincided with the ‘Last Post’ competition. I have been asked if FMs are going to last beyond this competition, and the answer is yes.

By restricting access to the chatroom so that only members can enter, it is now much easier to ban people that just want to annoy (or worse) other people. Posting comments may be eventually restricted in a similar fashion, but hopefully not just yet.

A few supporting members have voiced their concerns that I am now giving away for free some of the things that they paid their membership fees for (Avatars, Smilies, Personal pages). While Free Members still have Ads and don’t get the sudoku solving tools, I can understand some SMs feeling this way. I am grateful that they have paid their membership fees & it certainly isn’t my intention to seem disrespectful. Almost all the new recent additions to the site have been for SMs and I am sure there will be plenty of new SM-only additions coming along shortly. If an SM feels that the free membership has everything they want from the site, then I would hope that when the membership expires that they remain on as a free member. Finally, if an SM has just recently joined or renewed their membership and would rather be a free member then just contact me and I will be happy to issue a refund.

Whew - thats everything! I have plenty of new stuff in the pipeline, so hopefully the site will get better (and better!). As always, if you have any suggestions just let me know. I have been super busy lately, so if you have sent an email and haven’t got a response please send it again.

Thanks to all the visitors to sudoku.com.au; Supporting Members, Free Members, and even the people that don’t want to know about this and just want sudoku :)

Cheers,
Gath

Top 10 Fighting Robots

From the labs to the arenas to the battlefields, here are the Top Ten Real Life Fighting Robots.

10. Sewer Snake
Sewer Snake
Sewer Snake became the richest battlebot of all time when it won the $10,000 Combots 2005 Championship. Later the same year, Sewer Snake also won the RFL (Robot Fighting League) Nationals. In 2006 it went up a weight class to Super Heavyweight (340 lbs) and still managed second. Sewer Snake’s main weapon is an ‘Invertible Lifting Wedge’ (Flipper) which it uses to throw its opponents into the air and sometimes out of the arena. Robot fighting events go in and outta style each year, though maybe its on the way up - ComBots came in at #8 in ‘The Best 10 North American Geek Fests’ but was well behind the ‘World Championship Punkin Chunkin’ (pumpkin throwing) at #2.
http://www.youtube.com/watch?v=duHe8g6Hdn8

9. VIPeR
VIPeR
Straight outta Israel comes the 9 inch tall VIPeR. Though it looks more dinky than dangerous, apparently it can be fitted with an UZI machine pistol or plant grenades. It can also do the standard bomb-sniffing and surviellence through its onboard camera.
http://israelitybites.blogspot.com/2007/03/viper-and-heron-israels-latest-war.html

8. Gladiator
Gladiator
Developed by Carnegie Mellon University for the Marine Corps, the Gladiator is currently in prototype stage. It is highly configurable, the weapons payload can be changed (or completely removed) depending on the mission and the locomotion can alternate between tracks or 6 wheels. It is designed to take a lickin and keep on tickin; the specifications state it can withstand small arms fire at point blank range and still be operable.
http://www.globalsecurity.org/military/systems/ground/gladiator.htm

7. Robart III
Robart III
Built by the US Navy, this research prototype is one of the most sophisticated of the robots. It features automated target acquisition; firstly it scans the area for pre-taught known objects and then zooms in to look for vulnerabilities. It also can navigate autonomously through unknown terrain while simultaneously mapping the area. Armament is an air-powered Gatling gun. Though the gun only fires tranquilizer darts “the spinning-barrel mechanism also imparts a rather sobering psychological message during system initialization”.
http://www.spawar.navy.mil/robots/land/robart/robart.html#Robart3

6. Land Walker
Land Walker
This one’s for the BattleTech fans. Standing at 3.4 metres (11.15 feet) tall and with 2 side-mounted guns, this robot certainly looks the goods. Before you go out and buy one (get your own custom walker for $313,000), you might want to know that the guns shoot rubber balls and the walking is more like a ’shuffle’. Still cool, but maybe a rent rather than a buy.
http://www.sakakibara-kikai.co.jp/products/other/LW.htm

5. Huitong
Huitong
Huitong (’the child’) is a human-shaped robot built by the Beijing Institute of Technology. Details in english are sketchy at best, though it has “sense of sight, audio dialogue, sense of force and sense of balance”. It can also perform Taijiquan (shadowboxing) and demonstrated its swordfighting technique at an “exhibition of major achievements of the national 10th Five-Year program “. Or something.

http://www.chinanews.cn/news/2005/2005-09-19/11146.html

4. Flameosapien - Robosapien Flamethrower Hack
Flameosapien - Robosapien Flamethrower Hack
So the other robots here are cool n’all, but a little pricey. Well, if you are up for a little DIY then this could be for you. All it takes is a standard Robosapien, about $100 for the flamethrower parts and to be not concerned if you “blow off a hand or burn your house down”. On the same site they also have instructions on how to add a coil gun to your robosapien.

http://www.evosapien.com/robosapien-hack/marcus/html/flameosapien_v2.html

3. MQ-9 Reaper
MQ-9 Reaper
The MQ-9 is developed by General Atomics and is the first hunter-killer unmanned aerial vehicle (UAV) designed for long endurance high altitude surveillance. Armament is a combination of air-to-air and air-to-ground missiles as well as laser guided bombs (depending on the mission). As well as the US Air Force, it has been purchased by the US Navy who have increased the fuel carried to stretch the flying time to 49 hours. It has also been used by Australia to prevent illegal fishing, presumably without the missles.
http://en.wikipedia.org/wiki/RQ-9_Predator_B

2. Intelligent Surveillance & Security Guard Robot
Intelligent Surveillance & Security Guard Robot
Catchy name. This Samsung robot is designed to protect major military bases and national borders - specifically the South-North Korea border (where it is currently in operation). It can detect and track targets from 4km during the day, and 2km at night with infra red cameras. It has a speaker to communicate with nearby personnel and can automatically ask intruders for a password once they are within 10 meters. If the password is failed then it can respond with an alarm, rubber bullets or something a bit more lethal. It isn’t clear from the articles if the response is automatic or not, but I am assuming a human controller needs to intervene before weapons are fired. Interestingly, the $200,000 units come fitted with an anti-theft alarm, possibly after Samsung read this.
http://www.samsungtechwin.com/product/features/dep/SSsystem_e/SSsystem.html

1. Talon
Talon
Foster-Miller builds the Talon Robot or Special Weapons Observation Reconnaissance Detection System (SWORDS) as it is also known. According to FM, the Talon has completed evaluation by the 5th Special Forces in Iraq and will be deployed in an armed reconnaissance role in 2007. It can be equipped with either machine guns, large caliber rifles and rocket launchers. It cannot engage targets autonomously, but instead relies on an operator to direct and fire the weapons.
http://www.defensereview.com/modules.php?name=News&file=article&sid=704

Some other notable bots that didn’t quite make the top 10 were:
Life-size Boxing Robot, Transformer Robot and Huge Russian Fighting robots (looks super-cool, and equally super-fake).

Introduction

Hi,

Before we get into the Meat, lets do some Greet.

My name is Gath (pronounced Garth, my parents were ‘arty’) Adams and I live in Melbourne, Australia. I create and manage websites for a living. These include:

http://sudoku.com.au - Sudoku puzzles

http://iwantthatflight.com.au - Airfare comparison to get the cheapest Australian airfares.

http://jigsawonline.net - Online jigsaws

http://kakuro.cc - Kakuro puzzles

http://freecrosswordpuzzles.com.au - Crosswords

As well as a bunch of other sites (70 or so, all up). Changing and adding to the sites, feedback from the visitors and working from home all make it a pretty sweet deal. Not terribly social, though. Which is why I also run (with my wife)…

Hidden Bars of Melbourne Tours

Every Thursday night we take a group of 10-20 people around the ‘Hidden’ bars of the Melbourne CBD. All the bars are in back alleys/rooftops/basements - really hard to find. Thursday is the new Friday for me, the tour gets me out of the house & is great fun.

You can check out some photos of the tour here.

Mostly on this blog, I’ll be going on about ways to make money on the web, as well as changes/improvements you can make to sites. But there needs to be some fun stuff too, and I’ll be reporting on some of the news in the bar scene of Melbourne.

Cheers,
Gath