Blog Improvement, July 2013

I've been updating my site over the past few weeks.

The first thing was to change the way I post articles. Specifically, I want to write markdown, instead of HTML. That was hard just by itself. Good thing that there's a few text to markdown libraries in Java.

But that doesn't solve the problem where I have a hundred previous posts to convert from HTML to markdown. So I searched around and found an XSL transform that did it. The problem was that it took FOREVER: somewhere around a minute per post! I eventually found some JavaScript to do it. Good thing that I remembered that Java has a built in JavaScript interpreter. Especially since I use a platform built on it at work all day.

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
engine.put("example", "make a js var like this");
engine.eval("var output = call_js_function_like_this(example)");
String useThis = engine.get("output").toString();

So good! Something like that to get markdown from HTML! Awesome!

While I was back there, I added a preview function, so I don't have to post an article before I realize that I totally messed it up. And while doing that, I realized that the whole posting article system I had was essentially hanging by a thread and a prayer (i.e. easily broken, and it broke so fast), so I rewrote quite a bit of that.

Lest I neglected the front end, I redesigned the DOM of my pages (fewer classes), and removed the deprecated hgroup tags. I updated my CSS to handle it, and I made the fonts bigger. While doing that, I wanted to make sure that my site was actually using responsive design. After some back and forth with my good podcasting friend and avid theAndrewBailey reader, Ryan Rampersad, I realized the problem: mobile devices count pixels differently than straight CSS does. So he gave a solution:

<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=yes">

While I had upgraded the web server I was using in my Linux virtual machine to develop on, I neglected to do so on my server box. So I made everything Glassfish 4. Big mistake. I had to install it twice in order for it to start. I did the same things both times, but worked the second time. Maybe it was because the old version was still running, even though I had told it to quit. Firstly, I realized that there was a null pointer in the code they use to compress server output. OK, that's fine I'll disable that. Then I my page loads were really slow. Occasionally, something would break the output streams, letting the browser just hang there. I reverted back to Glassfish 3, and everything is fine.

But while I was on Glassfish 4, I tried out some new Java EE 7 features, like managed threads. I wanted to start my Jython interpreter on another thread, so startup times would be much faster. (I use Jython for Spruce, that random sentence generator I have on here.) Except those managed threads didn't work for me either. I'm not sure what the problem was, maybe I wasn't using them right, or the default configuration just sucks. So I simply made my own thread from an EJB (gasp), and works great. I don't have much interest in other features introduced, so no loss.

I have some ideas on how to improve Spruce, like how to do related words. Let's say you have a noun (extent), and you want to make it a verb (to extend), an adjective (extensive), or an adverb (extensively). I want Spruce to do the same.

When I found the ScriptEngineManager thing, I also decided to make Jython/Spruce use that, too, since it is a JSR standard. I obviously told the ScriptEngineManager to get the Python engine, not the JavaScript one.

Oh look, posted at the most not found time of the afternoon.

Posted under Programming.

No new comments may be posted for this article at this time.