Brian Clifton . com
Sitemap | About me
Loading...
Search:
 Menu 
| Code blog 
| Resources 

My Google Friend Connect library

Posted by Brian Clifton
Written February 6, 2010 at 16:10
When I redesigned my website, I wanted to have it more interactive. For example, being able to comment on anything, allowing for people to sign up for the website, and more. I chose to integrate with Google Friend Connect instead of reinventing the wheel. Here are a few useful links:

You can sign up for Friend Connect here:
http://www.google.com/friendconnect

I would also recommend checking out the Google social blog here:
http://googlesocialweb.blogspot.com/

If you get stuck, there's a developer forum here:
http://groups.google.com/group/google-friend-connect-developers/topics

With Friend Connect, you can create a community and Google provides you with code to put on your website.

Take my website here for example. If you look toward the top of this site, you'll notice the "Sign in using Google Friend Connect" button under the BrianClifton.com logo. Click it and you'll be able to sign into using Google, Twitter, AIM, etc.

Once you sign in, you can interact more with the website. You can respond to this blog post with feedback, go to the NES section and post a review where you can assign a star rating, the profile link at the top has information you can fill out about yourself, and you can sign up for a newsletter. Google wrote all of the code for you which makes the integration easy.

My website is written in C# using ASP.NET and hosted on a Windows shared account at GoDaddy.com, Inc. During my integration, I made a library that I think is very useful for integrating with GFC. I'm in the process of uploading this to code.google.com right now.

You can find my library here:
http://code.google.com/p/friendconnect-dotnet/

 

Simple object pool in C++

Posted by Brian Clifton
Written November 26, 2009 at 02:52
This is a simple object pool I use in my C++ code. It provides good performance and avoids memory fragmentation. I based the code on an example from Game Programming Gems 4.
#include <stdlib.h>
#include <list>

using namespace std;

class TestObject{
    public:
        int _TestValue;
        TestObject(void)
        {
            _TestValue = 0;
        }
};

template<class OPDataType> class ObjectPool{
    protected:
        OPDataType* _ObjectData;
        OPDataType** _ObjectFree;
        int _ObjectCount,_Top;

    protected:
        void FreeAll(void)
        {
            int i = (_ObjectCount-1);

            for(_Top=0;_Top<_ObjectCount;_Top++){
                _ObjectFree[_Top] = &_ObjectData[i--];
            }
            return;
        }
    public:
        void FreeInstance(OPDataType* instance)
        {
            if((instance) && (_Top<_ObjectCount) && (instance>=&_ObjectData[0]) && (instance<=&_ObjectData[_ObjectCount-1])){
                _ObjectFree[_Top++] = instance;
            }
            return;
        }

        OPDataType* NewInstance(void)
        {
            if(_Top>0){
                return(_ObjectFree[--_Top]);
            }
            return(0);
        }

        ObjectPool(int count)
        {
            _ObjectData = new OPDataType[count];
            _ObjectFree = new OPDataType*[count];

            _ObjectCount = count;

            FreeAll();
        }

        virtual ~ObjectPool(void)
        {
            delete[] _ObjectData;
            delete[] _ObjectFree;
        }
};

#define TEST_POOL_SIZE 200

int main(int argc,char** argv)
{
    ObjectPool<TestObject> pool(TEST_POOL_SIZE);
    list<TestObject*> objects;

    for(int i=0;i<TEST_POOL_SIZE;i++){
        TestObject* test = pool.NewInstance();
        test->_TestValue = rand();
        objects.push_back(test);
    }

    list<TestObject*>::iterator it = objects.begin();
    while(it != objects.end()){
        pool.FreeInstance( (*it) );
        ++it;
    }

    objects.clear();

    return(0);
}

 

Optimizing your website

Posted by Brian Clifton
Written November 26, 2009 at 00:28

I've found that making a website can be an endless process. Exactly when are you done? No matter how much thought you put into a design or many ideas you have, your website will end up evolving into something completely different over time.

Whatever shape or form your website starts to take, there are always ways to make your website better. You might be thinking... What do you mean better? By better, I mean easier for someone to stumble upon your website, use it, and find whatever they were looking for. Best of all, you don't need any artistic or design skills to make your website better.

I only started looking at improving my website a few months ago. After digging in and using some free tools, I've gotten a lot more traffic and made my website a lot better.

 

Integrate Google Analytics into your website

It's important to find out who visits your website so that you can try to provide the kind of stuff they want to see. Google Analytics is a great way to collect this info and it's really easy to add to your webpages.

Open this link in a new tab or window:
http://www.google.com/analytics/

When you go there, it wants you to sign in using a Google account. If you don't have one already, sign up for one (it takes less than a minute). After you login, you can create a new analytics account. You only need to provide Google with a few items:

  • Your website's URL ( e.g. http://brianclifton.com )
  • Account name for this site (e.g. My Website )
  • Your name ( e.g. Bubba Smith )
  • Your country (e.g. United States )

After that, just agree to the end user license and you're ready to begin. The next screen has some HTML you can copy and paste into your webpages. This is the actual tracking code (what talks Google Analytics).

Open up the HTML for your webpage. You can paste the code into the area shown below:

<html>
  <body>
    <h1>Welcome</h1>
    <div>Hello and welcome to my website</div>
    <!-- paste the snippet below this line -->

    <!-- paste the snippet above this line -->
  </body>
</html>

Pasting the snippet they provide you into that area is literally all you have to do (make sure to put it on all your webpages). Once it's in place, you can login and view a ton of information. Here are a couple cool examples of data you will have access to after you integrate with Google Analytics:

  • Which country or state people viewing your site are from. Is your site popular in Japan? Find out!
  • How many unique visitors come to your website ( by day / week / month )
  • How people found your website ( Google searches, links from another site, etc )
  • Which web browsers people are using

Sign up for webmaster tools (Bing, Google, Yahoo)

Each major search engine has a webmaster area. I would highly recommend signing up for this. For example, here are the two I am signed up with:
http://www.bing.com/webmaster/
http://www.google.com/webmasters/

Once you sign up for a webmaster site, you have to validate that you own the webpage by placing a meta tag in your HTML. It looks something like this:

<meta name="google-site-verification" content="ddffddsfasdfasdfasdf" />

Once that's in place, you can verify your site and it'll start collecting information for you. For example, you'll be able to see:

  • Crawler information for the search engine's bot (errors, stats, etc )
  • Popular keywords your site has
  • What searches found your site
  • View what the search bot sees when it parses your webpages

There's also links to help documents that can help you get the most out of your website. I recommend looking at any documentation you can get your hands on if it will help get traffic. I only listed Google and Bing above, but I would recommend checking out Yahoo's webmaster also.


Read the Google search engine optimization document

This is a really good document. You can download it from here:
http://googlewebmastercentral.blogspot.com/2008/11/googles-seo-starter-guide.html

This document covers a lot of the fundamentals of optimizing your site for search engines. More important than that though, I think the document really helps provide guidelines for making a good website.Some of the topics it covers that will help you make your website better include:

  • Use the title tag to give each webpage a unique and meaningful title
  • Use the meta description tag to describe a webpage
  • Use lowercase for URLs and webpage names
  • Pick easy to remember URLs (e.g. Stay away from www.website.com/zz4872/TEST/abc.aspx?OBJECTID=234&P=32)
  • Use a robots.txt
  • Have a sitemap.xml and submit it to every search engine

Conclusion

The info above has probably given you some really good food for thought. If you have any questions or need help, leave a comment on here or email me and I'll help you figure things out.

 

Handling NIC information on Windows

Posted by Brian Clifton
Written August 6, 2009 at 22:00
If you need to programmatically get info about the NIC, you can find it in the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}

You can enumerate through all of the sub-keys; they're labeled as 0000, 0001, 0002, etc. If you're on Windows Vista / Server 2008, be sure to catch exceptions because there is a sub-key called Properties that you will get an access violation on.

For example, in my Shuttle SG33G5, I have my primary NIC under a sub-key called 0004. I can tell it's my primary NIC because of the DriverDesc value. From this key, you can set duplex, buffer sizes, and other NIC driver settings.

Just as an example, lets say you want to set your NIC to be 100Mbps full duplex. Before you make an automated solution, you can see the values passed to the NIC driver in the sub-key called NDI under the sub-key Params. In my case, I would need to open this key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0004\Ndi\Params\*SpeedDuplex

There is a value here called default and it's set to 0. Looking at the sub-key called enum, there are some values I could use:
0 = Auto Negotiation
1 = 10 Mbps Half Duplex
2 = 10 Mbps Full Duplex
3 = 100 Mbps Half Duplex
4 = 100 Mbps Full Duplex

So when it's time for automating this, my code would:
1) Open this key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}
2) Go through each sub-key (0000,0001,0002...), until it finds a value DriverDesc called "Generic Marvell Yukon Chipset based Ethernet Controller".
3) I know for this card, the value 4 is 100Mbps. So I can set the value data for "*SpeedDuplex" to 4. The full path to this registry value is
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0004\*SpeedDuplex
4) After making the change you can restart your network interface by making a shell execute call to netsh.exe
netsh interface set interface "Local Area Connection" DISABLED
netsh interface set interface "Local Area Connection" ENABLED

This article is basically documentation of some code my friend Daymion wrote. You can probably achieve the same result with WMI, but it's a lot nastier to do that in C or C++.

 

Getting the current page name in ASP.NET

Posted by Brian Clifton
Written August 6, 2009 at 20:57
string strPage = Request.FilePath.ToLower();

 


Items per page: 5 | 10 | 25

 Previous   1 2 3 4 5 6   Next