# Ed's Big Plans

## A Tessellation (1-, 2-, 3- unit length edges)

Here’s a neat tiling I saw on the ground recently.

This tiling happens to be a solution that ensures that graph nodes are regularly spaced 1-, 2-, or 3- unit lengths apart.

If we re-orient all of the tiles in the same direction, the nodes then become two unit lengths apart — and the graph becomes homomorphic with a hexagonal tiling.

I’ll let you know if I find an application to the 1-, 2-, 3- hop pattern.

Written by Eddie Ma

February 18th, 2013 at 6:56 pm

Posted in Algorithms

Tagged with , , ,

## Java CDK LoggingToolFactory and Reflection (Solution)

### Update

Egon’s suggestion in the comments works best. Loading the JARs distributed for a project almost always requires far less work. If you’re like me and haven’t used Java in a while, it should be noted that the Java SE6 compiler and runtime both allow you to specify wildcards when referring to directories containing JARs. For Java SE6 and up, something like the below commands would work.

javac -classpath .:jar/*:dist/jar/* MGNQSAR.java
java  -classpath .:jar/*:dist/jar/* MGNQSAR


The directory “dist/jar” contains CDK JARs, while the directory “jar” contains dependencies. Embarrassingly enough, I didn’t notice this directory hiding in plain sight, meaning that I didn’t have to go out and find the same log4j package distributed directly from Apache.

Oh well! Live and learn

### Original Post

So today, I had to get some QSAR descriptors calculated from The Chemistry Development Kit (CDK) (Java) as a means to benchmark Chris’ MGN custom neural network architecture. While trying to compile CDK into my very simple main, I encountered a number of problems with LoggingToolFactory. Below is a simplified main that illustrates the problem…

import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.qsar.*;
import java.io.FileNotFoundException;

public class MGNQSAR {

public static void main(String[] args) {

try {
} catch (FileNotFoundException fnfe) {
System.err.println("FATAL: Couldn't find file ...");
System.err.println(path);
return;
}

Molecule mol = null;

try {
} catch (CDKException cdke) {
System.err.println("FATAL: CDK became enraged ...");
System.err.println(cdke.toString());
return;
}
return;
}
}


Logging is generally a good idea. In fact, it’s such a good idea — you should probably deploy some logging in every piece of medium- to large- scale software that you produce. The problem I encountered today was the absence of documentation of how to compile and run a main that calls code from CDK that calls LoggingToolFactory.createLoggingTool(.).

Here’s some context. All of the classes that I’ve encountered in CDK call this method statically to create a class-wide logger. This method provides the caller with a logging tool object that does some recording of debug information, or jots down a few notes about the path of execution in CDK, or saves some other informative alert for the end user. The logging tool is offered up to any class that implements the interface ILoggingTool (CDK allows you to implement your own). By default CDK offers two such tools — one that wraps Apache log4j (org.openscience.cdk.tools.LoggingTool), and stdout as a fallback (when log4j isn’t available) wrapped within (org.openscience.cdk.tools.SystemOutLoggingToolTest).

By design, the factory createLoggingTool(.) attempts to provide the user with an already instantiated copy of a logging tool — it’s the factory design pattern we all know. The problem is as follows. CDK has to be able to try and instantiate the wrapper for log4j first before trying to instantiate the stdout fallback. The notion of trying to instantiate is not something that one often does in Java. To perform this task, one has to use reflection — in this case, it looks like CDK’s LoggingToolFactory uses a few methods found in (java.lang.reflect.InvocationTargetException) and (java.lang.reflect.Method).

So how does reflection cause woe?

Well, when I compile my main, Javac visits the classes I’ve imported and the classes that they’ve imported (etc.) and compiles the Java sources into class bytecode files. That is, Javac does this for everything that’s been declared for import at compile time. That means that everything that requires reflection isn’t compiled since that code is only analyzed at runtime. Next, Java runs main and executes some code called by CDK — that code tries to createLoggingTool(.) but fails gracefully since Javac never compiled the corresponding classes (neither the log4j wrapper nor the stdout fallback wrapper). All is well until the uninstantiated logging tool is called to actually log anything — resulting in a null pointer exception.

It took me a while to track the problem down, but the solution is simple.

Manually compile (Javac) SystemOutLoggingTool — or better yet, get Apache log4j, then also manually compile LoggingTool.

The corresponding compile and run commands would look like this …

	javac MGNQSAR.java
javac -classpath .:log4j-1.2.17.jar org/openscience/cdk/tools/LoggingTool.java
javac org/openscience/cdk/tools/SystemOutLoggingTool.java
java  -classpath .:log4j-1.2.17.jar MGNQSAR


Where I’ve symbolically linked CDK’s org directory as a subdirectory of my working directory; and I’ve also symbolically linked (Apache log4j)’s jar file as an entry in this working directory too.

I hope this helps you too!

Egon says...

Interesting analysis!

Why aren’t you compiling the CDK separately and use the binary .jar of it when compiling your own code? Then the proper classes would be precompiled, and no longer depend on being directly referred to in your main() method…

Eddie Ma says...

I completely forgot about that option. I should do that.

Written by Eddie Ma

July 9th, 2012 at 5:52 pm

Posted in Biochemistry

## On SSL/TLS and HTTPS — Briefings for my Computer Security class

Brief: This is a technical briefing I made for fellow students in a Computer Security class (Winter 2011) about Secure Socket Layer [SSL] (now Transport Layer Security [TLS]). These briefings fit in nicely since it came after Dr. Obimbo explained the number theory behind RSA (modulus prime exponentiation). I went to the primary source on this topic to write this document: thanks to the Internet Engineering Task Force. I’ve posted this document as a consumable reference for anyone who needs it.

>>> Download: A Network Security Spotlight on SSL/TLS and HTTPS (pdf) <<<

Figure $_: A Schematic of the SSL/TLS Handshaking Procedure. This document is licensed under Creative Commons Attribution 3.0 Unported. The enclosed figures are further released into the public domain. Andre Masella says... Comic Sans? Really? Eddie Ma says... Yes. It was a dare. I won. Written by Eddie Ma February 16th, 2012 at 1:29 pm Posted in Featured,Technology ## Fighting spam account registration (phpBB3) with 3 comments I was asked to deploy a means to fight spam account registration on a phpBB3 installation. I tried the advice posted by Nadav Samet, but the version of phpBB3 we use doesn’t seem to respond to changes made to profile_add_body.tpl. I settled on an approach that’s similar to the one posted by Steve Maury, but is slightly improved as you can request any exact string for an answer from the registrant. This method should work with phpBB3 version 3.0.x. This method results in a mandatory field to be completed by the registrant during registration time. You can assign it any question you like where the answer is a string of text that you decide. I’ve given a really simple question in this example. Use a more difficult question that a bot would have trouble with but that your typical registrants can answer. We do this with a custom profile field in the registration screen as in the below screen capture. The above is a screen capture of an example mandatory question (choose a more secure question). There are two steps to setting this up. First, set up a custom question that must be answered — you can find such a setting in the administrative control panel (ACP) as in the following screen capture. Add a mandatory question in user and groupscustom profile fieldscreate new field. Here, I’ve named mine guelph_question. After you click Create new field, you will be presented with a screen where you can create the question of your choosing — be sure to make the field mandatory by using the radio button labelled Required field listed under Visibility options. Second, add the following code indicated below in includes/ucp/ucp_register.php – Notice that I’ve placed my custom code after existing code to check for a valid password and e-mail. This is commented under validate custom profile fields ( — just checked — starts at line 247 in the 3.0.9 source code). Replace the simple question and answer I’ve placed there with your own question and answer. Notice that you also have full control over the error message that the registrant sees if they answer the question incorrectly. // validate custom profile fields$cp->submit_cp_field('register', $user->get_iso_lang_id(),$cp_data, $error); if (!sizeof($error))
{
if ($data['new_password'] !=$data['password_confirm'])
{
$error[] =$user->lang['NEW_PASSWORD_ERROR'];
}

if ($data['email'] !=$data['email_confirm'])
{
$error[] =$user->lang['NEW_EMAIL_ERROR'];
}
}

// Anti-spam code below ...
if (!sizeof($error)) { if (!isset($_POST['pf_guelph_question']) ||
$_POST['pf_guelph_question'] != 'Gryphon') {$error[] = 'Incorrect answer to Guelph question.';
}
}
// ... EOAnti-spam code


And you’re done.

I hope this works for you! Enjoy

Giovanni says...

Thank you very much, Eddie . Your post solved my spambots problems.

Eddie Ma says...

Neat! I’m happy to have helped

Vasch says...

Hi Eddy,

Thanks allot for this info. I was looking for a solution since weeks! Seems to work fine.

Written by Eddie Ma

December 29th, 2011 at 4:49 pm

## Fuzzy c-means for greylevel image segmentation

Here’s a script I threw together to do grey-level segmentation using fuzzy c-means. This appeared as a small part of a project in the image processing course I took. The algorithm deployed was really a proof of concept meant to replicate and verify the results of another author — as such, I don’t recommend ever using fuzzy c-means for this task as it’s pretty inefficient. This software will handle any number of grey-level-segments you desire, but I recommend eight as a maximum.

The code and course project paper are originally dated April 20th, 2011.

( Requires pypng – Python PNG encoder/decoder )

Here are the examples included in the above archive. I like pictures.

Sunny in 8-bit greyscale, 3-bit greyscale, 2-bit greyscale.

Auryo in 8-bit greyscale, 3-bit greyscale, 2-bit greyscale.

Enjoy

Written by Eddie Ma

December 20th, 2011 at 11:21 pm

## My talk at Barcode of Life, Adelaide (2011)

I’ve just finished my presentation in Adelaide. This is the first real biology-heavy conference I’ve been to. Sujeevan has brought me along with the BOLD team from BIO in order to present my work — and more importantly — to acquire some resolution about the barcoding culture and its biological significance. The Consortium for The Barcode of Life (CBOL) co-hosted this event with many biodiversity parties in Australia. Another huge group present was the International Barcode of Life (iBOL) project. The Barcode of Life Conference is held every other year and is attended by researchers interested in the concerted international barcoding effort. I presented my preliminary findings with a data analysis session and had excellent feedback — it’s pretty clear where to go next with my thesis! My talk describes the first steps to automating barcode (contig-like) assembly from ab1 sequencer trace files. This talk describes the present need for automation, trends that we can readily detect in currently assembled data and most importantly — detectable patterns in how human experts perform manual barcode assembly.

The full name of the conference is Fourth International Barcode of Life Conference.