lunes, 24 de mayo de 2010

Proxy en apache

no recuerdo si sirven estos 2 comandos:

sudo apt-get install libapache2-mod-proxy-html
sudo a2enmod proxy

pero bueno, lo que sí servía:

sudo vim /etc/apache2/sites-available/default


Order deny,allow
Allow from all


ProxyPass /google http://www.google.cl/
ProxyPassReverse /google http://www.google.cl/



sudo /etc/init.d/apache2 restart

martes, 18 de mayo de 2010

Cómo iterar e imprimir enums en Java


private enum stats {
pings, opened, closed, queueEmpty, gets, releases, timeouts;
private int count=0;
public void add() {
count++;
}
};

private String getStatsString() {
EnumSet set = EnumSet.allOf(stats.class);
HashMap map = new HashMap();
for (stats stat : set) {
map.put(stat.toString(), stat.count);
}
return map.toString();
}

private void logStats() {
log.info("stats del pool: "+getStatsString());
}

sprintf a la Java con String.format

Si bien es cosa de gustos, creo que se ve más ordenado usar String.format en caso de grandes concatenaciones:


public class Sprintf {

public static void main(String[] args) {
String nombre = "Juan";
String apellido = "Riquelme";
int edad = 54;

String concatenacion;

concatenacion = "nombre: "+nombre+", apellido: "+
apellido+", edad: "+edad;
System.out.println(concatenacion);

concatenacion = String.format("nombre: %s, apellido: %s, edad: %d",
nombre, apellido, edad);
System.out.println(concatenacion);
}

}

lunes, 3 de mayo de 2010

Mysql 5.0.3 acepta varchars de mas de 255 caracteres

Para los que seguían pensando lo contrario:

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions.

http://dev.mysql.com/doc/refman/5.0/en/char.html

jueves, 29 de abril de 2010

Google translator para language detection

Ref: google apis

Prueba con inglés:

pablo@pablo-desktop:~$ curl -e http://www.fcwm.cl \
'http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&
q=hello%20world'
{"responseData": {"language":"en","isReliable":false,"confidence":0.114892714}, "responseDetails": null, "responseStatus": 200}

Prueba con italiano:

pablo@pablo-desktop:~$ curl -e http://www.fcwm.cl \
'http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&
q=ciao+a+tutti'
{"responseData": {"language":"it","isReliable":false,"confidence":0.29042974}, "responseDetails": null, "responseStatus": 200}

Prueba con español:

pablo@pablo-desktop:~$ curl -e http://www.fcwm.cl \
'http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&
q=hola+a+todos'
{"responseData": {"language":"es","isReliable":false,"confidence":0.28695157}, "responseDetails": null, "responseStatus": 200}

Prueba de detección de español con mayor "confidence" al agregar más palabras:

pablo@pablo-desktop:~$ curl -e http://www.fcwm.cl \
'http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&
q=hola+a+todos+los+cabros+de+la+cuadra'
{"responseData": {"language":"es","isReliable":true,"confidence":0.6409442}, "responseDetails": null, "responseStatus": 200}

Cómo setear el content-type y el charset en la respuesta de un restlet

Papita:

@Override
public Representation getRepresentation(Variant variant) {
if (MediaType.TEXT_XML.equals(variant.getMediaType())) {
...
StringRepresentation representation = new StringRepresentation(xmlText,
MediaType.TEXT_XML, Language.ENGLISH, CharacterSet.UTF_8);
return representation;
}
}

jueves, 22 de abril de 2010

Whole word search en java usando regex


Pattern myPattern = Pattern.compile("\\bSebastián Piñera\\b",
Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE
| Pattern.UNICODE_CASE | Pattern.CANON_EQ);

String text;
Matcher matcher;

text = "de la pradera camión\nSebastián Piñera";
matcher = myPattern.matcher(text);
System.out.println(matcher.find());

text = "clorox de la pradera Sebastián Piñera jaja";
matcher.reset(text);
System.out.println(matcher.find());

text = "clorox de la pradera jaja";
matcher.reset(text);
System.out.println(matcher.find());


(Ojo con el uso eficiente del "matcher" mediante el método "reset")

Imprimirá:


true
true
false


Ref: http://www.regular-expressions.info/java.html