How to Ensure You Will Actually Get Paid as a Freelancer

As unemployment rates remain elevated in most developed countries, people with specific marketable skill sets, such as website development, graphic design and copy writing, have been applying those talents in the marketplace in the form of freelance work to supplement their income streams.

As a person that has done a lot of freelancing work in the past, I quickly that there is much more to being a one-man web development shop than actually creating websites. When you work as a freelancer, you are starting a small business and hiring yourself as an employee. This means that you need to get all appropriate licenses (such as a business license and a sales tax license) if your locality requires them and you may even want to incorporate your business down the line. You also need to keep a good track of your income and expenses using Quickbooks, Outright or Excel for tax purposes.

Because you are essentially starting a small business when you opt to become a freelancer, you want to make sure that your business actually makes money. Financial author Dave Ramsey is quoted as saying that a business that doesn’t make any money is a hobby. Almost everyone that does freelance work does so because they want the extra money from the projects that they complete, thus, it makes sense to engage in behavior that will cause your business to maximize the amount of money that you’ll make.

One of the major pitfalls that freelancers run into is that they fail to adequately manage the business aspect of their work. They focus on actually doing the work and ignore many of the business aspects that revolve around the work that they do, often resulting deals which leave the freelancer making much less than they were expecting to or even not getting paid at all.

As a freelancer, one of your top priorities should be getting paid by your clients. If you have ever read the “Clients From Hell” blog, you would quickly realize there are a lot of crazy people that want to hire you—people that will either try to short change you, pay you with some worthless goods or service that you don’t want, or won’t even pay you at all.

In order to make sure that you actually get paid, the first thing that you need to do is prequalify your clients. If a person comes to you and asks you to do work for them, but you don’t feel like they have their act together and don’t believe they can or will actually pay you, it’s okay to tell them that you can’t take their project. If it’s the first time that you’ve worked with the client, it’s not out of line to ask for business references.

You should also have a document signed by both you and your client that clearly outlines what work you will do, what work you will not do, when you will have the work done and how much you will be paid and when you will be paid. You should also have a clause in your work agreement about change requests and additions and how that will affect the price. I typically refer to this as a “scope statement” in the agreements that I make.

Here’s the text that I have use in my scope statements:

The website developed will be as described in the initial description and the “section specifics” section of this proposal. Additional minor features will likely be completed at no-charge. If any of the “upgrade” options are chosen, they will be completed at the price listed above. Additional major features/usability changes which are requested during system development will be billed at a cost of $XX per hour. Matthew Paulson has sole discretion as to what would constitute a ‘major’ and a ‘minor’ change. An estimate will be provided for any additional worked that is deemed ‘billable’ before it is performed.

If it’s the first time that you’re working with a particular client and don’t know them terribly well, you should definitely ask for a percentage of the payment up-front. Depending on the size of the project and how you feel about the customer, either 25% or 50% is an appropriate up-front price. If the client appears to be really sketchy, insist on full payment up-front or simply say no to the project.

You also need to make sure that you do a good job of invoicing. Once you have completed your project, send an invoice to your customer with the remaining balance. You can do this with a simple word document of which there are hundreds of templates online for, or using a more advanced online invoicing system.

When I email an invoice, I typically say something like, “Let me know when you send the check so that I know to look for it in the mail.” Using a phrase like this will help you know when your money should be arriving and give you a reference point in the event that the client is slow to pay. In most cases, you’ll be paid quickly, in cases that you don’t, call or email the client on a weekly basis asking them when you will receive payment. Consumer advocate Clark Howard suggests that freelancers visit the client in person if the client is slow to pay. He believes that in-person visits are more effective for collections.

In the event that you don’t get paid, you probably didn’t do the best job of pre-screening your client. You have the option of taking the client to a small claims court and will likely win a judgment against them, but collecting on that judgment only gives you a “license to hunt” and doesn’t necessarily mean that you will get your money right away or ever.

The three keys to making sure that you get paid for the work that you do as a freelancer are to pre-screen your clients, clearly communicate terms and stay on top of billing. If you are up-front about how much you are charging, when you should receive the money and what work you will do and will not do, make sure that you only work for good clients and stay on top invoicing and billing your clients, you will avoid the majority of the issues that would result in you not getting the money that you have rightfully earned.



Freelancing

How to Optimize Your WordPress Blog for Performance

WordPress is an excellent blogging/news website platform as a whole, but has been criticized for being a bit of a performance dog. One of my websites which is powered by WordPress receives between 100,000 and 200,000 unique visitors a month. I’ve gotten a few nasty emails from the two hosts that I’ve had the site on during the last year for taking up too much of the shared server’s CPU usage. Fortunately the poor performance of the base WordPress installation can be mitigated with a few different performance optimization plug-ins and techniques.

Here are a few things that I’ve done to get my WordPress installations’ performance in check:

Minimize Plug-In Usage - Many WordPress users, including myself, have the bad habit of running 20 to 30 different WordPress plug-ins at once. Each plug-in that you have installed adds to the amount of work that the server needs to do to load pages on your website. Keep the number of WordPress plug-ins that you have installed to a minimum.

One of the Plug-Ins that has been considered a “worst offender” is the popular All-In-One SEO Plug-in, so much so that DreamHost has banned its users from using the plug-in. Some would dispute the claim that it’s a performance nightmare, however you are probably better off to build your SEO optimizations into the template itself rather than using a third-party plug-in.

Word Press Super Cache Super Cache is a plug-in that creates static HTML files which will load for your users instead of dynamically generating post HTML on each page load. This plug-in is a great help for sites that get featured on social bookmarking sites or have a few popular articles that get hammered.

Super Cache also supports a more traditional caching method (the one that came with the “WP Cache” plugin) for servers which do not support Super Cache. The downside to the “cache” method is that it does require loading a PHP script, whereas the “super cache” method requires nothing in terms of executing server-side scripts on a cached page load.

Word Press Object Cache – WordPress has a built in object cache which was added in version 2.5. The “Object Cache” will cache the results of different database queries that WordPress makes. For example, when any of the pages on your site loads, it will need to populate the site’s blog-roll and any widgets from the database. By enabling the object cache, you can cache the results from queries, minimizing the amount of database queries that WordPress needs to make.

To enable the WordPress object cache on yours site, edit your WP.Config file and add “define(ENABLE_CACHE, true);” to your list of “defines”. This may be added by default to later versions of WordPress.

To read more about the Object Cache, read this article on NeoSmart.NET.

Optimize Your PHP.INI File – Optimizing your PHP configuration file can improve the performance of your site. ElliotBack.com has some suggestions about what changes you might want to make to your configuration file, which will disable some modules which may not be needed for your website. He also offers a link to this more complete guide to optimizing your PHP.INI File.

Use a PHP Compiler Cache – You can make use of a PHP Compiler cache which will save scripts in a compiled format so they are not being recompiled each time they’re called from a page load on WordPress. The compiler cache will save your PHP scripts, including your WordPress files in a compiled state, eliminating the overhead caused by the compilation of your PHP files. Two popular PHP compilers are  APC & eAccelerator that you may want to investigate, but it’s probably not worth it to go through the process of using these tools unless you have an extremely high traffic website.

Choose a Good Web Host – This won’t make your WordPress install run any faster, but choosing the right host from the get-go can minimize the need to spend a lot of time tweaking your site’s performance. Not all host are the same. Most hosts will shove you on a shared server with dozens of other websites, which isn’t a bad thing, because shared hosting allows you to get web hosting for much less than you would have had to if you bought your own web-server. The difference lies in how many websites a host will try to shove onto a single server.

Before choosing a web-host, search for the name of the host followed by “WordPress issues” or “Wordpress Problems” to see if current customers of the host are having performance issues with their WordPress sites.

Hardcode Values in Your Template – By default WordPress values use PHP functions on each page load to calculate the server path of where your template files are. Digging into WordPress suggests that you should replace these with hard-coded values to improve performance. We’re not sure how much of a benefit using hard-coded values will provide and probably isn’t necessary for smaller sites, but will probably provide some sort of assistance for sites with substantial traffic levels.

MySQL Database Optimization with PHPMyAdmin - Your web host probably provides you PHPMyAdmin access, which will allow you to run a built in optimization function on your tables. Weblog Tools suggests that going through the process will  provide a nice performance boost. EarnersBlog.com agrees that it’s also worth doing. It’s probably worth trying, but make sure to back up your database first.

Conclusion

More often than not, installing Super Cache and getting rid of un-necessary plug-ins will be more than enough to make 95% of sites run at more than acceptable performance levels. If you’ve got a large site, as in that you are receiving hundreds of thousands of unique visitors each month, then it probably makes sense to start looking at some of the other optimizations suggested in this article.

WordPress

How to Make Use of Namespaces in C# and Visual Basic .NET

If you’ve written any sort of software application of decent size, you’ll know that you need to structure your code, most often using object oriented design techniques, to keep your code-base manageable. Some languages such as Java and C# enable developers to write object-oriented applications relatively well out of the box without much extra work. Others, such as JavaScript, Classic ASP and PHP (without any frameworks attached), make users do a lot more work to keep their code base manageable.

One of the features that was included with C#/VB.NET is the idea of name-spaces, which are not necessarily a requirement to write object-oriented code, however do a a great job of creating a hierarchical class structure and generally keeping your classes, methods, enumerations, etc in non-spaghetti-code state.

What is a namespace?

A namespace can best be described as a collection of classes and enumerations.

An Example

Typically, you would want to put classes and enums together in a namespace that are related. For example, if you were considering making some C# code to represent the organization structure of a library, you might have a namespace for the library as a whole, then have sub-namespaces for different aspects of the library, such as the materials that can be rented out in a library, the library’s staff members, and its facilities.

Here’s what a hierarchical structure of namespaces might look like in a Library in C#

You’ll notice that name spaces can be hierarchically organized and that name spaces can contain both classes and enumerations. They can also hold delegates, interfaces and structs. They cannot directly include methods, which must be contained within a class.

Referencing a Class in a Namespace

If you were to create the class that we just made above and put it into a C# application (most likely in the app_code folder), this is how you would create some of the classes above:

AdministrationBuilding -  Library.Facilities.AdministrationBuilding thisBuilding = new Library.Facilities.AdministrationBuilding();

Journal – Library.Materials.Periodicals.Journal thisJournal = new Library.Materials.Periodicals.Journal();

BookType - Library.Materials.BookType thisType = new Library.Materials.BookType();

Making Good use of the Using Declaration

If you plan to make use of a namespace a lot on a particular form, web-form, or any other C#/VB file, you can import the namespace directly on the page much in the way that you might import one of the inherited namespaces under the “System” class.

When doing development, if you wanted to create a DataTable object, you would probably want to add “using System.Data;” to the top of your page so that you can reference the variable type by just using “DataTable ThisTable” rather than “System.Data.DataTable ThisTable”.

You can also do this with your own namespaces.

Here’s how you would import the “periodicals” namespace in C# –   using Library.Materials.Periodicals;

Here’s how you would import the “periodicals” namespace in VB.NET — Imports Library.Materials.Periodicals

Now, instead of creating a journal like we did above, we could simply write “Journal thisJournal = new Journal();” to create a new object of type Journal.

Here are a few other good resources on Namespaces:

C#, Visual Basic

Arvixe’s Customer Service Has Won Me Over

For years, I had been a DreamHost customer. I had their standard shared reseller hosting account that costs peanuts. Every few weeks my sites would crash hard when they had any remote amount of significant traffic. Eventually it got to the point where I was losing out on ad-revenue because of DreamHost’s inability to keep their servers in good shape. I decided that I’d had it with DreamHost’s constant down-time issues and started researching hosting companies.

Picking out a web-host is probably one of the most difficult tasks that a web-developer has, mostly because it’s difficult to determine what level of customer service they will provide after you are a customer. Eventually I settled upon Arvixe, because the reviews that I read online were much more positive than what other companies had. Most companies have pretty mixed reviews; even Arvixe has a few bad reviews floating online.

The best way to scope out a host ahead of time is to type “CompanyName Sucks” on Google. You can also read reviews and see if the host bothered to respond and offer to help customers that had bad experiences. You definitely want a high ratio of good reviews to bad reviews, but you’re still taking a bit of a guess as to whether or not the host will be any good.

I’ve been using Arvixe to power my two high traffic sites, AmericanConsumerNews.com and AmericanBankingNews.com for about 5 months now. The two sites together easily get 150,000 unique visitors per month and Arvixe’s servers handle the load just fine, even on the cheap shared hosting plan that they offer.

I’ve ran into two situations where’s I’ve needed customer support from Arvixe. The first time, AmericanBankingNews.com had 19,000 unique visitors in a day. The WordPress-based site had a couple of plug-ins that were misbehaving and sucked up the entirety of the server’s CPU. As a result, Arvixe shut the site down, sent me an email and told me why they did what they did and what plug-ins I needed to remove to prevent the problem. After taking the action that they suggested, they were more than happy to re-enable the site and the problem disappeared.

The second time I dealt with Arvixe’s customer service team was last week when the server that powers my ASP.NET websites went down. Apparently there was a hardware malfunction and the server had to be taken off-line. Arvixe had full-backup and replaced the server within a few hours. The company also had to take the server down early on a Sunday morning to do a file system check.  As the file system check took place, Arvixe provided hour by hour updates to let me know when my sites would be back up. The company even provided a 2-month credit because of the down-time that really wasn’t their fault to begin with.

I’ve been really impressed with Arvixe’s customer support so far, so, keep up the good work guys!

hosting

Facebook Goes Live with Bookmark Prompt

A couple of months ago, Facebook announced some ambitious changes to their API. We’re now starting to see some of the first of the newly announced features be released into the wild. A couple of weeks ago, Facebook added the ability for developers to ask prompt to bookmark their application. Previously, users were only able to add bookmarks using the “Add Bookmark” in Facebook’s taskbar.

Facebook’s Developer Wiki says that applications should only launch the prompt after a user clicks on a link, but it’s likely that those guidelines will be abused.

Here’s what the prompt looks like for the “Spay Day Online Pet Photo Contest” application that Factor 360 developed for the Humane Society of the United States:

bookmark:

Here’s how to load the prompt on an Facebook Application (Iframe) using XFBML:

First, you’ll want to make sure that you have the prerequisites ready so that you can use XFBML.

Then, make a hyperlink that calls an “AddBookmark” function that we’ll write. You could also do a submit button or anything else that would call a JavaScript function.

Remember to <a href=”#” onclick=”AddBookmark(); return false;”>Bookmark this Application!</a>

Then, use the following JavaScript to define the AddBookmark function.

<script type=”text/javascript”>
function AddBookmark() {
FB_RequireFeatures(["Connect"], function() {
FB.Facebook.init(‘APIKEY’, ‘xd_receiver.htm’);
FB.ensureInit(function() {
FB.Connect.showBookmarkDialog(callback);
});
});
}
function callback(post_id, exception) {
alert(‘bookmarked’);
}
</script>

Make sure to replace “API Key” with your application’s API Key. The “FB.ensureinit” function makes sure that the library has fully loaded before trying to execute it. The reference to “FB.Connect.showBookmarkDialog(callback);” is where the magic happens. the callback function occurs after the user has closed the dialog box. You could put just about anything you want in here. For this demonstration, I’ve just included a basic JavaScript alert.

In the next couple of months, Facebook will be launching a number of additional API changes, including the removal of classic application invites and the addition of sending messages Facebook’s Inbox from within Applications. Developers will also soon be able to get access to their user’s email address if they give permission. You can see other changes coming on Facebook’s Developer Roadmap.

Uncategorized

How to Build a Code Igniter Development and Testing Environment on Windows

I’ve been playing around with the Code Igniter Framework for PHP over the last couple of weeks, primarily because Net Tuts has a series of 6 high-quality screencasts showing off some basic functionality of the framework. Essentially, Code Igniter provides some additional functionality and provides a standardized means of creating pages and methods using the MVC framework. If you’re not used to MVC, it’s a bit of an adjustment, but it can have some benefits on the testing side of things.

If you plan on doing any Code Igniter work, you’re going to need some form of development environment for it. On the Net Tuts tutorial, the author uses Text Mate, which works pretty well as a Mac product, but I’ve found that PHP Eclipse is a bit better of a solution as a development environment on the windows side. You’ll also need to get a copy of WAMP setup, get the CodeIgniter files and configure CodeIgniter to look at the right path on your web-server as well as the correct database.

Here’s how to setup the ultimate development and test environment for Code Igniter in Windows

Step 1: Installing Wamp

The first thing you’ll need to do is get a copy of WAMP. This stands for “Windows Apache MySQL and PHP”. It essentially provides a set of web-development framework that combines all of the tools that you need for creating a PHP test-bed in a Windows environment. Since Joomla is based on PHP, WAMP is a perfect solution to run Joomla on top of. You can download the installation files from WampServer.com

You will also be asked about SMTP information. Unless you have a specific need to do anything that involves sending emails from your web-server, it’s safe to leave those blank. If you are developing contact forms or somethign that would require credentials, you can get those from your internet service provider.

Step 2: Testing WAMP

After getting WAMP installed, you’ll be given the option of letting it start up automatically or you can simply launch WAMP from the start menu. Once you have the WAMP client running, you can enable the web-server and database by right clicking on the icon and clicking “Start All Services”. To make sure that the environment is working properly, right click the icon and select “Local Host.”  If all is well, you’ll see a page that says “WAMPServer” that has a white-background.

wamp-first-steps

Step 3: Getting Code Igniter

Once you have WAMP running, you’ll want to grab a copy of the Code Ingiter files from the Code Igniter Website. They typically come in the form of a ZIP file. Take the files in the Zip File and extract them to a sub directory of your WAMP installation’s WWW directory. Typically WAMP’s WWW directory is located at “c:\wamp\www\”, so a good directory to put your files in might be c:\wamp\www\ci\”.

Step 4: Testing Code Igniter

The next thing that you want to do is to test out your copy of Code Igniter on WAMP and make sure that it’s running properly. You can do this by opening up your web-browser and navigating to “http://localhost/ci/” (assuming that you named your Code Igniter file “ci”). If it’s working, it should look like this:

code igniter welcome

Step 5: Configuring Code Igniter

Once you have code igniter working, you’ll want to make a few modifications to Code Igniter’s config file so that Code Igniter is properly configured and can access your database.

The first file  you want to modify is “config.php”, this is located in “/system/application/config/” relative to your root directory of code igniter, for us, that would be “C:\wamp\www\ci\system\application\config.”

On line 14, you’ll notice:

$config['base_url']    = “http://example.com/”;

We’ll want to change that URL to the URL of our code igniter install, so it should be:

$config['base_url']    = “http://localhost/ci”;

Step 6: Database Configuration

Finally, we’ll want to point Code Igniter at a database if we want to use one. Code Igniter by it self does not require a database, but if you want to do a project that requires database access, WAMP comes with MySQL Server, which will work just fine for a development environment.

To connect Code Igniter to a database, you’ll want to look at lines 40-43 of “database.php”, which is also located in Code Igniter’s config directory. We need to setup a username and password and choose which database we want to make use of. WAMP’s default MySQL username and password is “root” and nothing, so enter those in for your local environment. You’ll also want to make sure that your host name is set to localhost and that your database name is set to the database that you create.

$db['default']['hostname'] = “localhost”;
$db['default']['username'] = “root”;
$db['default']['password'] = “”;
$db['default']['database'] = “DATABASENAMEHERE”;

Step 7: Choosing an Editor

Right now, you have everything you need to start developing in Code Igniter, but you’re probably going to want some form of editor that will make your life a lot easier. The one I like to use is PHP Eclipse, which can be download from eclipse.org. Other editors you might want to try include TextPad, and TextMate.

Step 8: Making Your First Program

Now that your development and hosting environment is ready to go, you can start writing some code. To write your first “Hello World” program, head on over to Net Tuts and watch “CodeIgniter From Scratch: Day 1“.

Uncategorized

How to Post to Facebook’s “Stream” using Facebook Connect and XFBML

For my day job, I’ve been developing a facebook application to coincide with its annual SpayDay event. Developing the application has caused several headaches, but once I realized that the majority of the facebook integration wouldn’t happen from the Facebook Developer Toolkit (an ASP.NET Facebook Development Framework), and instead from JavaScript-based XFBML, life got a lot easier. Specifically, the application that I’m developing is an ASP.NET-based iframe application, which probably isn’t the best choice for a facebook application, but it’s what I’m familiar with, so it works.

Facebook recently announced that they are streamlining their primary integration points to the stream (users’ facebook wall posts) and to the inbox. As of writing this article, the inbox API isn’t out yet, but the StreamPublish function (the function that everyone is supposed to use to write to people’s streams and facebook walls), has been out for a while. For the purpose of this demonstration, we’ll be writing an XFBML function using FacebookConnect. Typically this would apply to IFrame Applications on Facebook.

Here’s how to implement posting to a Facebook user’s wall/stream using Facebook Connect.

First, there some prerequisites to place on your page before you can use XFMBL. Basically, it’s a couple of scripts that you need to reference which process the FBML and pass data back and forth to Facebook using a cross-domain receiver. You can learn how to add those scripts to your page here.

The next thing to do is to write a function that will call the XFBML, which will look something like this. Note that the specific text I used is for the SpayDay application, but it’s pretty easy to start making modifications to specific parts of the post.

    <script type="text/javascript">

        //post story function
        function PostStory() {

            //init facebook
            FB_RequireFeatures(["Connect"], function() {

                FB.Facebook.init('PLACE_YOUR_API_KEY_HERE', 'xd_receiver.htm');

                FB.ensureInit(function() {

                    var message = 'I support Bill The Aircraft Carrier in the SpayDay Online Photo Contest! Will you vote for Bill The Aircraft Carrier?';
                    var attachment = {
                        'name': 'Vote for Bill The Aircraft Carrier!',
                        'href': 'http://spayday.factor360.com/contest.html?page=viewInd&id=48082&contestId=2', 'caption': '{*actor*} supports Bill The Aircraft Carrier in the SpayDay Online Photo Contest!',
                        'description': 'Bill The Aircraft Carrier`s favorite thing to do is fight the Klingons, but sometimes gets in trouble because he/she likes to fight the Klingons. Bill The Aircraft Carrier makes me smile because... he has spock-like ears.',
                        "media": [{ "type": "image", "src": "http://spayday.factor360.com/calendar_contest/images/69839_1.jpg", "href": "http://spayday.factor360.com/contest.html?page=viewInd&id=48082&contestId=2"}]
                    };
                    var action_links = [{ 'text': 'Vote for Bill The Aircraft Carrier!', 'href': 'http://spayday.factor360.com/contest.html?page=viewInd&id=48082&contestId=2'}];
                    FB.Connect.streamPublish(message, attachment, action_links, null, "Share your support for Bill The Aircraft Carrier!", callback, false, null);
                });
            });
            function callback(post_id, exception) {
                alert('Wall Post Complete');
            }

}

</script>

A Few Notes:

Now that we have our function written, we simply need to call it. You can use hat with a plain old hyperlink:

<a href=’#onclick=‘PostStory(); return false;’>Post a story!</a>

That’s pretty much it. Once you get the hang of a few different XFBML functions, the rest come pretty easily. You should see something like this if all is well with your code:

post

One debugging hint. If nothing pops up at wall and you can’t get ANY XFBML to work, make sure to set your Facebook Connect URL to the same URL as your Facebook Application in your Application’s settings in the Developer Application.

Facebook

Fast and Efficient C# and Visual Basic String Concatenation

If you do any sort of web development work on the .NET platform, you are going to find yourself concatenating (connecting) strings together on a very regular basis. There are two ways to do this.

The first is with a traditional string concatenation, which would look something like this:

string MyString = String.Empty;
MyString = “Hello ” + “World”;

The second way, is using the StringBuilder library, which would look something like this:

StringBuilder MyString = new StringBuilder();
MyString.Append(“Hello “);
MyString.Append(“World”);

These two sets of code do basically the same thing, but is it preferable to use one over the other? It turns out, that the StringBuilder class is much, much more efficient when dealing with large sets of strings. For short strings, with fewer than five concatenations, chances are you’ll be better off with traditional string concatenation because you don’t have to instantiate a copy of the StringBuilder library, but for situations that you want to do a lot of string manipulation, you definitely want to use the StringBuilder library.

Here’s a synthetic test using C# and ASP.NET comparing the two:

        Trace.IsEnabled = true;

        StringBuilder StBuilder = new StringBuilder();
        Trace.Write(“String Builder Append Begin”);
        for (int x = 0; x < 10000; x++)
        {
            StBuilder.Append(“Testing123″);
        }
        Trace.Write(“String Builder Complete”);

        string stString = String.Empty;
        Trace.Write(“String Concatenation Beginning”);
        for (int x = 0; x < 10000; x++)
        {
            stString += “Testing123″;
        }
        Trace.Write(“String Concatenation Complete”);

The test concatenated the string 10,000 times. Although it’s a synthetic test, it shows that the StringBuilder class is substantially more efficient than the string class for concatenation. The string class concatenated the text in 5.292587 seconds. The StringBuilder class performed the same task in just 0.006142 seconds. In other words, the StringBuilder was over 850 times faster at concatenating the string than the string class was.

Now that’s a performance benefit!

ASP.NET, C#

ASP.NET Performance Tip: Remove Unnecessary Library References

Over the last few days, I’ve been scouring the web for techniques and strategies to optimize ASP.NET code so that it runs faster and more efficient, resulting in quicker load times. A lot of what I found was pretty standard advice, disable viewstate, use the StringBuilder for concatenation, disable tracing and use AJAX. One piece of advice that I didn’t find when searching was to be selective about the libraries that you reference.

By default, ASP.NET will add the following references to your page:

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

In a library that I was using, I was able to pair those down to these five libraries:

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

After removing the un-necessary libraries, the page load time decreased by nearly half of a second. If you were to do this with all of your libraries and pages, chances are you could see a pretty significant performance increase.

ASP.NET, C#

How to Display Your Twitter Feed using ASP.NET

UPDATE 3/23/2010 - Ricky from Twitterizer commented below noting that basic authentication will soon go away via Twitter and OAUTH will be required. Note that the code below will only work for a few months. We will post an updated code-example soon.

As I write this article, It’s about 75 degrees and Sunny outside. When I should be going out on a bike ride, instead I’ve opted to play with Twitterizer (an ASP.NET Twitter Library). Twitterizer is an ASP.NET library that lets you interact with the Twitter API using easy to use objects and methods. It will work with any of the .NET variants (C#, VB, J#, Windows Forms, ASP.NET, WPF, etc). I added the functionality into the 360 Web Content Management System and I thought I’d share with you how I did it.

Here’s how to retrieve twitter feeds in ASP.NET

(1) Get a copy of the Twitterizer Library

First, you’ll need to get a copy of the Twitterizer Library from Google’s Codebase. The download is pretty small and contains only the application library (DLL) you need. Create a new website in ASP.NET and extract the twitterizer library to the /bin/ folder so that you can use it.  Once you have it placed in your /bin/ folder, add a “using” reference to the library in the header of your page.

using Twitterizer.Framework;

(2) Create a “Twitter” object and Retrieve Your Status Updates.

The library contains a few different objects that you can create. A “Twitter” object is the most generic object that you can create. Creating an instance of this object using your username and password gives you all the functionality you would normally have in Twitter, but instead of using the Twitter web interface, you’re using C# or Visual Basic. First, we’ll need to instantiate the object, and then get a collection of status updates from your account.

Twitter thisUser = new Twitter(“UserNameHere”, “PasswordHere”);
TwitterStatusCollection thisCollection = thisUser.Status.UserTimeline();

(3) Loop Through Your Status Updates and Generate Some HTML

The “TwitterStatusCollection” object type is a list of “TwitterStatus” objects, so you can use a foreach loop and go through your most recent status updates. You’ll notice in the code below that I also do some basic work with the time of the status update to generate a hyperlink to the page of the status, similar to what Twitter does.

string TwitterCode = “”;
foreach (TwitterStatus thisStatus in thisCollection)
{

TimeSpan thisSpan = new TimeSpan();
thisSpan = DateTime.Now.Subtract(thisStatus.Created);

string TimeBetween = “”;
if (thisSpan.Days > 0) { TimeBetween = thisSpan.Days.ToString() + ” days ago”; }
else if (thisSpan.Hours > 0) { TimeBetween = thisSpan.Days.ToString() + ” hours ago”;}
else if (thisSpan.Minutes > 0) { TimeBetween = thisSpan.Days.ToString() + ” minutes ago”;}
else if (thisSpan.Seconds > 0) { TimeBetween = thisSpan.Days.ToString() + ” seconds ago”;}

TwitterCode += “<div class=’TwitterStatus’>” + thisStatus.Text + ” <a href=’http://twitter.com/” + thisStatus.TwitterUser.UserName + “/status/” + thisStatus.ID + “‘>” + TimeBetween + “</a></div>”;
}
(4) Display Your Tweets

You now have a string with your most recent twitter status updates that you can display on the page using a simple Response.Write() or you can display it in a label. You can see a variation of this code running on the “Twitter” page for the 360 Web Content Management System.

You can also download a copy of my sample code.

ASP.NET, C#, Content Management Systems, Social Media, Visual Basic