<?xml version='1.0' encoding='ISO-8859-1'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-2460456040562366745</id><updated>2009-02-12T18:28:12.924-02:00</updated><title type='text'>Sopa de Blogs!</title><subtitle type='html'>O blog da Sopa de Tags!</subtitle><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2460456040562366745/posts/default'/><link rel='alternate' type='text/html' href='http://www.sopadetags.com.br/blog/'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.sopadetags.com.br/blog/atom.xml'/><author><name>sopa de tags</name><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2460456040562366745.post-7448785459708905471</id><published>2009-02-12T18:24:00.004-02:00</published><updated>2009-02-12T18:28:12.931-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='portfolio'/><category scheme='http://www.blogger.com/atom/ns#' term='site'/><title type='text'>Novo site para o portfolio: BIOINFO, v2</title><content type='html'>Acabei de botar no ar a nova versão do site do Grupo de Bioinformática Estrutural, Centro de Biotecnologia/UFRGS.&lt;br /&gt;&lt;br /&gt;Dessa vez o desafio foi maior: usar código válido em PHP 4.3 e incluir uma modalidade bilíngue automática, além de acomodar vários elementos da versão anterior do site. Como dizem por aí: &lt;span style="font-weight:bold;"&gt;do not redesign, realign&lt;/span&gt;!&lt;br /&gt;&lt;br /&gt;Vejam por vocês mesmos: &lt;a href="http://www.cbiot.ufrgs.br/bioinfo/"&gt;http://www.cbiot.ufrgs.br/bioinfo/&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/2460456040562366745/7448785459708905471/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://www.sopadetags.com.br/blog/2009/02/novo-site-para-o-portfolio-bioinfo-v2.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2460456040562366745/posts/default/7448785459708905471'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2460456040562366745/posts/default/7448785459708905471'/><link rel='alternate' type='text/html' href='http://www.sopadetags.com.br/blog/2009/02/novo-site-para-o-portfolio-bioinfo-v2.html' title='Novo site para o portfolio: BIOINFO, v2'/><author><name>sopa de tags</name><email>noreply@blogger.com</email></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2460456040562366745.post-8593742672012437494</id><published>2009-02-05T22:13:00.003-02:00</published><updated>2009-02-05T22:16:24.202-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C-Sharp'/><category scheme='http://www.blogger.com/atom/ns#' term='código'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='CPF'/><category scheme='http://www.blogger.com/atom/ns#' term='validação'/><title type='text'>C#: validando CPF</title><content type='html'>Posto abaixo um código que eu adaptei de algum lugar da web. Só me lembro que estava em javascript. Acho que o original é do Thiago Prado. Eu portei e dei uma melhorada mais estética no código. E espero que ele se auto-explique, como sempre.&lt;br /&gt;&lt;br /&gt;Eu gostei do código do Thiago porque ele usa Arrays em vez de milhares de substrings.&lt;br /&gt;&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;public static Boolean CPF(String cpfvalue)&lt;br /&gt;{&lt;br /&gt; // some variables&lt;br /&gt; Int32 dv, calcdv, sum, position;&lt;br /&gt;&lt;br /&gt; // declares the cpf array&lt;br /&gt; int[] cpfarray = new int[11];&lt;br /&gt;&lt;br /&gt; // conversion to int and retrieves the dv&lt;br /&gt; dv = Int32.Parse(cpfvalue.Substring(9, 2));&lt;br /&gt;&lt;br /&gt; // populates the array with the first 8 CPF values&lt;br /&gt; for (int i = 0; i &lt;= 8; i++)&lt;br /&gt; {&lt;br /&gt;  cpfarray[i] = Int32.Parse(cpfvalue.Substring(i, 1));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; // calculates the 1st digit&lt;br /&gt; position = 10; sum = 0;&lt;br /&gt; for (int i = 0; i &lt;= 8; i++)&lt;br /&gt; {&lt;br /&gt;  sum += cpfarray[i] * position;&lt;br /&gt;  Console.WriteLine(sum.ToString());&lt;br /&gt;  --position;&lt;br /&gt; }&lt;br /&gt; cpfarray[9] = sum % 11;&lt;br /&gt; if(cpfarray[9] &lt; 2) { cpfarray[9] = 0; }&lt;br /&gt; else { cpfarray[9] = 11 - cpfarray[9]; }&lt;br /&gt;&lt;br /&gt; // now calculates the 2nd digit&lt;br /&gt; position = 11; sum = 0;&lt;br /&gt; for (int i = 0; i &lt;= 9; i++)&lt;br /&gt; {&lt;br /&gt;  sum += cpfarray[i] * position;&lt;br /&gt;  --position;&lt;br /&gt; }&lt;br /&gt; cpfarray[10] = sum % 11;&lt;br /&gt; if(cpfarray[10] &lt; 2) { cpfarray[10] = 0; }&lt;br /&gt; else { cpfarray[10] = 11 - cpfarray[10]; }&lt;br /&gt;&lt;br /&gt; calcdv = cpfarray[9] * 10 + cpfarray[10];&lt;br /&gt;&lt;br /&gt; if(calcdv == dv) { return true; }&lt;br /&gt; else { return false; }&lt;br /&gt;} // end CPF&lt;br /&gt;&lt;/tt&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/2460456040562366745/8593742672012437494/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://www.sopadetags.com.br/blog/2009/02/c-validando-cpf.html#comment-form' title='1 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2460456040562366745/posts/default/8593742672012437494'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2460456040562366745/posts/default/8593742672012437494'/><link rel='alternate' type='text/html' href='http://www.sopadetags.com.br/blog/2009/02/c-validando-cpf.html' title='C#: validando CPF'/><author><name>sopa de tags</name><email>noreply@blogger.com</email></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2460456040562366745.post-3110778662181694546</id><published>2009-01-29T10:19:00.004-02:00</published><updated>2009-01-29T10:39:11.217-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='código'/><title type='text'>Criando GUIDs com PHP?</title><content type='html'>Essa é uma pergunta meio velha já. Mas não há uma resposta satisatória para ela, pelo menos no meu ponto de vista. Uma solução que resolva todos os problemas em todas as plataformas. Aponto as soluções que pesquisei e achei abaixo:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;1. Para quem roda PHP no Windows&lt;/span&gt;&lt;br /&gt;Essa é fácil. Desfaça-se do trabalho duro e deixe o &lt;a href="http://en.wikipedia.org/wiki/Component_Object_Model"&gt;Component Object Model&lt;/a&gt; fazer o serviço pra você, em estrondosa (1) linha de código.&lt;br /&gt;&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;$guid = com_create_guid();&lt;br /&gt;&lt;/tt&gt;&lt;br /&gt;&lt;br /&gt;A vantagem desse método, para quem tem Windows como servidor, é que o GUID gerado é pseudo-sequencial (o que ajuda muito quando usa-se um GUID como chave primária de um banco de dados).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;2. PHP em qualquer plataforma com MySQL&lt;/span&gt;&lt;br /&gt;MySQL é uma coisa linda de Deus, assim como a Avaiana de Pau. E tem uma série de funções internas que podem facilitar o trabalho do programador preguiçoso (ou esperto, como diria Larry Wall). Por exemplo, o MySQL também tem uma função chamada &lt;tt&gt; GUID() &lt;/tt&gt; que gera um identificador pseudo-sequencial, usando o endereço MAC da placa de rede em Linux e FreeBSD e a data/hora do computador em Windows, Mac e Solaris.&lt;br /&gt;&lt;br /&gt;Basta fazer todo o código de uma consulta SQL normal, mas usando a seguinte sintaxe:&lt;br /&gt;&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;SELECT GUID();&lt;br /&gt;&lt;/tt&gt;&lt;br /&gt;&lt;br /&gt;Ou então ainda mais preguiçosamente, na hora e inserir o número no banco de dados, porque não criá-lo só quando for necessário?&lt;br /&gt;&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;INSERT INTO customers(guid, nome, endereco) VALUES (GUID(), 'nome', 'endereco');&lt;br /&gt;&lt;/tt&gt;&lt;br /&gt;&lt;br /&gt;Muita gente não gosta de usar o MySQL para nada que não seja inserir, procurar, retirar e mexer nos dados. É uma boa prática, &lt;span style="font-weight:bold;"&gt;sempre&lt;/span&gt;, separar banco de dados da programação normal (ou seja, não parece ser uma boa idéia pela maioria usar o MySQL para guardar valores LONGTEXT compactados - sim, o MySQL tem funções para ZIP e BZIP), deixando programação com a página ou script, e o banco apenas armazenando e manipulando informação.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;3. Hardcore-PHP, para quem não tem preguiça&lt;/span&gt;&lt;br /&gt;É possível também criar um script em PHP que faça todo o trabalho duro. Mas atenção: esse número deixa de ser pseudo-sequencial, como veremos logo adiante. Eu comentei o código direto abaixo, e espero que ele seja auto-explicativo.&lt;br /&gt;&lt;br /&gt;A função tem apenas um parâmetro, &lt;tt&gt;$WinStyle&lt;/tt&gt; (true/false), para saber se o GUID gerado virá com os {} ou não.&lt;br /&gt;&lt;br /&gt;A mágica dela resume-se em usar a função uniqid() e fazer um hash MD5, de modo a obter uma sequência de 32 caracteres.&lt;br /&gt;&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;br /&gt;function createGUID($WinStyle) {&lt;br /&gt; /*&lt;br /&gt; description:&lt;br /&gt; creates a GUID-like value, using md5 hash, the uniqid() function and the Mersenne Twister Random&lt;br /&gt; number generator, in order to make it harder to predict the value (the uniqid() function is time-based).&lt;br /&gt; returns the GUID as a string 36-character lengthy (32 numbers plus four em-dashes like '-');&lt;br /&gt;   &lt;br /&gt; the $WinStyle parameter is for Windows-style GUIDs, with {} after and before the GUID value&lt;br /&gt; and all the characters to uppercase.&lt;br /&gt;   &lt;br /&gt; In order to avoid multiple substrings, I tried to use regular expressions, reducing the number of&lt;br /&gt; code lines from 8 to 3 ONLY for partioning the $number. Adieu, substrings!&lt;br /&gt; */&lt;br /&gt;  &lt;br /&gt; //creates the random number with a 32-hex-character pattern&lt;br /&gt; $number = md5(uniqid(mt_rand(), true));&lt;br /&gt;  &lt;br /&gt; /* &lt;br /&gt; defines the pattern of the Perl-compatible reg. expression for a GUID&lt;br /&gt; this patter means: any character from a to f or 0 to 9 in a group of 8, then 4, 4, 4 and 12.&lt;br /&gt; So, ([a-fA-F0-9]{8}) neans 8 characters without spaces, being from a-f (or A-F) and/or 0-9&lt;br /&gt; any of the between-parenthesis pattern is stored in a temporary variable $n, so, $1 would be the&lt;br /&gt; first-matched pattern (8-char long), and so on.&lt;br /&gt; the replacement is only the 5 patterns with dashes between them. &lt;br /&gt; */&lt;br /&gt; &lt;br /&gt; $preg_pattern = '/([a-fA-F0-9]{8})([a-fA-F0-9]{4})([a-fA-F0-9]{4})([a-fA-F0-9]{4})([a-fA-F0-9]{12})/';&lt;br /&gt; $preg_replacement = '$1-$2-$3-$4-$5';&lt;br /&gt; $guid = preg_replace($preg_pattern, $preg_replacement, $number);&lt;br /&gt;  &lt;br /&gt; if($WinStyle === true) {&lt;br /&gt; //exclusive format for windows-style GUID, otherwise it leaves the way it is.&lt;br /&gt;  $guid = '{' . strtoupper($guid) . '}';&lt;br /&gt; }&lt;br /&gt;  &lt;br /&gt; return $guid;&lt;br /&gt;} //end createGUID&lt;br /&gt;&lt;/tt&gt;&lt;br /&gt;&lt;br /&gt;Claro que esse código pode ser melhorado. Mas aí estão algumas alternativas.</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/2460456040562366745/3110778662181694546/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://www.sopadetags.com.br/blog/2009/01/criando-guids-com-php.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2460456040562366745/posts/default/3110778662181694546'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2460456040562366745/posts/default/3110778662181694546'/><link rel='alternate' type='text/html' href='http://www.sopadetags.com.br/blog/2009/01/criando-guids-com-php.html' title='Criando GUIDs com PHP?'/><author><name>sopa de tags</name><email>noreply@blogger.com</email></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2460456040562366745.post-710656900891082254</id><published>2009-01-29T09:57:00.001-02:00</published><updated>2009-01-29T10:18:48.884-02:00</updated><title type='text'>Sopa de Blogs!, o blog da sopa de &lt;tags&gt;!</title><content type='html'>Saiu o blog da Sopa de &amp;lt;tags!&amp;gt;. Resolvi chamá-lo de Sopa de Blogs! Nada mais pseudo-criativo.&lt;br /&gt;&lt;br /&gt;Esperem desse blog muitas e poucas coisas.&lt;br /&gt;&lt;br /&gt;Até o próximo post,</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/2460456040562366745/710656900891082254/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://www.sopadetags.com.br/blog/2009/01/sopa-de-blogs-o-blog-da-sopa-de.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2460456040562366745/posts/default/710656900891082254'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2460456040562366745/posts/default/710656900891082254'/><link rel='alternate' type='text/html' href='http://www.sopadetags.com.br/blog/2009/01/sopa-de-blogs-o-blog-da-sopa-de.html' title='Sopa de Blogs!, o blog da sopa de &amp;lt;tags&amp;gt;!'/><author><name>sopa de tags</name><email>noreply@blogger.com</email></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>