quinta-feira, 29 de abril de 2010
SSH
Quando der um pau de louco no SSH e vc obter esta resposta:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
Faça o seguinte no shell de sua maquina:
ssh-keygen -R NUMERO_DO_SEU_IP
ssh-keygen -R site_q_quer_liberar.com.br
O comando acima zera as chaves SSH para o IP ou site informado.
segunda-feira, 5 de abril de 2010
sexta-feira, 26 de março de 2010
MySQL - Exportar apenas uma tabela
mysqldump --default-character-set=latin1 banco1 tabela1 > backup-tabela1.sql
quarta-feira, 24 de março de 2010
Javascript e PHP - Botão Bold, Italico,Underline, e-mail e Http
Sei o que muitos vão dizer, pq não usar o WYSYS? Resposta simples, pq ele altera todo o padrão CSS ja pré-definido da pagina.
Para tirar o efeito por exemplo <b>laweb</b> vc deve selecionar desde <b até </b> e depois clicar no botão "Tirar Efeito".
Para poder usar o mesmo script em várias paginas eu dividi ele da seguinte maneira:
Script para usar em sua pagina PHP
<?php
$Nome_do_Campo = "agenda";
include_once("biu.php");
?>
<textarea cols="80" rows="10" name="agenda" class="preto" ></textarea>
Arquivo biu.php
<script type="text/javascript">
<!--
function formatText (el,tag) {
var selectedText=document.selection?document.selection.createRange().text:el.value.substring(el.selectionStart,el.selectionEnd);// IE:Moz
if (tag !='e' || tag !='h') var newText='<'+tag+'>'+selectedText+'</'+tag+'>';
if (tag=='e') var newText='<a href="mailto:'+selectedText+'">'+selectedText+'</a>';
if (tag=='h') var newText='<a href="http://'+selectedText+'" target=_blank>'+selectedText+'</a>';
if(document.selection){//IE
document.selection.createRange().text=newText;
}
else{//Moz
el.value=el.value.substring(0,el.selectionStart)+newText+el.value.substring(el.selectionEnd,el.value.length);
}
}
function formatText_tira (el) {
var selectedText=document.selection?document.selection.createRange().text:el.value.substring(el.selectionStart,el.selectionEnd);// IE:Moz
var newText=selectedText;
var oldText=selectedText;
for (i=1;i<=5;i++) { if (i==1) tag='b'; if (i==2) tag='i'; if (i==3) tag='u'; if (i<=3) { var tagX='<'+tag+'>';
var tagY='</'+tag+'>';
newText = newText.replace(tagX,'');
newText = newText.replace(tagY,'');
}
if (i==4) {
var tagJ=newText.split('<',1); if (!tagJ[0]) { var tagX=newText.split('>',2);
var tagY='</a';
newText = newText.replace(newText,tagX[1]);
newText = newText.replace(tagY,'');
}
}
if (i==5) {
var tagJ=newText.split('<',1); if (!tagJ[0]) { var tagX=newText.split('>',2);
var tagY='</a';
newText = newText.replace(newText,tagX[0]);
newText = newText.replace(tagY,'');
}
}
}
if (newText=="undefined") nextText=oldText;
if(document.selection){//IE
document.selection.createRange().text=newText;
}
else{//Moz
el.value=el.value.substring(0,el.selectionStart)+newText+el.value.substring(el.selectionEnd,el.value.length);
}
}
//-->
</script>
<style>
.button {
font-family:Tahoma, Verdana, Arial;
color: #000066;
font-size:12px;
font-weight:bold;
text-align:center;
background: #f5f5f5;
}
.button_tirar {
font-family:Tahoma, Verdana, Arial;
color: #CC0000;
font-size:12px;
font-weight:bold;
text-align:center;
background: #f5f5f5;
}
</style>
<table cellspacing=0 cellpadding=0><tr>
<td><input type="button" value="N" onclick="formatText (<?=$Nome_do_Campo?>,'b');" class=button /></td>
<td><input type="button" value="I" onclick="formatText (<?=$Nome_do_Campo?>,'i');" class=button /></td>
<td><input type="button" value="S" onclick="formatText (<?=$Nome_do_Campo?>,'u');" class=button /></td>
<td><input type="button" value="e-mail" onclick="formatText (<?=$Nome_do_Campo?>,'e');" class=button /></td>
<td><input type="button" value="link" onclick="formatText (<?=$Nome_do_Campo?>,'h');" class=button /></td>
<td><input type="button" value="Tirar Efeito" onclick="formatText_tira (<?=$Nome_do_Campo?>);" class=button_tirar /></td>
</tr></table>
Para tirar o efeito por exemplo <b>laweb</b> vc deve selecionar desde <b até </b> e depois clicar no botão "Tirar Efeito".
Para poder usar o mesmo script em várias paginas eu dividi ele da seguinte maneira:
Script para usar em sua pagina PHP
<?php
$Nome_do_Campo = "agenda";
include_once("biu.php");
?>
<textarea cols="80" rows="10" name="agenda" class="preto" ></textarea>
Arquivo biu.php
<script type="text/javascript">
<!--
function formatText (el,tag) {
var selectedText=document.selection?document.selection.createRange().text:el.value.substring(el.selectionStart,el.selectionEnd);// IE:Moz
if (tag !='e' || tag !='h') var newText='<'+tag+'>'+selectedText+'</'+tag+'>';
if (tag=='e') var newText='<a href="mailto:'+selectedText+'">'+selectedText+'</a>';
if (tag=='h') var newText='<a href="http://'+selectedText+'" target=_blank>'+selectedText+'</a>';
if(document.selection){//IE
document.selection.createRange().text=newText;
}
else{//Moz
el.value=el.value.substring(0,el.selectionStart)+newText+el.value.substring(el.selectionEnd,el.value.length);
}
}
function formatText_tira (el) {
var selectedText=document.selection?document.selection.createRange().text:el.value.substring(el.selectionStart,el.selectionEnd);// IE:Moz
var newText=selectedText;
var oldText=selectedText;
for (i=1;i<=5;i++) { if (i==1) tag='b'; if (i==2) tag='i'; if (i==3) tag='u'; if (i<=3) { var tagX='<'+tag+'>';
var tagY='</'+tag+'>';
newText = newText.replace(tagX,'');
newText = newText.replace(tagY,'');
}
if (i==4) {
var tagJ=newText.split('<',1); if (!tagJ[0]) { var tagX=newText.split('>',2);
var tagY='</a';
newText = newText.replace(newText,tagX[1]);
newText = newText.replace(tagY,'');
}
}
if (i==5) {
var tagJ=newText.split('<',1); if (!tagJ[0]) { var tagX=newText.split('>',2);
var tagY='</a';
newText = newText.replace(newText,tagX[0]);
newText = newText.replace(tagY,'');
}
}
}
if (newText=="undefined") nextText=oldText;
if(document.selection){//IE
document.selection.createRange().text=newText;
}
else{//Moz
el.value=el.value.substring(0,el.selectionStart)+newText+el.value.substring(el.selectionEnd,el.value.length);
}
}
//-->
</script>
<style>
.button {
font-family:Tahoma, Verdana, Arial;
color: #000066;
font-size:12px;
font-weight:bold;
text-align:center;
background: #f5f5f5;
}
.button_tirar {
font-family:Tahoma, Verdana, Arial;
color: #CC0000;
font-size:12px;
font-weight:bold;
text-align:center;
background: #f5f5f5;
}
</style>
<table cellspacing=0 cellpadding=0><tr>
<td><input type="button" value="N" onclick="formatText (<?=$Nome_do_Campo?>,'b');" class=button /></td>
<td><input type="button" value="I" onclick="formatText (<?=$Nome_do_Campo?>,'i');" class=button /></td>
<td><input type="button" value="S" onclick="formatText (<?=$Nome_do_Campo?>,'u');" class=button /></td>
<td><input type="button" value="e-mail" onclick="formatText (<?=$Nome_do_Campo?>,'e');" class=button /></td>
<td><input type="button" value="link" onclick="formatText (<?=$Nome_do_Campo?>,'h');" class=button /></td>
<td><input type="button" value="Tirar Efeito" onclick="formatText_tira (<?=$Nome_do_Campo?>);" class=button_tirar /></td>
</tr></table>
segunda-feira, 25 de janeiro de 2010
sexta-feira, 22 de janeiro de 2010
Oracle - Ubuntu 8.04 - PHP - Instalação
artigo original em ingles por John Wendell
Além de instalar o oracle-xe-universal_10.2.0.1-1.0_i386.deb siga os passos abaixo para completar a instalação.
Instale alguns pacotes necessários:
sudo apt-get install php-pear php5-dev libaio1 build-essential
Download o Oracle Instant Client:
http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html
Pacotes necessários:
* Basic client
* SDK
* SQL Plus (Optional)
Unzip todos os downloads em /opt/instantclient
Execute os comandos abaixo:
cd /opt/instantclient
sudo ln -s libclntsh.so.11.1 libclntsh.so
sudo ln -s libocci.so.11.1 libocci.so
sudo sh -c echo "/opt/instantclient" > /etc/ld.so.conf.d/oracle.conf
sudo ldconfig
Instalando o modulo OCI8:
sudo pecl install oci8
Quando questionado por Oracle PATH, tecle nessa ordem:
all <enter>
instantclient,/opt/instantclient <enter>
<enter>
Coloque a extensão no PHP.ini:
sudo sh -c echo "extension=oci8.so" > /etc/php5/conf.d/oracle.ini
Restarte seu apache:
sudo /etc/init.d/apache2 restart
Cheque com phpinfo() se o modulo OCI8 esta lá.
sexta-feira, 15 de janeiro de 2010
MySQL - Pesquisa automática por data - de 3 meses atrás até 1 dia atrás
OBS: Esta pesquisa esta limitada a 5 resultados (limit 5) e esta setada para trazer os resultados aleatóreamente.
select SEUS_CAMPOS from SUA_TABELA where (campo_data<SUBDATE(Now(), INTERVAL 1 DAY) and campo_data>SUBDATE(Now(), INTERVAL 91 DAY)) ORDER BY RAND() limit 5
terça-feira, 15 de dezembro de 2009
PHP Tirar Acentos - remove special characters
function retira_acentos($texto)
{
$array1 = array( "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç"
, "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç" );
$array2 = array( "a", "a", "a", "a", "a", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u", "c"
, "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C" );
return str_replace( $array1, $array2, $texto);
}
$texto = retira_acentos($variavel_q_quer_tirar_acentos);
$variavel_q_quer_tirar_acentos = $texto;
Se quiser ainda tirar carateres especiais como $ ou ª ou º entre outros sugiro um uso combinado de regex com str_replace conforme abaixo:
function retira_acentos($texto)
{
$array1 = array( "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç"
, "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç" );
$array2 = array( "a", "a", "a", "a", "a", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u", "c"
, "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C" );
$texto= str_replace( $array1, $array2, $texto);
$texto=preg_replace("/[^a-z0-9\s\-]/i", "", $texto);
$texto=preg_replace("/\s/", "_", $texto); // Replace all spaces with underline
return $texto;
}
$texto = retira_acentos($variavel_q_quer_tirar_acentos);
Para não ter problema com o nome do arquivo, sugiro usar assim:
// Descobrir os 4 ultimos caracteres do arquivo, por exemplo .pdf
$final = $arquivo_name;
$final = substr($final,(strlen($final)-4),strlen($final));
$nome_sem_final=substr($arquivo_name, 0, -4);
$arquivo_name = retira_acentos($nome_sem_final).$final;
Para achar a extensão do arquivo temos também:
$info = pathinfo($filename);
$name = $info['filename'];
$ext = $info['extension'];
// Shorter
$name = pathinfo($file, PATHINFO_FILENAME);
// Or in PHP 5.4
$name = pathinfo($filename)['filename'];
// Or in PHP 5.6, 7>
$ext=pathinfo($filename, PATHINFO_EXTENSION);
quinta-feira, 3 de dezembro de 2009
VirtualBox Guest Additions
Quem atualizou o Ubuntu 8.0.4 atualmente pode ter problemas. Para sanar use o abaixo:
use o comando uname -r (troque KERNELVERSION pelo resultado no comando abaixo)
1. sudo apt-get install build-essential linux-headers-KERNELVERSION
2. Clique 2x no icone do virtualbox additions na área de trabalho e clique em auto-run
3. Desligue e ligue novamente a virtual machine e pronto!
use o comando uname -r (troque KERNELVERSION pelo resultado no comando abaixo)
1. sudo apt-get install build-essential linux-headers-KERNELVERSION
2. Clique 2x no icone do virtualbox additions na área de trabalho e clique em auto-run
3. Desligue e ligue novamente a virtual machine e pronto!
sexta-feira, 27 de novembro de 2009
MySql - Apagar varios dados em varias tabelas
Para apagar dados com um, ou mais campos em comum:
Exemplo:
delete FROM t1,t2,t3 USING t1 INNER JOIN t2 INNER JOIN t3 where t1.id=t2.id and t2.id=t3.id and clientemaster=830
Assinar:
Postagens (Atom)
Linux bash file returns unexpected token `$'do\r''
open file in vi edit with vi filename.sh command; type in vi :set ff=unix command; save file with :wq It will save the file with unix...
-
Adicionar ♦ 10 dias a partir de hoje echo date('d/m/Y', strtotime("+10 days")); ♦ 10 dias a partir de uma data echo ...
-
function retira_acentos($texto) { $array1 = array( "á", "à", "â", "ã", "ä", "é...