The subfiles latex package is a good way of splitting one large latex document up into several smaller ones. It has the capability to allow the subfiles to be compiled separately so you don’t have to wait for the main document to compile while you are trying things out.
Category Archives: Uncategorized
Autoclosable method reference trick in Java 8
final Foo foo = new SomeFoo(); try (final AutoCloseable ignored = foo::close) { foo.doFoo(); } |
Mock Server
A remotely programmable HTTP “mock” server with expectation matchers/action responses http://www.mock-server.com/
Language Design – things not to do 2
Don’t make the behaviour of your strings depend on the system time! (Java String hashCodes I’m looking at you).
It seems like this is new in Java7, and is for security reasons (mostly to stop DOS attacks on hashmaps). So perhaps it could have been abstracted? Instead of putting the code into String.class, call a native method for the string hash seed, and let the JVM control the String hashCode policy? It is yet another source of non-detrminism in the core language.
Language Design – things not to do
Don’t require some classes to be initialised, then make thouse classes use methods (identifyHashCode) in some god class (System) which you also require to be initialised before any of its methods can be used.
Transformations
Robert Martin describes transformations as similar to refactorings but not behaviour preserving.
Adding nodes to a MongoDB replica set using the Java driver
MongoDB console has a method for adding a replica to a replica set called rs.add. The Java driver doesn’t support this directly, but you can use the code from the mongo shell to implement add directly by running commands against the admin database.
rs.add = function (hostport, arb) { var cfg = hostport; var local = db.getSisterDB("local"); assert(local.system.replset.count() <= 1, "error: local.system.replset has unexpected contents"); var c = local.system.replset.findOne(); assert(c, "no config object retrievable from local.system.replset"); c.version++; var max = 0; for (var i in c.members) if (c.members[i]._id > max) max = c.members[i]._id; if (isString(hostport)) { cfg = { _id: max + 1, host: hostport }; if (arb) cfg.arbiterOnly = true; } c.members.push(cfg); return this._runCmd({ replSetReconfig: c }); } |
Testing using FEST Swing in Jenkins
You can use the same trick as with cruise control (which actually originated from the hudson website)
java -DJENKINS_HOME=C:\Jenkins -jar C:\Jenkins\jenkins.war |
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon=1 HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName=testuser HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword=secret |
VIM Anti Patterns
Nice post on anti-patterns in vim.
Convert URL to URI using lambdaj
import ch.lambdaj.function.convert.Converter; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; public class ConvertUrlToUri implements Converter<URL, URI> { public static ConvertUrlToUri convertUrlToUri() { return new ConvertUrlToUri(); } @Override public URI convert(final URL from) { try { return from.toURI(); } catch (final URISyntaxException e) { throw new RuntimeException("unable to convert " + from + " to URI", e); } } } |