Lighttpd

November 16, 08 by the programmer

I recently found out that lighttpd powers several popular Web 2.0 sites like YouTube, wikipedia and meebo.
It has to be a pretty good web server if such a big sites are using it.
I thought that they are on apache, but anyway I just wanted to share that with you.

I have to check that out and see how it goes

Will write in more details after I check it out.
If you want to check it out this is the URL:
http://www.lighttpd.net/

Remove multiple slashes anywhere in url using .htaccess

November 16, 08 by the programmer
Hello,
Sometimes a url can be accessed like this http://minanov.com//test.html.
The above url is the same as this one http://minanov.com/test.html, it points to the same content.
The search engines looks at this url as a duplicate content, which is not good and we have to eliminate it.
Sometimes urls with double slashes can be indexed by the search engines too. That is why a 301 redirect is added in the bellow code.
With 301 redirecting the url with double slashes to the url with single slashes we tell the search engine that the url is moved to the version with single slashes.
This is how to remove duplicate slashes from a url on a apache web servers using url rewriting and the .htaccess file.

 

Craete a .htaccess file in your root directory if you dont already have one.
Copy and paste the bellow code in the .htaccess file
Replace minanov.com with your domain name
Save the file and that’s it

 

#remove multiple slashes anywhere in url
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . http://minanov.com%1/%2 [R=301,L]

 

Programming rules: Always make a backup!

November 16, 08 by the programmer

Probably you all know this one, or you already expirienced it by yourself, but I noticed that I forget it sometimes and when at that moment the problems start to appear :), as always…

So it is very simple, before you make any change to your code, copy your old code to a safe location and continue working on it.

Someone will ask why…

Here are a couple of good reasons:

1. Sometimes your boss can change his mind and say: “I dont like that, can you return it as it was before”.

2. You push the new code and you suddenly find a bug, that is not so easy to debug but you already pushed it on the live server and a lot of people are visiting the site with the bug on it. In that case you have to act fast and revert to the old code.

3. While working on it you can realize that there is a better way of doing that, and you have to start from the beginning.

4. It is always good to have a backup of your code. I realized that when the hard drive died on couple of my friends :)

5. Sometimes you start working on something, and something more important comes out and you are in the middle of programming the less important stuff but you have to finish it before starting work on the new stuff.

I guess you can think of other reasons too, but I guess everyone agrees with this one.

Always make a backup of your code

How to strip HTML and PHP tags from text with PHP?

August 01, 08 by the programmer

If you ever need to clean a text from HTML or PHP tags you can do that very easy using the PHP function strip_tags. This is how you can use the function:

$text_without_html_and_php_tags = strip_tags(”text with html and php tags”);

You can find more about this function on the official php page http://www.php.net/strip_tags

How to list all installed plugins in Firefox?

August 01, 08 by the programmer

Today I wanted to check which version the flash plugin I have installed in my Firefox 3 browser.

I found a very interesting hidden page that Firefox has and lists all the installed plugins.

to view this page you have to write about:plugins in the location bar and you are done.

You will get a list with all the installed plugins like this:

Pictures partially displayed, tinyMCE problem, lightbox2 problem because of sendfile

July 25, 08 by the programmer

I had this problem a long time, I found a post I wrote from 2007-10-27.

The symptoms are

  1. Pictures displayed from the web server are not complete, only the top part of the picture is displayed, and the rest of the picture is black. This usually happens if the picture is very big (high resolution)
  2. Weird javascript problems. Problems occur only if the Javascript is served by the apache web server. The problem can gennerally occur with every static file.

This is the configuration I have:

Apache 2.0.54 on Windows XP Professional SP2
PHP 4.4.4
MySQL 4.1.12

I noticed the problem once when I was making a picture upload. I noticed that when I try to view the uploaded picture I could see only a part of the image, only the top part and never the full image.

This was pretty weird for me at the time, so I tried to see if the same is going to happen on the production server, because that was on my local server. Everything was ok on the production server so I did not bothered to fix the problem because it did not make any difference for me.


After a while I tried to install TinyMCE, a free HTML WYSIWYG editor, version 2.1.2. I run the examples from the desktop folder before uploading them to the local web server, and they were working great. After I saw that the examples were working I wanted to put them in my project and I copied all the files to the htdocs folder on the apache web server.

After I uploaded the files I tried to run the same example scripts but I noticed that they are not working, and that there was an error in firebug.

This is what the error was:

tinyMCE is not defined
tinyMCE.init({

example_advanced…. (line 8 )

missing : after case label
function TinyMCE_Engine(){var ua;this.majorVersion=”2″;this.minorVersion=”1.2″;t…

At that time I made a post to the tinyMCE support forum. This is the post. Nobody new why this error was appearing because nobody responded to my post.

So I tried to find a solution of the problem on the net, but none was available, at least I could not find it.
I also tried to upload the scritpts to my production server and supprisingly everything worked great there, so the scripts were ok, and I tried to be suspicious of my PHP, Apache confuguration. I thought that this might be some security issue or something similar.

I could not fix the problem so I decided not to use tinyMCE and I worked without a HTML WYSIWYG editor.


2 Days ago I a friend asked me to make him a web page with picture gallery I and I decided to use the lightbox2 javascript picture gallery (version v2.04 Released 3/09/08). It is very nice. It looks great. I downloaded the javascript files on my desktop.
I run the example files from my desktop and they were working great.
Again I copied the same files in the htdocs folder and after I run the examples I got an error in the firebug console.
This is what the error was:

syntax error
if (parent == do

prototype.js (line 4417)

uncaught exception: script.aculo.us requires the Prototype JavaScript framework >= 1.6.0

Object.extend is not a function
}, window.LightboxOptions || {});


lightbox.js (line 63)



I remembered that I had problems with tinyMCE, with the pictures display and now with lightbox2 and I somehow new that all those problems must be related.
I aslo noticed that the problem happens only i the files are static, like .js files of .jpg files, and if the files are big. Both the tinyMCE and lightbox have a lot of lines of javascript code.


At that moment I went to the tinyMCE Web site and downloaded the latest version (v 3_1_0_1_2). I wanted to see if the same problem will appear with the new version again. It did. I After I run the example files from the htdocs folder I got a javascript error in the firebug console.
This was the error:

missing ) in parenthetical
var tinymce={majorVersion:’3′,minorVersion:’1.0.1′,releaseDate:’2008-06-18′,_ini…

tiny_mce.js (line 1)

tinyMCE is not defined
tinyMCE.init({

skins.html (line 10)

Displaying pictures from http
Dispaying half images


I had a filling that the poblem must be in the php, apache configuration. Maybe something with the encodings, or the file size limitation or something similar. But it had to be with some confuration. So I decided that I have to solve this problem. I started to search the net for any similar cases and I found a post that is not very related to this problem but I decided to try.

I found this post: CSS and Javascript files not showing up when running Apache under Ubuntu on a flash drive? Read on. (Many thanks to the writer for writing the solution)

This guy had some similar problem, not displaying images, javascript files problem, so I thought I would give it a try.

As I found out later from the post apache by default uses a system command from the operating system called sendfile.

This command tries to deliver the static files to the browser, but because I am using Windows XP and it is “Windows operating system”, there must be some problem with it.

So I found out that Apache by default checks if the operating system supports sendfile syscall, and if it does then it uses it from the operating system, and if not it uses his own implementation of the functionality. Aslo I found out that there is a configuration property called EnableSendfile in the http.conf file, the Apache configuration file, which by default is on, which means use operating system function.

I set this configuration property to off, restarted Apache and BINGOOOOOOOOOOOOOO.

Everythig worked.

The pictures were showing up, both versions of the tinyMCE editor were working and the lightbox2 script was working. Finally after more that 9 months the problem is resolved :)

So if you have similar problems open httpd.conf, find “EnableSendfile” and set it to off like this:
EnableSendfile off


Dont forget to restart Apache after changing the configuration file

The symptoms as I mentioned before are

  1. Pictures displayed from the web server are not complete, only the top part of the picture is displayed, and the rest of the picture is black. This usually happens if the picture is very big (high resolution)
  2. Weird javascript problems. Problems occur only if the JavaScript is served by the apache web server.



More about EnableSendfile can be found here:

http://wiki.apache.org/httpd/SendfileNotImplemented

http://httpd.apache.org/docs/2.0/mod/core.html#enablesendfile


I hope this post will be useful to somebody with similar problems

Thank you



How to create rounded corners using css?

July 14, 08 by the programmer
CSS3 Offers a lot new possibilities for the designers and programmers. One of the new option is the ability to make rounded corners.

Unfortunately as always we have problems with Internet Explorer, it doesn’t support this feature, only Mozilla/Firefox and Safari 3 supports it.

Top left rounded corner:

Firefox: -moz-border-radius-topleft: 10px;

Safari: -webkit-border-top-left-radius: 10px;

Top right rounded corner

Firefox: -moz-border-radius-topright: 10px;

Safari: -webkit-border-top-right-radius: 10px;

Bottom left rounded corner

Firefox: -moz-border-radius-bottomleft: 10px;

Safari: -webkit-border-bottom-left-radius: 10px;

Bottom right rounded corner

Firefox: -moz-border-radius-bottomright: 10px;

Safari: -webkit-border-bottom-right-radius: 10px;

HAVING in SQL queries explained

July 12, 08 by the programmer

What is the “HAVING” keyword and what it is used for.

Because the WHERE keyword could not be used against aggregate functions (like SUM, COUNT…), HAVING was added to SQL so the results can be filtered by using aggregate functions as filter criteria

HAVING is always used with GROUP BY

Example:

SELECT product_name,SUM(product_quantity)
FROM products
GROUP BY product_name
HAVING SUM(product_quantity)>10000

Funny error message

July 12, 08 by the programmer

This one is good, while surfing the net I found some pages where some people were getting error messages like that one:

“Error: keyboard wasnt detected, press F1 to continue….”

Press F1 if you can :)

Dynamically position DIV with JavaScript?

July 12, 08 by the programmer

If you want to position a DIV element using javascript this is how you can do it:

Catch me if you can

<div id=”movable_div” style=”position:absolute; top:0px; left: 0px; width:100px; height:100px; background:#EAF3FA;” >Catch me if you can</div>

You can position the above DIV on any coordinates you want using the bellow JavaScrpt function:

Note that the style attribute must be there in order this to work.

function move_div(div_id, x, y){
var div = document.getElementById(div_id);
if(div){
div.style.left = x+”px”;
div.style.top = y+”px”;
}
}

The bellow code will move the above DIV to coordinates x:100. y:100 pixels

<script type=”text/javascript>

move_div(’movable_div’, 100, 100);

</script>