# Ed's Big Plans

## Codex

with one comment

I think it’s safe to say that I’m unlikely to post anymore on this blog (although announcements related to my department will still be broadcast here until I find a suitable spot for them). The original intention was to quickly write down a few thoughts, especially if I learned something that was new to me, and then be able to refer to it in future. At some point, there was a transition from shorter, less meaningful posts that were easy and quick to write — to longer, more meaningful posts that took a lot of time to produce (at the same time, I recall trying to write posts that became less and less personal to the point where the narrative suffered – Who’s telling the story? Why would I even look back on these posts in future?). After that, things became very sparse as the amount of time I wanted to dedicate onto side projects was consumed with razor-focus on my thesis. That focus on my thesis actually did me very well in retrospect.

The gut feeling I have is there’s still an exception, there’s a need that’s been left unattended for a long time since I stopped completing articles in the blog — I still have a need to record things down where I could review them later — and then to allow those articles to be quickly given to someone else as an answer to a question (passing a URL is easy).

My wiki is still up (again, rarely updated), that seems to be a reasonable stop-gap. The problem is that there’s not really a sense of accomplishment writing things down in there (for the corporate type, what operational definition can we pull out as a key performance indicator? Bytes? Pages? Number of updates over a timespan? These do not describe the practical utility of the content of a wiki).

I’m going to try something different and create something like a journal, that is the culmination of things learned. The codex will exist as a set of loosely organized LaTeX sources and accompanying figures arranged in yet another SVN/git repo (I think I have like five on my home server now…)– plus their PDF outputs. When articles from the codex seem reasonably mature, they’ll get a stamp stating their version number, and a copy will be released somehow, for magical search engines to index — or it’ll be archived somewhere locally if it somehow isn’t appropriate to shove onto the net (e.g. oh hey, this particular article would work 1:1 as part of my dissertation). If the articles are any good, it’d then be possible to string chapters together, and eventually to bind them into a book to have for posterity. Now that’s a physical secondary storage of stuff that I learned that I’d get to keep and flip through (the ol’ primary storage isn’t as sharp as it used to be).

Having OSX and an SSD means searching for keywords in local PDFs is super quick (– I don’t know what the experience is like in Windows 7 /8, but I assume it’s similarly quick to find documents containing phrases — there’s a search field in the system-wide start menu that appears to do the same thing). I think the codex would become the best way for me to write things that solves the problems of (1) a fluctuating personality I experienced when blogging with WordPress, and (2) a feeling of unfulfillment I felt putting things in my wiki.

Finally, there’s time commitment. Let’s see — I used to be terrible at budgeting time – now I’m just bad. So that’s an improvement. Let’s say I spend about six hours each week writing in my codex. Without the pressure to actually release anything as a blog post, I’ll actually feel like my ongoing project isn’t stagnating. Rather than having a few dozen drafts, I’ll have a few dozen works in progress that are already useable and searchable fragments of chapters. Since each chapter can be on its own subject, I don’t have to worry about keeping to a narrow personalty — as in the limit, the codex will cover my own personality.

Written by Eddie Ma

October 20th, 2013 at 12:50 pm

Tagged with ,

## 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!

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

featured post

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. Written by Eddie Ma February 16th, 2012 at 1:29 pm Posted in Featured,Technology ## SoCS Grads’ very first Wine & Cheese! (W2012) without comments Brief: Well, I’ve organized the first Wine & Cheese for the School of Computer Science graduate students slated for next week (University of Guelph). I had significant moral support from Richard Schwarting and Jason Ernst. We’re hoping for a turnout of about thirty including faculty and staff. I’m particularly proud of the logo I made. I think we’ll have an excellent turn out — Richard and I did advertise as much as humanly possible after all Written by Eddie Ma February 11th, 2012 at 12:09 am ## 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

Written by Eddie Ma

December 29th, 2011 at 4:49 pm