Melon Marshall Farrier's tech blog

Commentary, coding tips, libraries and utilities

Predicting stock growth 2016-03-10

Machine learning has been used for pattern recognition with an astonishing degree of success in a wide range of contexts. Fairly simple algorithms yield over 90% accuracy in reading hand-written digits, and other algorithms make it possible to classify objects appearing in digital images and to identify individuals through facial recognition techniques. But predicting market prices of publicly traded equities proves to be somewhat more difficult because price behavior is subject to significant unforeseeable fluctuations, or noise. After many failed and some partially successful experiments, we have, however, developed a technique for predicting growth with a reasonably high degree of accuracy. More

Object-oriented JavaScript 2014-05-18

A simple piece of library code improves upon JavaScript's native inheritance syntax. More

Modifying existing JavaScript for RequireJS 2014-05-17

I recently organized all of my JavaScript code into RequireJS modules and have some notes on why it's worth it to make the necessary changes in order to get it set up correctly. While you do have to wrap every file in a define() function, a solid directory structure probably won't need to be modified (mine didn't), and dependency management is much easier. For me, the change actually slightly reduced the number of lines of code and cleaned up the global scope a bit. More

Multi-threading in JavaScript 2013-12-06

JavaScript runs in a single thread. Don't let yourself be told otherwise! Ajax calls, setTimeout(), and setInterval() all actually run in one thread and just cause calls to be pushed onto the stack with some delay. But ... there is one exception where you actually can spawn a true, OS-level thread in JavaScript: Workers, which are supported in all major browsers. You can create a worker using the syntax var worker = new Worker('worker.js'); and communicate with it using an onmessage callback. Workers don't have access to the DOM but are useful for offloading computationally intensive JavaScript that could bog down the main thread. Further implementation details on MDN. Additional comments and some performance tests in John Resig's blog.

Multi-tab Chrome extension 2013-11-05

Clicking through the same links over and over again for daily viewing the charts of some stocks I follow, I eventually decided that this would be a good task to automate but couldn't find a browser extension that allowed you to open a preset group of links with one click. So, I built a Chrome extension called Multi-tab to do exactly that.

Java MinHeap implementation 2013-11-01

Working recently on a problem requiring Dijsktra's algorithm, I noticed that Java's native PriorityQueue is missing a necessary decreaseKey() method. I feel sure that the reason for this omission is that this method inevitably exposes too much of the inner workings of the data structure. Specifically, it doesn't make a lot of sense without also implementing a find() method which in turn presupposes that the priority queue is backed by an array (minimally: some object with indices). I agree that exposing the array index is a little ugly, but we really do need a decreaseKey() method. So, I've implemented a MinHeap<T> that does everything that Java's PriorityQueue<T> does but adds the missing method. For shared functionality, the implementation of com.codemelon.util.MinHeap<T> closely follows java.util.PriorityQueue<T> (source here) but in some spots prefers performance over safety. The code for com.codemelon.util.MinHeap<T> can be viewed and downloaded on GitHub.