К основному контенту

Сообщения

Сообщения за 2008

Server Side Includes (SSI) adding a blank/empty line to HTML page

While creating a page that used server side includes, I ran into some very strange behavior. Right before each SSI, a blank line would appear on the page. It didn't have anything to do with margins or padding. It was just like an empty line appeared right out of nowhere, messing up the layout. First, I thought it was some problem with IIS and SSI, but I couldn't find anything there. After a few hours of frustration and trying the weirdest solutions I could think of, I started playing around with saving the include files with different file names. Well, when I got to the *.txt, I noticed that Visual Studio gives me a new option under "Save As"... its "Advanced Save Options". When I looked at the encoding of the file, it was set to "Unicode (UTF-8 with signature) - Codepage 65000". I then switched to "Unicode (UTF-8 without signature) - Codepage 65001", and the blank lines disappeared. It appears that Visual Studio picks an encoding wh...

Fixing invisible or disappearing text and double margins in Internet Explorer

This How-to applies to: Any version. This How-to is intended for: Integrators, Customizers Internet Explorer has a very serious bug when calculating the height of floating elements, which can cause elements to disappear. Here's a simple way to work around it in any layout, with a special convenience class for Plone - although the approach is valid for any CSS layout. The problem Displaying a page in Internet Explorer causes text to disappear, or elements to be wider than their proper width. There is not general way to fix this problem on a page-wide scale, so you have to test your pages in Internet Explorer and see if they exhibit this behaviour. If they do, you can apply a simple class to that element, and it will behave the way you intended again. Some examples Below are a couple of examples of the bug as they normally appear in Plone: The classic example of disappearing text in Internet Explorer. Here we see that the headline of the Plone welcome page is only visible when sele...

SQL WHERE clauses: Avoid CASE, use Boolean logic

As some of you may know, I recommend to avoid using CASE expressions in the WHERE clause of a query to express conditional logic. I prefer to have everything translated to simple ANDs, ORs and NOTs to keep things a) portable, b) easier to read and c) efficient. Learning some good boolean logic techniques will go a long way towards making your queries more efficient, and you won't need to rely on CASE's and other methods of doing conditional logic. First off, when I say “conditional logic”, I am talking about something like this: “If A then B” where A and B are both conditions. For example, in a WHERE clause, you might want to implement a condition like this: “If (@ReturnAll 1) THEN (EmpID = @EmpID)” To express this logic in the WHERE clause, many people might code it like this: WHERE EmpID = CASE WHEN @ReturnAll 1 THEN @EmpID ELSE EmpID END However, this is kind of counter-intuitive (why should we check that EmpID = EmpID ?) and can be really tough to implement when the cond...

Optimizing Conditional WHERE Clauses: Avoiding ORs and CASE Expressions

Often, we need to create a flexible stored procedure that returns data that is optionally filtered by some parameters. If you wish to apply a filter, you set the parameter to the necessary value, if not, you leave it null. This is pretty standard stuff, of course, that we can write fairly easily, without the need for dynamic SQL, like this: create procedure GetData @MinDate int = null, @MaxDate int = null, @MinAmount money = null, @MaxAmount money = null, @ProductCode varchar(200) = null, @CompanyID int as select * from Data where (@MinDate is null OR @MinDate (@MaxDate is null OR @MaxDate >= Date) and (@MinAmount is null OR @MinAmount >= Amount) and (@MaxAmount is null OR @MaxAmount (@ProductCode is null OR ProductCode = @ProductCode) and (@CompanyID is null OR CompanyID = @CompanyID) Note that we are using good boolean algebra as discussed here, and not using inefficient CASE or COALESCE() exp...

Fix title/alt attribute for tag

Часто сталкивался с проблемой, что редактора вставляют одинарную или двойную кавычку в заголовок, и когда его подставляешь в title или alt, то едет дизайн. Решение простое: Replace("\"", """) Replace("'", "'") Первая идея была: Replace("\"", """) Replace("'", "'") Но IE ее не понля :) Ссылка ниже ведет на таблицу в которой описаны специальные коды HTML для различных символов, встречающихся в HTML-страницах. Из таблицы были выброшены символы русского и английского алфавитов и цифры. Не все броузеры поддерживают некоторые коды, поэтому рекомендуется протестировать HTML-файл перед использованием. http://www.cubes.com.ua/documentation/index.php?page=articles/bl_htmlcodes

SQL SERVER - TRIM() Function

CREATE FUNCTION dbo.TRIM ( @string VARCHAR ( MAX )) RETURNS VARCHAR ( MAX ) BEGIN RETURN LTRIM ( RTRIM ( REPLACE (@string , CHAR(9) , '' ))) END GO CHAR(9) = TAB CHAR(10) = Line Feed CHAR(13) = Carriage Return This function also trims TABs, you can add Line Feed and Carriage Return replacement, if it is needed.

Где находится в Windows Vista файл hosts?

Нажмите + R, в окне выполнить вставте: \Windows\System32\drivers\etc Теперь Enter

Javascript Get or Set Checked Radio Value

// return the value of the radio button that is checked // return an empty string if none are checked, or // there are no radio buttons function getCheckedValue(radioObj) { if(!radioObj) return ""; var radioLength = radioObj.length; if(radioLength == undefined) if(radioObj.checked) return radioObj.value; else return ""; for(var i = 0; i if(radioObj[i].checked) { return radioObj[i].value; } } return ""; } // set the radio button with the given value as being checked // do nothing if there are no radio buttons // if the given value does not exist, all the radio buttons // are reset to unchecked function setCheckedValue(radioObj, newValue) { if(!radioObj) return; var radioLength = radioObj.length; if(radioLength == undefined) { radioObj.checked = (radioObj.value == newValue.toString()); return; } for(var i = 0; i radioObj[i].checked = false; if(radioObj[i].value == newValue.toString()) { radioObj[i].checked = true; ...

Fix the slow Firefox when using localhost

It turns out that the slowness is caused by an IPv6 issue with DNS and can easily be resolved by turning IPv6 support off in Firefox while doing localhost testing. To make the change, type about:config in the address bar, locate the network.dns.disableIPv6 setting and double-click on it to set it to true. This does the trick for the Firefox localhost issue on Vista and everything is running fast again.

Custom errors in classic ASP on IIS7 and Vista

Spent a few hours the other day trying to solve an issue I had with Vista and IIS7 using Classic ASP. Basically I couldn't get the 404 error to redirect to a custom page. I tried various methods but all failed. IIS6 was simple IIS7 just didn't work. The reason for doing this was to allow "friendly URLS" on IIS6. This is basically where you can have www.mysite.com/aboutus and it'll redirect to a dynamic URL. It's done using a meta tag that creates a friendly redirect AND using a custom 404 page. In IIS6 this is easy to setup, just specify your 404.asp page, and any requests that aren't found are redirected to:- 404.asp?404;http://{HTTP_HOST}:{SERVER_PORT}{HTTP_URL} with the {} values replaced obviously. Your page then picks out the relevant URL and redirects accordingly. Now in IIS7 I couldn't get this to work so eventually I found a work around. 1. Go to this page and download the URL Rewrite module 2. Install it and then against the site you want to ...