MongoDB certification from 10gen May 28, 2013 No Comments

Just got my certificate from 10gen that I have successfully completed “M101P: MongoDB for Developers” course (https://education.10gen.com). I really enjoyed those 6 weeks of education. Thank you for such a great course!

Screen Shot 2013-05-28 at 1.03.00 PM

Upgrading MySQL to 5.6.10 on mac os and fixing mysql2 gem February 21, 2013 4 Comments

After updating MySQL to 5.6.10 in mac os with homebrew package manager you can notice that mysql2 gem will show such an error:

“Incorrect MySQL client library version! This gem was compiled for 5.5.29 but the client library is 5.6.10″

To fix it you can rebuild mysql2 with new mysql version config with the following command:

sudo ARCHFLAGS=”-arch x86_64″ gem install mysql2 — –with-mysql-config=/usr/local/bin/mysql_config

Please also notice that your /usr/local/bin/mysql_config can have different location. So probably need to find where your mysql version is installed with find or which command.

Using WYISIWYG editors for content management February 14, 2013 No Comments

WYSIWYG editor is easy way to give clients to edit content on dynamic sites. But then another problem appears – how to explain clients that they need to fit styles of content they create in editor to the current style of the site. How to explain that Sans Comic isn’t very nice choose if site uses Arial font mostly. Or that using more than 5 different colors to highlight “important lines” of content isn’t good at all.

So the solution is to remove all bad choices/functions from WYSIWYG editor itself. So clients do not see it at all and have no choice except using predefined styles.

I will walk through some of the popular settings. I will use CKEditor () as WYSIWYG editor. But those rules can be easily apply to other editors as well.

  1. Remove HTML form elements because usually clients should edit only content and not forms.
  2. Leave Paste from Word and Paste as plain text. Those features are nice to avoid unnecessary HTML tags that MS Word application create when you copy/paste content from. It looks really bad inside sources. So teach your clients how to use those features. HTML code on the site will be much cleaner.
  3. Remove smiles :) Because it usually doesn’t fit any serious design.
  4. Remove ability to create div containers. It’s not necessary for clients to have neither.
  5. Ability to insert IFRAME tags is also tricky. Your clients can just insert too much in IFRAME. And site will look awful.
  6. Remove ability to select fonts because each site should have predefined fonts for all elements like headers, paragraphs etc. So no need to allow clients to select different fonts. It will just break the design. The same about font size.
  7. Set custom styles. You can read about it here –
  8. Set custom format.
  9. Keep only predefined colors in Font and Background colour pallets and turn of more colors option:
    CKEDITOR.editorConfig = function(config)
    {
      config.colorButton_colors = ’1563a1,f68121,bd2833,000000′;
      config.colorButton_enableMore = false;
    }

Leading zero in CSV files data October 24, 2012 No Comments

Comma separated values files are used widely to create reports or export data from applications. It’s easy to generate such files and use them. You can use MS Excel or Open Office or Google Docs. Thought there is one issue can appear if you have numbers with leading zero which are important do not miss. For example, part numbers. If you open such CSV files in MS Excel it will convert numbers with leading zero to numbers and remove leading zero.

The solution will be to notify MS Excel to interpret data as string but not as number. You can do it in the following format:

,”=””[value]“””,

So this number will be shown with leading zero as text but not as number:

,”=””033434″””,

Row number in MySQL September 10, 2012 No Comments

I’ve faced recently with a problem to update positions of accounts ordered by some criteria right in MySQL database. I needed it for accounts rating so I will know in what rating position each account is placed on in the current time. And it reminded me ROW_NUMBER() in MS SQL Server which isn’t available unfortunately in MySQL. Of course we can use procedures and cursors in MySQL though the performance isn’t good at all. And of course there is more nice solution for it – using variable in SQL query. Let’s check it:

SET @row_num = 0;
SELECT @row_num := @row_num + 1 AS row_number, id FROM accounts ORDER BY yield DESC;

So we have variable counter right in our SQL query and that’s cool. What if we what to make this shorter? In just one SQL sentence. Here you are:

SELECT @row_num := @row_num + 1 AS row_number, a.id FROM accounts a, (SELECT @row_num := 0) AS r ORDER BY a.yield DESC;

What we did is just placed @row_num initialisation as sub query. Next I needed to save new account positions in accounts table so I will know what position each account is placed on. And we can do this all in the same query!

UPDATE accounts x
INNER JOIN (SELECT @row_num := @row_num + 1 AS row_number, a.id FROM accounts a, (SELECT @row_num := 0) AS r ORDER BY a.yield DESC) y ON x.id = y.id
SET x.position = y.row_number;

In summary this query do ranking accounts by yield and save each account position in accounts table in position column. And no cursors or other loops are required!

You can notice that row number will stop working in correct order if you use joins in your SQL query. For instance, we need to join accounts and clients tables and still return rank:

SELECT @row_num := @row_num + 1 AS row_number, a.id FROM accounts a
INNER JOIN clients c ON c.id = a.client_id, (SELECT @row_num := 0) AS r
WHERE c.`status` = ‘active’
ORDER BY a.yield DESC

This will show row_number out of order. I guess because order is made after joining tables and calculating row_number variable. Well it’s easy to fix with sub-query:

SELECT @row_num := @row_num + 1 AS row_number, id
FROM accounts, (SELECT @row_num := 0) AS r
WHERE id IN (SELECT a.id FROM accounts a INNER JOIN clients c ON c.id = a.client_id WHERE c.`status` = ‘active’)
ORDER BY yield DESC

Bug with Broken Ordered list in IE9 June 11, 2011 9 Comments

Recently I’ve been working with ordered lists. And found strange behavior in IE9 when one ordered list is hiding and new one is showing – instead of usual order 1,2,3.. it showed all zeros. And it actually doesn’t matter what list style type you choose – decimal, lower alpha or other.

Let me show you an example in case you do not have the same problem as well on your project:

<html>
<head>
<script type="text/javascript">
window.onload = function() {
        document.getElementById(‘lnk-one’).onclick = function() {
                document.getElementById(‘two’).style.display = ‘none’;
                document.getElementById(‘one’).style.display = ‘block’;
        };
        document.getElementById(‘lnk-two’).onclick = function() {
                document.getElementById(‘one’).style.display = ‘none’;
                document.getElementById(‘two’).style.display = ‘block’;
        };
}
</script>
</head>
<body>
<a href="#" id="lnk-one">One</a> <a href="#" id="lnk-two">Two</a>
<div id="one">
        <ol>
                <li>one</li>
                <li>two</li>
        </ol>
</div>
<div id="two" style="display:none">
        <ol>
                <li>three</li>
                <li>four</li>
        </ol>
</div>
</body>
</html>

If you open this HTML in IE9 and then click at first on “Two” link and then “One” you will see the issue:

Looks like order breaks in IE9 when one order is hidding then appears new one and then previous one is showing again. To quickly fix you need to place empty element say <div> in the end of the body and when you show ordered list just assing space to this element inner html. Here you are previous html page fixed:

<html>
<head>
<script type="text/javascript">
window.onload = function() {
        document.getElementById(‘lnk-one’).onclick = function() {
                document.getElementById(‘two’).style.display = ‘none’;
                document.getElementById(‘one’).style.display = ‘block’;
                document.getElementById(‘empty’).innerHTML = ‘ ‘;
        };
        document.getElementById(‘lnk-two’).onclick = function() {
                document.getElementById(‘one’).style.display = ‘none’;
                document.getElementById(‘two’).style.display = ‘block’;
                document.getElementById(‘empty’).innerHTML = ‘ ‘;
        };
}
</script>
</head>
<body>
<a href="#" id="lnk-one">One</a> <a href="#" id="lnk-two">Two</a>
<div id="one">
        <ol>
                <li>one</li>
                <li>two</li>
        </ol>
</div>
<div id="two" style="display:none">
        <ol>
                <li>three</li>
                <li>four</li>
        </ol>
</div>
<div id="empty"></div>
</body>
</html>

It’s important to place empty <div> after ordered lists. If you place it before – it won’t work.

OpenInviter and UTF8 encoding January 17, 2011 3 Comments

If you need to import contacts from other services there is quite good cheap solution for PHP – open source library www.openinviter.net. It supports a huge amount of services and that’s awesome.

There is nice auto-installer and documentation. Here I just want to discuss an issue that you can experience – incorrect encoding of russian contact names.

To solve it replace in OpenInviter base class the following line:

$name=trim((!empty($arrayImport[‘first_name’])?$arrayImport[‘first_name’]:false).‘ ‘.(!empty($arrayImport[‘middle_name’])?$arrayImport[‘middle_name’]:false).‘ ‘.(!empty($arrayImport[‘last_name’])?$arrayImport[‘last_name’]:false).‘ ‘.(!empty($arrayImport[‘nickname’])?$arrayImport[‘nickname’]:false));

with

$name=utf8_decode(trim((!empty($arrayImport[‘first_name’])?$arrayImport[‘first_name’]:false).‘ ‘.(!empty($arrayImport[‘middle_name’])?$arrayImport[‘middle_name’]:false).‘ ‘.(!empty($arrayImport[‘last_name’])?$arrayImport[‘last_name’]:false).‘ ‘.(!empty($arrayImport[‘nickname’])?$arrayImport[‘nickname’]:false)));

The array declaration difference between Firefox and IE JavaScript interpreter May 21, 2010 2 Comments

Found interesting difference in array declaration between FF and IE. For example, if leave comma (,) after all elements in array there will be different size of array as a result:

var arr = [1,2,3,];
document.write(arr.length);

As a result in Firefox and Safari it will write “3″ but in IE it will be “4″.

2010 Ukraine State Holidays May 2, 2010 No Comments

Always forget to remind clients about state holidays in Ukraine at least one week before. So decided to create the calendar for 2010 which includes all state holidays in Ukraine. Those days the Projestic team will be out of the office. If you work with development centers in Ukraine find attached calendar file.

2010 Ukraine State Holidays

Using arrays in form element names July 27, 2009 2 Comments

Sometimes there is variable number of similar elements on a form. For example, phone numbers. To iterate all filled values on the server it will be nice to use arrays. And form element naming allow it:

<form method="post">
<input type="text" name="phone[0]" />
<input type="text" name="phone[1]" />

</form>

Using PHP it’s easy to iterate through those values now:

foreach ($_POST[‘phone’] as phone) {
// do something with phone, save in the database
}

But how to access those values with JavaScript? In case we need to validate required fields, for example. It’s easy to suppose that document.forms[0].phone[0].value returns value. Actually no. In this case we need to use document.forms[0].elements array and access by key:

alert(document.forms[0].elements["phone[0]"].value);

Using arrays in form element naming allows us to control the variable number of form elements. For example, we can add link “Add another phone” and when user clicks on it add new <input type=”text” name=”phone[2]” /> field. And we do not need to change anything in PHP code because it will iterate all values that we have passed to the server.