This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Para actualizar un campo tipo blob, ya sea de bytes o de texto / To update a blob field, either byte or text | |
Class.forName(driver); | |
Connection con = DriverManager.getConnection(...) | |
Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); | |
String query = "SELECT info FROM tabla WHERE id = 1"; | |
ResultSet rs = stmt.executeQuery(query); | |
rs.next(); | |
if (esBinario) { | |
rs.updateBytes(campo, contenidoBytes); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Código fácil para cifrar y descifrar en Java ("encriptar" y "desencriptar"). | |
* No ha sido auditado, ni garantizo su seguridad. | |
*/ | |
import java.security.MessageDigest; | |
import javax.crypto.Cipher; | |
import javax.crypto.spec.SecretKeySpec; | |
public byte[] cifra(String sinCifrar) throws Exception { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright 2014 Arturo Tena | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean equals(Object other) { | |
if (this == other) return true; | |
if (!(other instanceof MyClass)) return false; | |
final MyClass that = (MyClass) other; | |
return this.intField == that.intField && | |
this.booleanField == that.booleanField && | |
(this.stringField == null ? this.stringField == null : this.stringField.equals(that.stringField)) && | |
(this.objectField == null ? this.objectField == null : this.objectField.equals(that.objectField)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fechas implements Iterable<Timestamp> { | |
FechasIter iter; | |
Fechas(int field, int amount) { | |
this.iter = new FechasIter(field, amount); | |
} | |
public Iterator<Timestamp> iterator() { | |
return iter; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Quick-and-dirty way to count the lines of Java source code of a project | |
System.out.println(Files.walk(Paths.get(".")) | |
.map(e -> e.toFile()) | |
.filter(f -> f.isFile() && f.canRead()) | |
.filter(f -> f.getName().endsWith(".java")) | |
.mapToLong(f -> { | |
try { return new BufferedReader(new FileReader( f )).lines().count(); | |
} catch (Exception ex) { throw new RuntimeException(ex); } | |
}) | |
.reduce(0, (acc, current) -> acc + current)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Abre un shell de root en OS X | |
# El usuario actual debe ser administrador | |
sudo -s | |
# La contraseña que solicita es del usuario actual. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Encuentra archivos con cierto nombre en OS X | |
find / -name "java" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I haven't tested it | |
public int compareTo(MyClass that) { | |
if (this == that) return 0; | |
int comp = Integer.valueOf(this.intField).compareTo(that.intField); | |
if (comp != 0) return comp; | |
comp = this.stringField == null ? -1 : this.claveRed.compareTo(that.stringField); | |
if (comp != 0) return comp; | |
comp = Boolean.valueOf(this.booleanField).compareTo(that.booleanField); | |
if (comp != 0) return comp; | |
comp = this.objectField == null ? -1 : this.claveRed.compareTo(that.objectField); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Remove all entries except the given keys */ | |
private <K,V>void removeAllExcept(Map<K,V> map, K... keys) { | |
Map<K,V> objs = new HashMap<K,V>(keys.length); | |
for (K key : keys) | |
objs.put(key, map.get(key)); | |
map.clear(); | |
map.putAll(objs); | |
} | |
/** Remove all entries except the given keys */ |
OlderNewer