Tive um problema de out of memory em uma aplicação Java. Em uma máquina menos potente o sistema funcionou e em uma máquina com mais memória e processador a aplicação não funcionou. Os dois equipamentos estavam com SO OpenSUSE.
Verificando a memória com o comando:
ulimit -a
e alterando
ulimit -v unlimited
Funcionou. Dica do Sergio Matos
Esta página contem informações úteis para o dia a dia de meu trabalho
quinta-feira, 26 de janeiro de 2012
terça-feira, 17 de janeiro de 2012
Edição HTML com AJAX
O estilo apresentado abaixo permite a edição de um campo em uma página HTML, ou seja, permite a edição em uma página de relatório.
HTML
<input
value="teste"
onmouseout="this.style.border="0px none""
onmouseover="this.style.border="1px solid #000000""
maxlength="255"
onkeyup=" { document.getElementById("botao_salvar").style.display="";document.getElementById("botao_cancelar").style.display="";this.parentNode.parentNode.firstChild.firstChild.title="*";} this.value = this.value.replace(/\d/g,"").toUpperCase();"
HTML
<input
name=""
onchange="javascript:ajaxCampoResposta(this.value,1,5 )"
value="teste"
style="width: 100%; background: none repeat scroll 0% 0% transparent; border: 0px none;"
onmouseout="this.style.border="0px none""
onmouseover="this.style.border="1px solid #000000""
maxlength="255"
onkeyup=" { document.getElementById("botao_salvar").style.display="";document.getElementById("botao_cancelar").style.display="";this.parentNode.parentNode.firstChild.firstChild.title="*";} this.value = this.value.replace(/\d/g,"").toUpperCase();"
>
JavaScript - Codigo JavaScript que faz chamada para um Ajax de atualização de Campo.
function ajaxCampoResposta(oiac_objeto, id_dicionario, id) { /* alert(oiac_objeto+campo); return true; //*/ var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Seu navegador não suporta AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { // document.getElementById("resultado_ajax").innerHTML=xmlHttp.responseText; //alert("Kadu"); alert(xmlHttp.responseText); } } xmlHttp.open("GET","tab_seletor_campos_ajax_resposta.php?p_conteudo="+escape(oiac_objeto)+'&id_dicionario='+id_dicionario+'&id='+id,true); xmlHttp.send(null); }
segunda-feira, 16 de janeiro de 2012
Algorítimo de DICE
"Dice's coefficient, named after Lee Raymond Dice and also known as the Dice coefficient, is a similarity measure over sets."
Código para PSQL (POSTGRESQL)
CREATE OR REPLACE FUNCTION cgu_planilha.dice(texto1 character varying, texto2 character varying)
RETURNS double precision AS
$BODY$
DECLARE
qtde1 integer;
qtde2 integer;
tam_texto1 integer;
tam_texto2 integer;
tam_texto integer;
nt float;
nx float;
ny float;
ch1 varchar;
ch2 varchar;
t1 varchar;
t2 varchar;
BEGIN
qtde1 := 0;
t1 := lower(texto1);
t2 := lower(texto2);
t1 := translate(t1, 'áéíóúàèìòùãõâêîôôäëïöüçÁÉÍÓÚÀÈÌÒÙÃÕÂÊÎÔÛÄËÏÖÜÇ', 'aeiouaeiouaoaeiooaeioucAEIOUAEIOUAOAEIOOAEIOUC');
t2 := translate(t2, 'áéíóúàèìòùãõâêîôôäëïöüçÁÉÍÓÚÀÈÌÒÙÃÕÂÊÎÔÛÄËÏÖÜÇ', 'aeiouaeiouaoaeiooaeioucAEIOUAEIOUAOAEIOOAEIOUC');
tam_texto1 := length(t1);
tam_texto2 := length(t2);
nx = tam_texto1-1;
ny = tam_texto2-1;
if (tam_texto2 > tam_texto1) then
tam_texto := tam_texto1;
else
tam_texto := tam_texto2;
end if;
nt := 0;
LOOP
ch1 = substr(t1, qtde1, 2);
ch2 = substr(t2, qtde1, 2);
if (ch1 = ch2) then
nt := nt +1;
end if;
qtde1 := qtde1 + 1;
IF qtde1 > tam_texto THEN
EXIT; -- exit loop
END IF;
END LOOP;
RETURN (2*nt)/(nx+ny);
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION cgu_planilha.dice(character varying, character varying) OWNER TO postgres;
Aplicação do algoritmo para uma frase
CREATE OR REPLACE FUNCTION dice_frase2(texto1 character varying, texto2 character varying)
RETURNS boolean AS
$BODY$
DECLARE
alvo_pesquisa varchar;
t1 varchar;
t2 varchar;
tamanho2 integer;
tamanho1 integer;
i integer;
j integer;
texto_original varchar;
BEGIN
-- determinando o tamanho da segunda palavra
tamanho2:=length(texto2);
tamanho1:=length(texto1);
-- pesquisando na primeira frase
i := 1;
texto_original := texto1;
loop
alvo_pesquisa := substr(texto_original, i, tamanho2);
insert into lixo values(alvo_pesquisa, texto2, dice(alvo_pesquisa, texto2));
if (dice(alvo_pesquisa, texto2)>0.75) then
return true;
end if;
i := i+1;
if (tamanho1 <= i) then
exit;
end if;
end loop;
return false;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
Aplicação do algoritmo para um conjunto de palavras em qualquer ordem
CREATE OR REPLACE FUNCTION dice_frase3(texto1 character varying, texto2 character varying)
RETURNS boolean AS
$BODY$
DECLARE
ch2 varchar;
t1 varchar;
t2 varchar;
i integer;
j integer;
k integer;
BEGIN
j := 1;
k := 1;
loop
t2 = split_part(texto2, ' ',j);
if (length(t2)=0) then
exit;
end if;
i:=1;
loop
t1 = split_part(texto1, ' ',i);
if (length(t1)=0) then
exit;
end if;
insert into lixo values (t1, t2, i ||' '|| j || ' '|| k);
if (dice(t1, t2)>0.75) then
k := k+1;
exit;
end if;
i := i+1;
end loop;
j := j+1;
end loop;
if (j = k) then
return true;
else
return false;
end if;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION dice_frase(character varying, character varying)
OWNER TO postgres;
quinta-feira, 17 de novembro de 2011
What is the different between Stored, Tokenized, Indexed, and Vector?
- Stored = as-is value stored in the Lucene index
- Tokenized = field is analyzed using the specified Analyzer - the tokens emitted are indexed
- Indexed = the text (either as-is with keyword fields, or the tokens from tokenized fields) is made searchable (aka inverted)
- Vectored = term frequency per document is stored in the index in an easily retrievable fashion.
terça-feira, 6 de setembro de 2011
Encontrar um arquivo com determinado conteudo
Precisei procurar aonde estava o arquivo com o conteúdo "consulta_generica_sql". Assim executei
uma procura de arquivos com extensão ".php" e procurei em cada arquivo o conteúdo "consulta_generica_sql".
find . -name '*.php' | while read Linha; do echo $Linha; cat $Linha | grep consulta_generica_sql; done
uma procura de arquivos com extensão ".php" e procurei em cada arquivo o conteúdo "consulta_generica_sql".
find . -name '*.php' | while read Linha; do echo $Linha; cat $Linha | grep consulta_generica_sql; done
segunda-feira, 28 de março de 2011
Campos POSTGRES
Consulta para apresentar os campos de uma tabela POSTGRES
select c.relname, a.attname as "Column", pg_catalog.format_type(a.atttypid, a.atttypmod) as "Datatype"
from pg_catalog.pg_attribute a inner join pg_stat_user_tables c
on a.attrelid = c.relid
WHERE a.attnum > 0
and NOT a.attisdropped
and c.relname = 'nome tabela'
Para mudar o tipo de letra de campos da tabela. Neste exemplo estou transformando para caixa baixa todos os campos de 'nome tabela'
update pg_catalog.pg_attribute a set attname=lower(attname)
where a.attrelid in
(select relid from pg_stat_user_tables c
WHERE c.relname = 'nome tabela' )
and a.attnum > 0
and NOT a.attisdropped
select c.relname, a.attname as "Column", pg_catalog.format_type(a.atttypid, a.atttypmod) as "Datatype"
from pg_catalog.pg_attribute a inner join pg_stat_user_tables c
on a.attrelid = c.relid
WHERE a.attnum > 0
and NOT a.attisdropped
and c.relname = 'nome tabela'
Para mudar o tipo de letra de campos da tabela. Neste exemplo estou transformando para caixa baixa todos os campos de 'nome tabela'
update pg_catalog.pg_attribute a set attname=lower(attname)
where a.attrelid in
(select relid from pg_stat_user_tables c
WHERE c.relname = 'nome tabela' )
and a.attnum > 0
and NOT a.attisdropped
segunda-feira, 24 de janeiro de 2011
Exemplo de Expressão Regular
public static void main(String[] args){
String entrada;
String endereco;
String padrao="href=\"[a-zA-Z.0-9/:_+\-]*.jpg";
padrao="h[a-zA-Z.0-9/:_+\-]*-h/[a-zA-Z.0-9/:_+\-]*.png";
FileInputDemo aux = new FileInputDemo();
File testFile = new File("c:/Aulas/RegEx/pagina_julho_2010a.txt");
entrada = aux.getContents(testFile);
URLConnectionReader auxUrl = new URLConnectionReader();
Pattern pattern = Pattern.compile(padrao);
Matcher matcher = pattern.matcher(entrada);
boolean found = false;
while (matcher.find()) {
endereco = matcher.group().substring(6);
try {
System.out.println(endereco);
// auxUrl.urlRead(endereco);
} catch (Exception ex) {
Logger.getLogger(RegEx.class.getName()).log(Level.SEVERE, null, ex);
}
found = true;
}
if(!found){
System.out.printf("No match found.%n");
}
}
}
String entrada;
String endereco;
String padrao="href=\"[a-zA-Z.0-9/:_+\-]*.jpg";
padrao="h[a-zA-Z.0-9/:_+\-]*-h/[a-zA-Z.0-9/:_+\-]*.png";
FileInputDemo aux = new FileInputDemo();
File testFile = new File("c:/Aulas/RegEx/pagina_julho_2010a.txt");
entrada = aux.getContents(testFile);
URLConnectionReader auxUrl = new URLConnectionReader();
Pattern pattern = Pattern.compile(padrao);
Matcher matcher = pattern.matcher(entrada);
boolean found = false;
while (matcher.find()) {
endereco = matcher.group().substring(6);
try {
System.out.println(endereco);
// auxUrl.urlRead(endereco);
} catch (Exception ex) {
Logger.getLogger(RegEx.class.getName()).log(Level.SEVERE, null, ex);
}
found = true;
}
if(!found){
System.out.printf("No match found.%n");
}
}
}
Assinar:
Postagens (Atom)