How to point your Naked domain to an AWS Instance

The answer is to use Elastic IP Address, If your instance(the one you want to point your naked domain like example.com to) is already assigned an Elastic IP address, just update your domain’s A record to point it to this IP address. If you dont have an elastic ip address mapped to your instance, then you can follow check the AWS documentation on how to do assign an Elastic IP address to your instance.

What is Naked domain ?

Naked domain is the domain name with out the www subdomain that is example.com instead of http://www.example.com, this is usually helpful when a website administrator want to give the users the flexibility to visit their website without typing the www.

There are many websites that does this, and this can be achieved either by pointing the A record directly to the IP address where the website is hosted or using a placeholder IP and redirecting all the web request to the www url.

Drawbacks of pointing naked domains to a web application

  • Pointing your domain name to a web application is known to cause issues with SMTP servers and may impact mail delivery for that domain name.
  • Hard coding an IP address to your website address also might not be scalable.

Micro Performance optimisation using If-Else

This post is actually a question I asked on Stackoverflow,

The question is Which performs better if or if-else ?, this might seem to be a silly question for a few because of 2 reasons.

  • If block will have relatively less lines of code, if both the blocks are having the same code, it is apparently a matter of commonsense.
  • And if they are not having the same code then we should not compare them in the first place

So Which one actually performs better, well lets look into the  results

When Condition is true, the If Block took 1700 milliseconds to execute the 1000000 iterations, where as the if-else block took only 1688 milliseconds

When the conditions fails, the if scored 1677 Milliseconds which is still a bit late than the If-Else block’s 1664 Milliseconds

So the results  say that If-Else performs better than If and guess according to most of SO posters the If-Else block is more readable too

Sql Query to get domain Name from email column

The following T-SQL Query will retrieve anything that is after the @ symbol, the query can be very useful for retrieving the domain of an email address

Domain name availability search using Whois information in C#

Programmatically searching for domain name availability is easier than I expected, all we have to do is get the Whois information for the domain name that we are looking for, and look for a specific text inside the Whois response.

I have already written a post on how to write a C# class to get whois information, you can go over there if you want more information on Whois, but if you just want the class name you can find it below and you can also find the complete source code at the links that I have provided.

Domain Search Code

Whois Information

Usefull links

This post is originally published on coderbuddy.wordpress.com.

C# Code to get Whois information of a domain name

What is Whois ?
Whois is a protocol to fetch the registered users of a internet resource such as a domain name or an IP block, it is documented in RFC 3912.

Whois information can be used to know some basic information about a domian name like the person or the organization it is registered to, registration & expiry date etc.,

One of the popular use case for the whois information is to check the availability of a domain name, you can read more about this in my other post.

The protocol
The whois protocol is a pretty straight forward TCP based query response protocol, each TLD or top level domain(example .com, .net, .org, etc., ) will have a whois server that will listen on the port number 43 for the queries, Once a request is received the server will check its internal database for the domain name details and return the information in the response, the availability of a domain name in a particular TLD can be identified from the whois information returned, the structure of the whois might differ from server to server.

The protocol can be explained simply as follows

Connect to the service host
   TCP: service port 43 decimal
Send a single "command", ending with a new line character(ASCII CR and then ASCII LF)
Receive information in response to the command line.  The
server closes its connections as soon as the output is
finished.

Implementation In C#
To get the Whois information of any domain, we need 3 parameters

  1. Domain name
  2. Record type, which is “domain”
  3. The whois server address for the TLD of the given domain name

A collection of Whois server list is maintained by nirsoft.net which we can use to determine the correct Whois server for a given domain name based on its TLD

Once we get this, all we have to do is connect to the server on port 43 using TCP and send the query as combination of the text “domain” and your domain name, seperated by a single space character ” “, your query should always end with a new line character.

You can get the whois information by just calling the Whois.Lookup method with your domain name as parameter as shown in the code below.

Note
Please note that this is implementation works only “.com” TLD domains, you have to change the server name to make it work for other TLD’s, you can find the implementation which works with different TLD’s in the github project I linked below

Usefull links

This post is originally published on coderbuddy.wordpress.com.

C# code to publish, delete, retrieve tweets using oauth

The following C#.net class can be used to update statuses, delete, retweet statuses, obtain information regarding a particular status and any body who retweeted a particular status using status id.

This class implements all the methods that are under the “Tweets Resources” section in Twitter API documentation

This class file uses OAuth implementation by shannon whitley (for more information see my previous post Implementing oauth twitter search in C# and JSON).

You can download the complete source code along with this class from https://sites.google.com/site/coderbuddy/downloads/TwitterAPI.zip?attredirects=0&d=1

Implementing oauth twitter search in C# and JSON

To implement twitter search in C# that uses oauth for authentication, first we need a C# oauth implementation, and a JSON parser for extracting results. For oauth implementation I’m using Twitter oAuth with .NET by Shannon whitley and for parsing the results JSON parser by Procurious and i have to say that this post is just a bit refined implementation of Parsing Twitter JSON data in C# by Jamie’s Digital Blog.

To get started with twitter needs you to authenticate your application before you could use twitter API’s search feature, to authenticate an application needs to initialize a oAuthTwitter object so that it is accessible through out the class like

Now since we have obtained the authentication we can use this oAuth to search twitter

Now we have the 100 search results stored in a string result in JSON format, we will use JSON parser for extracting the values of each tweet

You can download the complete source code along with oauth and JSON parser implementations from https://sites.google.com/site/coderbuddy/myReserach.zip?attredirects=0&d=1

You may need to make some modifications to the code like providing the consumer key and consumer secret before working with the code

Simple way to create a barcode generator

I was searching for some source code to create an OCR reader in C#.net and luckily found this amazing article on codeproject, I don’t want to even try rewriting the article as it was such superbly written, If you are looking for an easiest way to create a barcode generator in C#.net, goto http://www.codeproject.com/KB/cpp/wsbarcode.aspx

C# class to check for internet Connection

I found this piece of code on the internet, the author of this code is Tamer Oz.

C# simple class to convert a URL into acceptable windows file name

Hi, i was working on a project that takes screen-shots of web pages that are loaded in to Internet Explorer browser.As per the clients requirement, I need to save the screen-shot of a web page using the later ‘s URL.
I searched the web to find some help, but found nothing that matches my criteria, then i decided it do it my own way, write your own class file for converting a URL into an acceptable windows filename.
here is the code that will change a URL into a filename.

To use the code, copy this code into your project, and declare an object of the class and call the ConvertToWindowsFileName method.