Blog

Java and Soft References

In a previous post, I described what weak references were and how the JVM interacted with them and how they contrasted with strong references. In summary, a strong reference is what we typically think of as a reference in Java; that is, when we instantiate an object and assign its reference to a variable, that is a strong reference. Obviously, these objects will not be cleared by the garbage collector (GC) until the reference is removed.

By contrast, a weak reference doesn’t prevent the garbage collector from clearing the referred object. That is, if the only references that remain to an object are weak references, that object will be treated as if there are no strong references to it, and thus it will be cleared by the GC on its next run. Weak references are implemented mainly by the WeakReference “wrapper” and WeakHashMap, the latter of which only maintains weak references to the keys, so that once the keys are inaccessible (i.e. no strong references exist), the WeakHashMap will automatically drop/remove the corresponding entries, which can also make the value objects eligible for GC so as long as there are no other references to them.

But how do these references contrast with a soft reference?

Continued

Analysis of the 2011-2015 Boston Marathon results

I recently analyzed the 2011-2015 Boston Marathon results. You can see the results in this GitHub Repo, or go straight to the IPython/Jupyter Notebook for the details.

Boston’s getting competitive Continued

Converting an IPython Notebook to PDF

If you have an IPython Notebook (*.ipynb file), you may want to convert to PDF for distribution. If you read the documentation for ipython nbconvert, it seems fairly straightforward:

$ ipython nbconvert --to PDF <your notebook>.ipynb</your> Continued

Remote Python debugging using PyDev/LiClipse for OpenStack Swift

We all know what debugging is – stepping through running code, line by line, inspecting variables and trying to figure out what’s wrong with your program while simultaneously tearing your hair out. However, usually when debugging Python code, the Python process is running locally on your system. What happens if you want to debug through code running on another server?

This is typically the case when working with OpenStack Swift, since the Swift-all-in-one (SAIO) instructions tell you to use a VM to run your Swift installation in, and a Vagrant VM provided by SwiftStack simplifies this. However, this means that the Swift code is not running locally; it’s running inside of your VM – so how do you debug into it?

Remote debugging aims to solve this by allowing you to inspect, trace and step through code running in a Python process on another machine. Setting this up requires some work, but is well worth the effort when debugging a non-trivial application running on a remote server or VM.

Continued

Accessing the host file system from a Docker container on OS X or Windows

Mounting (or sharing) a directory from the Docker daemon host into a container is simple enough. Example:

$ docker run -v [host directory path]:[container directory path] -it [image name]

However, on OS X and Windows, the Docker daemon (currently) runs inside of a Linux VM, that by default is run using VirtualBox. (Since Docker only runs natively on Linux) So, you’d be mounting a folder from the Linux VM, which is probably not what you want if you want to share files from your host machine into the container.

Continued

Golang: Promoted methods, method sets and embedded types

In Go, interfaces are implemented implicitly by ensuring that the implementing type’s method set contains all the methods of the interface. That is, if a type A contains a method set that is a superset of interface I’s method set, then type A implements interface I.

This seems pretty straightforward, but can get a little convoluted when dealing with struct types that have embedded/anonymous fields.

Continued

Converting CAD to USD using the DLR ETF

If you’re converting a large amount of CAD to USD (to buy US-listed/denominated securities, or to purchase US goods, or whatever) the spreads your bank offers you may not be the best way. Instead, if you have a brokerage account (one for both CAD and USD), you can use the Horizons DLR ETF to do the conversion for a lower cost.

Horizons has a nice PDF detailing the procedure, but I wanted to go through my experience with the process.

Continued

Python script to search CBC Radio 2 broadcast/play log history

I’m a fan of CBC Radio 2. Okay, that’s not exactly true, but I do have my $10 radio alarm clock tuned to 94.1 FM to wake me on weekdays. I often find myself in a stupor or only semi-awake when the tunes start blasting away before dawn, and as such, I often have trouble remembering what was exactly on the radio that morning. However, once during the day I remembered that a certain Ben Folds Five song had received airtime on CBC Radio 2 during my morning wake-up, but could not recall the exact day. It bothered me.

Thankfully, they did have broadcast/play logs of all tracks they had aired, along with the date/times, providing for a succinct history. Unfortunately, it didn’t seem possible to search them, and I didn’t feel like searching through each day’s play log for the particular title. What to do?

Scripting to the rescue!

Continued

React animations for a single component

React is a great framework for building web UIs. (And perhaps other UIs as well) I’ve recently started using it in some side projects, and love its ability to easily manage view state and efficiently update the DOM, reducing a lot of the “grunt work” of building dynamic web UIs. On the other hand, it feels relatively lightweight in that it doesn’t impose a lot of structure in how you design your app. This may be a Good or a Bad thing, but the upside is that there isn’t a steep learning curve.

One thing I recently wanted to do with React was to build a component that would animate during its transition from state A to B; an example would be an On/Off button. It is possible to do so with React’s built-in animation addon, but it just required some attention to detail.

Continued

RequireJS shim configuration, jQuery plugins and enforceDefine

If you’re using RequireJS’s shim configuration to load jQuery plugins while setting enforceDefine: true in your configuration, you probably noticed the following uncaught error in your JavaScript console: (The following example is for the iCheck plugin)

Uncaught Error: No define call for iCheck
http://requirejs.org/docs/errors.html#nodefine Continued
View all entries by month or by category