# Monthly Archive for June, 2011

### Temperature Conversion Program in Java

Here's a simple program to convert temperatures between degrees Celcius, Fahrenheit and Kelvin written in Java. There's no GUI used here - all output is done via the command line.
The forumulae for the conversions were obtained from Temperature conversion forumlas on Wikipedia

File: Converter.java

```/**
* Conversion between temperatures in Celcius, Fahrenheit and Kelvin
* Uses conversion forumulas from the wikipedia:
* http://en.wikipedia.org/wiki/Temperature_conversion_formulas
* User: Steven
* Date: 27-Dec-2005
*/
public class Converter {
public Converter()
{

}

// Method to convert from degrees Celcius to degrees Fahrenheit
public static float celciusToFahrenheit(float degCelcius)
{
float degFahrenheit;
degFahrenheit = degCelcius * 9/5 + 32;
return degFahrenheit;
}

// Method to convert from degrees Fahrenheit to degrees Celcius
public static float fahrenheitToCelcius(float degFahrenheit)
{
float degCelcius;
degCelcius =  (degFahrenheit - 32) * 5/9;
return degCelcius;
}

// Method to convert from degrees Celcius to degrees Kelvin
public static float celciusToKelvin(float degCelcius)
{
float degKelvin;
degKelvin = degCelcius + 273.15f;
return degKelvin;
}

// Method to convert from degrees Kelvin to degrees Celcius
public static float kelvinToCelcius(float degKelvin)
{
float degCelcius;
degCelcius = degKelvin - 273.15f;
return degCelcius;
}

// Main method demonstrating usage of above methods
public static void main(String[] args)
{
System.out.print("100 degrees Celcius in Fahrenheit is: ");
System.out.println(celciusToFahrenheit(100));

System.out.print("-40 degrees Fahrenheit in Celcius is: ");
System.out.println(fahrenheitToCelcius(-40));

System.out.print("0 degrees Celcius in Kelvin is: ");
System.out.println(celciusToKelvin(0));

// to convert from Kelvin to Fahrenheit, combine two methods:
System.out.print("373.15 degrees Kelvin in Fahrenheit is: ");
System.out.println(celciusToFahrenheit(kelvinToCelcius(373.15f)));
}
}```

### How To Add A New Line in a C# or Visual Basic TextBox

If you're building a Windows Form Application, for example with C# or Visual Basic, then you may need to add a new line character, for example in a multiline TextBox. You do this using Enviroment.NewLine to insert the line break as follows:

`textBox1.Text="First Line" + Environment.NewLine + "Second Line";`

My preferred use is with the += operator in C#:

```textBox1.Text = "Line One";
textBox1.Text += Environment.NewLine;
textBox1.Text += "Line Two";```

This way, you can add extra lines of output to the TextBox as you require it.

References: Environment.NewLine on MSDN

### Generating Random Numbers in PHP

To create random numbers in PHP, you can use the rand() function call, which takes either zero or, optionally, two parameters determining the minimum and maximum random numbers (inclusive) that you'd like. If you don't specify a maximum then it will default to a value, RAND_MAX, set in the PHP configuration. The function returns an integer, generated "randomly." (Computers can't generate real random numbers, but this tries and is suitable for most purposes.)

You can get the value of RAND_MAX with the function getrandmax(). Then if you desire a random number larger than that, you have to specify the min and max bounds as parameters, eg rand(0, 100000) will return a random number between 0 and 100000 inclusive - so both 0 and 100000 can be returned.

For example:

```<!--?php // random number between 0 and RAND_MAX:
echo rand(); // output: 28688 (for example)
// random number between 37 and 50:
echo rand(37, 50); // output: 44
// find out the value of RAND_MAX:
echo getrandmax(); // output: 32767
// get a larger random number by specifying min and max:
echo rand(0, 1000000); // output: 351990
?>```

The output shown in the comments above is as an example. Since it is generating random numbers, the numbers generated are very likely to be be different every time.

It's possible to search Google for synonyms of a word, ie other words that Google thinks has the same meaning. To do this, simply precede the term by a tilde: ~, for example: ~blog will return results for terms such as weblog and blogger as well as those for blog. If you're only interested in the synonyms then you can exclude the original word in the usual way (ie by prefixing a minus sign: - to the term.

So ~blog -blog will return results for weblog, blogger and log but exclude those with the term blog.

This could be useful from a SEO perspective: if you are writing articles which target certain keywords, then it may be useful to target other words which Google associates with those keywords, too.

### Can the Virgin Media Superhub be wall mounted?

Virgin Media issue a new 'Superhub' with faster broadband. While older routers could be mounted on the wall, the new Superhub can't be due to the curved shape, and since the connectors are on the back, rather than one of the sides.

On the plus side though, it replaces the need for a separate cable modem, so saves a bit of space.

### Hide a hard drive from My Computer

Here's a little privacy hack for users running Windows XP. If you have a hard drive with some kind of mildly sensitive information on it, then you can stop it appearing in My Computer but you'll still be able to access it by installing a utility that Microsoft created, Tweak UI. It allows you to tweak many smaller settings which don't feature in any of the standard Windows preference menus. One such option is to control which drives appear when you open up My Computer and which don't.

Once you've installed Tweak UI then you have to find and expand the My Computer node in the tree menu on the left, then select Drives. Once you've done that, then you'll be shown drives A to Z (even if they're not actually drives you have - if you later install a hard drive W: then the setting here will determine if it is shown then), each with a check box next to it. Uncheck the drives that you don't want to be shown. To access the drive once you've done that then you'll need to enter the drive letter, eg C: in the address bar of Windows Explorer.
I should point out that this isn't a secure solution - it doesn't do anyone to actually stop anyone accessing information on the drive, however it can be useful to prevent friends and coworkers stumbling upon information you'd rather they don't see.

Although I've mentioned that this is a privacy tip, that's not what I use it for. I have a dual boot set up with another version of Windows, though XP is my main one, and the drive from that other install shows up in My Computer. I use Tweak UI to get rid of the drive letter there, purely for tidiness. I know I could just remove the drive from that version of Windows through the Administrative Tools in the Control Panel, but it is sometimes convenient to have access to it so I use this method. Tweak UI is good at resolving small annoyances such as that.

### Web Hosting Terminology

This article will define what various terms used by web hosting companies mean. It's not possible (and sometimes insulting to the reader) to cover everything so this will just cover the most commonly used and important terms.

Bandwidth (or Transfer or Data Transfer)
Bandwidth is the amount of traffic that is sent (and recieved) by your website. It is usually measured in gigabytes (GB), where 1 GB = 1024 megabytes (MB), and it is usually allocated on a monthly basis, for example you could have 5GB/month of bandwidth, which means that there is a limit of 5GB of files that can be downloaded from your site within a month. Bandwidth is only a concern if you host a lot of files, for example images or movies, as webpages are usually small file sizes.

Colocation Server (or Colocation Hosting)
This is similar to Dedicated Hosting (see below), except the server is owned by a customer and they pay the colocation hosting company to host the server for them - that involves paying a charge for bandwitch which the hosting company provide, the physical space which the server takes up and the power that the server uses. With this set up the customer is responsible for their hardware.

Control Panel
This is a web page with a usable interface which the customer can connect to when they want to tweak their hosting settings, view the transfer statistics, or utilise other features provided with their hosting.

Dedicated Server (or Dedicated Hosting)
This is a server which is owned by the hosting company which they will rent out to you for a monthly fee along with an allotment of bandwidth which you can use with it. This means that you get a whole server to yourself to use for what you desire, this is needed for scripts which use a lot of server resources (for example large message boards, for one of which I pay for a dedicated server). As a customer, you would have full control over the server and could change the configuration as required, a facility not available when you have to share a server with others. With a dedicated server, the web hosting company is responsible for the hardware as they own it, not the customer.

`Disk Space`
This is the amount of space on the server that you have to upload your files on, it's usually measured in MB or GB.

MySQL
This is a type of database (as is PostgreSQL) which allows the customer to store and retrieve information on the server. A lot of scripts require that a database is present to function.

Reseller Hosting
This is similar to Virtual Hosting (see below), but the customer is given the ability to create small hosting accounts of their own, which they can then give or sell to people if they desire. It usually allows the customer more features, bandwidth and diskspace than with normal virtual hosting.

Scripts
(eg PHP, Perl, ASP)
These are server side scripting languages which allow the customer to use already written scripts, or write their own, which provide additional features for the website and increased interactivity (for example message boards and content management systems).

Virtual Hosting (or Shared Hosting)
This is where a webhosting company puts many customers' webpages on the same server - so the server resources are shared amongst all the customers using it. This means that applications which cause a high server load are not suitable, and if one customer uses one then other customers will suffer.

### Dedicated Servers: A Summary

What is dedicated hosting?
This is a server which is owned by the hosting company which they will rent out to you for a monthly fee along with an allotment of bandwidth which you can use with it. This means that you get a whole server to yourself to use for what you desire, this is needed for scripts which use a lot of server resources (for example large message boards, for one of which I pay for a dedicated server). As a customer, you would have full control over the server and could change the configuration as required, a facility not available when you have to share a server with others. With a dedicated server, the web hosting company is responsible for the hardware as they own it, not the customer.

What are the advantages of it?
You can do anything you like on it that you like (although most hosts have acceptable use policies which state that illegal content is not allowed, and in some cases they prohibit connecting to IRC). This means that you can login to the server, set up programs as you desire, then run them without having to worry about the effects on server resources for other people. You can run games servers (for games such as Half-Life, etc), IRC servers or bots, or just run a web server which uses a lot of resources (and with a special setup which isn't found in shared hosting).

The main disadvantage is the cost, which will put many people off getting one. The cheapest seem to come at about \$50/month, and the most expensive cost thousands of dollars each month. The price can be reflective of the quality (such as the cost of running - or your host renting a space in - the datacentre, the hardware in the server, the technical support provided by your host and so on), alternatively it can just be an over inflated price for what is a poor quality product. It's important to compare the prices and packages offered from several companies before coming to a decision, also you should ask your friends if they have any opinions on the matter, and research information about the hosting companies and datacentres - are the constantly offline due to DDOS attacks? do they have a poor record of customer service?
Another disadvantage is the added responsibility involved in keeping the software on your server secure, for example you may have to update builds of apache, control panel software, etc as security holes are found.

Is it for me?
That depends, if you want to a game server then you'll need one - but it may be easier for you to buy one from a dedicated games server comapny, they know their stuff and would probably be able to install and configure the servers for you. However they would place restrictions on what you could do with the server and maybe the setup.
If you want to run a small IRC server, bot or bouncer then you would probably be easiest paying a smaller fee to hire one of those from an IRC or shell provider company, also you don't have to worry about restrictive datacentre AUPs which prohibit IRC use.
If you are starting a small web forum or site then you probably won't need one initially, wait until it grows and you can determine if you need the server to ensure further growth is ok.
Otherwise you could possibly look into getting one, you could even email hosting providers asking what package they think your site would require (although take their replies with a pinch of salt, they could try to sell you stuff you don't actually need).