Saturday, August 21, 2010

Z-Index problem with IE

I spent couple of hours to find the solution of this bug, so I just post it here hope it can help somebody else.

The problem is introduced here http://www.quirksmode.org/bugreports/archives/2006/01/Explorer_z_index_bug.html

and here
http://therealcrisp.xs4all.nl/meuk/IE-zindexbug.html

Some of the solutions proposed are here:
http://brenelz.com/blog/squish-the-internet-explorer-z-index-bug/
http://systembash.com/content/css-z-index-internet-explorer/

What really worked for me was the combination of two solution above, set position:relative to the containing divs and give each containing div higher value of z-index of the contained one.

Case example :

<div style="z-index:5; position:relative">

    <div style="z-index:4">

        <div style="z-index:3">

        </div>

    </div>

</div>

<div style="z-index:2; position:relative">

    <div style="z-index:1">

    </div>

</div>


For the code above, we should be able to see the div with z-index 3 on top of the divs positioned after it (z-index 2 and 1).

Monday, August 16, 2010

MySQL (No data - zero rows fetched, selected, or processed)

Trying execute a sp in unit test, the tester stop because a one warning (No data - zero rows fetched, selected, or processed), the sp is rigth, but when try run return a error that we will see below.

Ex:

DELIMITER $$
DROP PROCEDURE IF EXISTS `sp_test` $$
CREATE PROCEDURE `sp_test`()
BEGIN
DECLARE v_employee_id INT;
SELECT id INTO v_employee_id
FROM employee
WHERE name = 'Ozahata';
SELECT CONCAT('The id is ', v_employee_id);
END $$
DELIMITER ;

execute this and calling (call sp_test();) will return:
+-------------------------------------+
| CONCAT('The id is ', v_employee_id) |
+-------------------------------------+
| NULL |
+-------------------------------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

See the warning: (show warnings;)
+---------+------+-----------------------------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------------------------+
| Warning | 1329 | No data - zero rows fetched, selected, or processed |
+---------+------+-----------------------------------------------------+
1 row in set (0.00 sec)

This happend because not found a information in the select and try put into a variable.

To fix you need execute like the sp below.

DELIMITER $$
DROP PROCEDURE IF EXISTS `sp_test` $$
CREATE PROCEDURE `sp_test`()
BEGIN
DECLARE v_employee_id INT;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_employee_id=0;
SELECT id INTO v_employee_id
FROM employee
WHERE name = 'Ozahata';
SELECT CONCAT('The id is ', v_employee_id);
END $$
DELIMITER ;

will have the result:

+-------------------------------------+
| CONCAT('The id is ', v_employee_id) |
+-------------------------------------+
| The id is 0 |
+-------------------------------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Back to work. ;)

Tuesday, May 11, 2010

Convert query result to dictionary like json in Python

If you wish get a result of a query but like to return each row like a dictionary {Field name: value, ...} inside a array, you can make in a single line:

query_result = [ dict(line) for line in [ zip([ column[0] for column in cursor.description ], row) for row in cursor.fetchall() ] ]

I will try explain the line.

The cursor.fetchall() will return the row, but we don't know the name of field, so to get this information we need request to a cursor.description to give me the fields.
The cursor.description have more then a name of field, so we use a column[0] to get the name of field.
To give a list of columns we use a for to give a sequence to me :
[ column[0] for column in cursor.description ]

Now we need give the name for each field and a value returned in a row, for this we use a function zip, but we can't forget that each row need be in a sequence resulted a this command :
[ zip([ column[0] for column in cursor.description ], row) for row in cursor.fetchall() ]

This will result a sequence line:
[ [(Field, value), (Field, value), ...],  [(Field, value), (Field, value), ...], ]

Finally we convert this lines to a dictionary using the function dict(). resulting the line above.

this is a example (In this case I use the mysql connection):

try:
# Load the connection
connection = MySQLdb.Connection(host='host_name', user='user_name', passwd='password', db='db')
cursor = connection.cursor()
cursor.execute(query)
query_result = [ dict(line) for line in [zip([ column[0] for column in cursor.description], row) for row in cursor.fetchall()] ]
print query_result
except Exception, e:
print "Error [%r]" % (e)
sys.exit(1)
finally:
if cursor:
cursor.close()


NOTE: This will not result a JSON result is only a sequence of dictionary that will be like JSON if you use a simple result (date will return like: datetime.datetime(2010, 4, 23, 14, 44, 6))

Tuesday, January 12, 2010

Erlang YAWS now supports WebSockets

http://yaws.hyber.org/websockets.yaws
http://armstrongonsoftware.blogspot.com/2009/12/comet-is-dead-long-live-websockets.html

Friday, November 27, 2009

Code highlighting in Blogger

I just posted an article which demonstrate code highlighting in blogger. I get the highlighting feature from here: http://code.google.com/p/google-code-prettify/

Additional Reference : http://lukabloga.blogspot.com/2008/10/to-test-new-highlighting.html

Hope you enjoy it.

SVN::Notify::HTML::ColorDiff modification

We are using SVN to save our works and hooking a post-commit script which one of the function is to send e-mail regarding the changes that had just made. We are using the wonderful SVN::Notify, a perl application to do the job. It already have the functionality to produce a beautifully diff colored HTML email using the SVN::Notify::HTML::ColorDiff module as the handler.

However, since we are using web based Google Apps Gmail interface as our email client, the HTML was not rendered nicely because the CSS is not applied inside the interface. We need to change the CSS to the inline style. And then I found a patch done here. Because it is a direct hack, I want it to be more generic that the user can choose the inline style or not, then I modified a little bit more. I added optional parameter --css-inline to generate CSS style directly inline with the HTML tags. I had submitted the changes to the original author hoping he will include this option in the next revision. Just in case, I also put it here.

Snippets to add the additional parameter:

package SVN::Notify::HTML;

# $Id: HTML.pm 4617 2009-03-19 17:04:53Z david $

use strict;
use HTML::Entities;
use SVN::Notify ();

$SVN::Notify::HTML::VERSION = '2.79';
@SVN::Notify::HTML::ISA = qw(SVN::Notify);

__PACKAGE__->register_attributes(
    linkize   => 'linkize',
    css_url   => 'css-url=s',
    wrap_log  => 'wrap-log',
    css_inline => 'css-inline',
);

You may download the full source below:

Friday, November 13, 2009

[Linux] Extract files from command-line

Elixir for the lazy...

http://lightlinux.blogspot.com/2009/11/uncompress-files-from-cli.html

Saturday, October 17, 2009

Screen and Vim (and Skype) for Remote Pair Programming

I don't know if everybody follows VoiceTechnology Google Group:

http://www.linux.com/archive/feature/56443


Original Post:

2009/10/17 Fabrício

Sent to you by Fabrício via Google Reader:

via Gustavo Dutra by Gustavo Dutra on 10/10/09

Bem, é notável o crescimento das metodologias ágeis de desenvolvimento de software. Uma das práticas que me agrada muito, é a programação em pares (pair programming). É bem perceptível, a um longo prazo, a diferença que faz essa prática. Navegando pela internet, como um marujo sem rumo, encontrei um post falando sobre Remote Pair Programming. Parece meio estranho, porque o XP (eXtreme Programming) faz alusão a uma dupla programar em um único computador, com um único teclado e um único mouse.

Então, vamos tentar simular este ambiente utilizando 4 ferramentas simples:

  • screen
  • ssh
  • vim
  • skype

Destas, só o skype não é open-source. Mas é interessante manter uma conversa verbal, pois conversas escritas podem desviar o foco da programação, que é bem mais rápida e precisa do que a escrita, que pode deixar brechas para má interpretações. A conversa verbal consegue interromper o programador ao mesmo tempo em que escreve, corrigindo-o ou questionando-o.

Conectados no skype, basta decidir em qual máquina será o desenvolvimento. Esta, por sua vez, terá que ter um servidor ssh. Ela será o host da programação. Será necessário, também, nesta máquina, ter instalado o screen, que é um programa que possibilita criar ’sessões’ no terminal.

Host

screen -S PairProgramming

Parece que nada mudou, mas você está numa sessão do screen chamada PairProgramming.

Precione CTRL+a e digite:

:multiuser on

Pressione CTRL+a novamente e digite:

:acladd usuarioclient

Tudo que você ver nesta sessão, será visto pelo outro usuário (usuarioclient) que se conectará nela.

Então, abra o vim, pois será necessário um edito de textos de verdade :D , e se divirta:

vim /caminho/arquivo

Client

ssh usuarioclient@host
screen -x usuariohost/PairProgramming

Pronto! Agora você está acessando a mesma seção! Tudo que o usuáriohost fizer, o usuárioclient enxergará e vice-versa.

Agora, basta descutir a tarefa via Skype e programar. As atualizações são em tempo real, ou seja, aparecem ao mesmo tempo que são escritos, digo… depende da conexão, mas não é um grande problema.

Caso seja necessário que o usuarioclient não possa modificar o código, apenas assitir e dar pitacos, o usuáriohost deve pressionar CTRL+A e digitar:

:aclchg usuarioclient -w #

Eu ainda vou programar assim, depois digo a experiência.

Referências

Thursday, September 24, 2009

Six smart and cost-effective ways to train employees

I received this article, and found interesting, not only for management, but for any employee in general. The ideas of discussion forums, blogging, and volunteering (among others) seem nice way to improve yourself, in many ways.

Worth reading: Six smart and cost-effective ways to train employees

(sent to me by Lin)

Wednesday, September 2, 2009

Using google chat translator bots in group

Well, this is not related to programming but our fellow Bruno told me to put here and I can finally be out of the list of persons that never put something here!

In google chat, there are "bots" that you can invite, like below:

en2ja@bot.talk.google.com : english to japanese
en2pt@bot.talk.google.com : english to portuguese

The interesting trick is that you can invite them in a group chat, and
making them work as a real time translators.

This is very useful for example when 2 persons of different native languages
need to chat using english.
If a japanese and a brazilian need to chat, you can call en2ja@ and ja2en@ and
form a group chat of 4. The japanese guy can write in japanese and the brazilian guy can
write in english.
Of course, the translation is not perfect, but it helps.