Front-end engineering and so on

30 January 2012

Magento 1.6.1 setup doesn't work if you have wrong date/time on server

I've spent around one day trying to fix following error message from Magento after clean installation on CentOS 6.2 under VirtualBox:
"Illegal scheme supplied, only alphanumeric characters are permitted"

Another symptom: database table core_config_data contains only 2 rows. Something broken in installation process...

Problem source: Web-setup wizard of Magento was run in browser on workstation. Workstation and VM had different date/time. You ask me why? Because: I didn't install VBox Addons in CentOS and I restored snapshots with frozen time (1h, 2h, 1d before now)
Somehow Magento 1.6.1 setup can't complete process successfully in such case. I assume this issue could appear if you have wrong date/time on real server.

Guys, do not repeat my mistake :-)

30 December 2010

getCookie() example from w3schools defines extra global variables

I've found following peace of code in our code base and it made me not happy:
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}

What's wrong? This function defines 2 global variables: c_start and c_end.

Author should learn how to use var keyword in JavaScript. But 10 minutes later I found following page and realized that it's just copy-paste from very popular website:
http://www.w3schools.com/JS/js_cookies.asp

Really not good. W3schools have to fix it. People doesn't learn JS, they just do copy-paste.

23 December 2010

RAID 0 vs. RAID 1 on AMD SB770 motherboard chipset

Few weeks ago I've installed second hard drive into my home PC and configured RAID 1 with using motherboard chipset (AMD SB770). I can't say that I saw some real performance boost. PC was working as usual. I think boost had place, but it had totally psychological nature and only in my mind. Because 1w ago I tested performance of raid array. So, with 2 disks it gave me 102MB/sec avg read speed (I used HD Tune). I removed 1 disk from array - It's RAID 1, I can do that! :) And tested again... Wow! 100MB/sec! Second disc gives nothing. Only second copy of data. It doesn't speed up disk subsystem.

I read a lot about RAID arrays, types, reliability, performance. And found that not all RAID 1 implementations do distributed read requests in order to increase read speed. The main idea of RAID 1 is redundancy. So, my motherboard's chipset supports RAID 1. It just supports it. Only essential functions. There is no double read speed. Probably other vendors implement this feature, but not AMD.

Today I've tried RAID 0. In short words it gives significant speed up according to HD Tune. Average speed of read is 216MB/sec. It's just benchmark, let's see how it performs on home PC. And yes, I know that my data is under double risk now :)

P.S. I can't get rid of idea of buying discrete sata raid controller.
P.S.S. During usage of RAID 1 I've found that Linux sees raid as 2 separated disks: sda & sdb (at least Gentoo Linux from installation CD). I think it requires proprietary drivers.

10 September 2010

Принцип взаимокомпенсации ошибок

При четном количестве ошибок в коде программа работает, ибо ошибки друг друга компенсируют.
Нельзя удалять по одной ошибке, только парами…

13 June 2010

Habrahabr: Мысли вслух о протоколе X

Кто бы мог подумать, что протокол X11 не развивается 23 года? Честное слово, я и не задумывался об этом :) Рекомендую к прочтению всем любителям ОС Linux.

http://habrahabr.ru/blogs/linux/96305/
(Осторожно, статья создает ложное впечатление, о том что мир Linux в опасности)

14 May 2010

IE + navigator.cookieEnabled => security warning

Has anybody seen messages from IE with following text after adding peace of JavaScript to the page?
"This page has an unspecified potential security risk. Would you like to continue?"
- Yes/No
I was very surprised when received this message. There is no special exceptions of "Permission denied" kind and also you can't handle it via using window.onerror event. The source of this warning was in the usage of navigator.cookieEnabled property. I just needed to know whether cookies are enabled.
I fixed it by using small workaround: create cookie and try to read it. In case of disabled cookies you will no be able to read it.
function cookiesEnabled() {
var name = "__test_cookie__";
document.cookie = name;
return (document.cookie.indexOf(name) != -1);
}
Honestly saying that was not default IE browser. IE was used as a component in another software to render web-pages. I assume it's running in some specific security/privacy mode.

20 March 2010

IIS6: How to add new ServerBinding with PowerShell 1.0

Few day ago I needed to write automation script which will add new domain to existing site in IIS6 with using PowerShell. I already developed several scripts to automate different operations with using WMI interface. So, obviously I decided to use WMI again.
It looks like pretty simple task - just to add new item to ServerBindings array in IIS website configuration object. But I spent near 3 hours to get to working script. You can found different samples in C#, but nothing completely working on PowerShell 1.0 + WMI.

Main issues:
  1. You can't add new item to $site.ServerBinding, because it is read only list. But you can replace it. You have to act in following order:
    • create generic list
    • copy all existing bindings to it
    • add new binding
    • convert to array and replace existing list of bindings
  2. You can't simply create new list item by calling code like "New-Object -type ServerBinding", because you don't know actual class name (it derived from System.Management.ManagementBaseObject). You even can't clone existing binding, because there is no method .Clone()
    You should use classes ManagementScope, ManagementPath and ManagementClass from System.Management namespace to create new binging.

Source code:


function AddServerBinding($siteName, $hostName, $port, $ip) {
    function _New-GenericList {
        param ([Type]$Type)

        $base = [System.Collections.Generic.List``1]
        $qt = $base.MakeGenericType(@($Type))
        New-Object $qt
    }
   
    function _New-ServerBinding {
        $scope = new-object -type System.Management.ManagementScope("\\.\root\MicrosoftIISV2")
        $scope.Connect()
        $managementPath = new-object -type System.Management.ManagementPath("ServerBinding")
        $classBinding = new-object -type System.Management.ManagementClass($scope, $managementPath, $null)
        return $classBinding.CreateInstance()
    }

    # get web site configuration
    $site = Get-WMIObject -query "select * from IIsWebServerSetting where ServerComment='$siteName'" -namespace "root\microsoftiisv2"

    # create list of bindings
    $bindings = _New-GenericList -Type System.Object # If it doesn't work, change the type to System.Management.ManagementBaseObject
   
    # copy old bindings
    foreach ($item in $site.ServerBindings) {
        $bindings.Add($item)
    }

    # add new binding
    $newBinding = _New-ServerBinding
    $newBinding.hostName = $hostName
    $newBinding.port = $port
    $bindings.Add($newBinding)

    # save site configuration
    $site.ServerBindings = $bindings.ToArray()
    $site.Put
()
}

 

Usage example:

AddServerBinding "SampleWebSite" "www.example.com" 80 $null

 

Source code as dedicated page >>

Profile

My Photo
Kyiv, Ukraine
Dev Team Lead, Scrum Master