Nov 19, 2007

harm of the indian code

if($pay == 3){ $pay = 3; }
else{ $pay = $pay; }

If it's "three" - let it be :)

Nov 17, 2007

vertical block in HTML and CSS

I met a task: to create a vertical image (line of repetitive images) starting under a header of a page and ending at the bottom.
If the window size of the browser changes the line should still hit the end of the page and no vertical rollers should appear.

After spending a day I found a solution. Take a look at the vertical bar to the left:



HTML:

<div id="vertical"><div></div></div>

CSS:

body{
height: 100%;
}
div#vertical{
position: absolute;
top: 0px;
height: 100%;
width: 56px;
overflow: hidden;
}
div#vertical div{
background-image: url('/images/vertical_bg.gif');
background-repeat: repeat-y;
margin-top: 212px;
height: 100%;
}


Explanation.
Here I use two DIVs, one in another.
The first has a full-page height.
Inner DIV has a background image and shifted relatively to the parent one with a "margin-top" style parameter.
"overflow: hidden" parameter of the outer DIV cuts the outstanding edges of the inner DIV and the browser does not have a vertical scrolling.
This way it always fits the page heights and does not cover the header.

The outer DIV has an "absolute" positioning.
Of course, I should remember to reserve the space to the left for all elements on the page with a "margin-left" or a "left" CSS parameter.

Nov 15, 2007

VPS - a good choice for hosting new web projects

It is convenient to run a web project on a personal server rather then on a public hosting. Reasons are:
  • Custom configuration - developer can provide a more productive and efficient solution not limited by compatibility requirements;
  • Full (root) access - convenience in management;
  • Security - in most public hostings people can access files and databases of each other, with is not good in many cases;
  • No limits - host as many web sites as you want, run your own email and DNS services, etc.
The main drawback of a dedicated server is it's cost. The fee for renting a normal dedicated server in the US is about $100 per month. For new web projects that are serving no users it means wasting money - the server capacity will not be consumed.

The solution is to use a Virtual Private Server. It feels almost like a dedicated server with a full access, but much cheaper because a real physical machine serves many VPS.

You can find many providers offering VPS from $15 to $45 per month.
Disadvantages are:
* Low memory limits (usually 64-256 Mb)
* Disk subsystem is usually overloaded and very slow
Rest is fine - processor is not loaded usually, and the bandwidth allowed is more then enough.
So you'd better use caching wherever you can and not run beyond your RAM limit cause swap is very slow. If you do that - your sites will be running as fast as they would on a dedicated server.

In the future posts I will describe how I am setting up a full-functional and productive web service on a cheap VPS with low memory consumption.