Posts

Ubuntu alongside Windows on HP ProBook 450 G2 (dual-boot)

IMPORTANT NOTE : Do not try any of the following unless you have fully backed-up your files and after you have created Recovery Media on DVDs (i.e. a Windows 7 Installation DVD and a HP Drivers and Tools DVD) using the instructions provided by HP. NOTE : This guide is for people who already know how to install Windows and Ubuntu/Linux. It focuses on specific issues pertinent to this specific laptop. For general installation instructions you must find another source. DISCLAIMER : Installing an operating system that is not supplied by the hardware vendor may cause your computer to malfunction and/or void its warranty. The decision to perform such an installation is wholly your's (the reader's). The author holds no responsibility in case of damages due to reading and/or following the procedures described in this post. I spent so much time trying to dual-boot Ubuntu 14.04 (64bit) and Windows 7 (64bit) on a HP ProBook 450 G2 laptop, that I figured I should share the knowled

How to efficiently replace multiple characters in a Java String

The problem of string transformation and manipulation is so common that every programming language offers either special features about it or, at the very least, a standard library with basic solutions. In Java there's both regular expression matching /replacement via its standard library, and various “replace” operations that may be directly called on a String object. The replace operations return a new String, as in Java there can be no in-place replacement of String contents; String objects are immutable. One problem that is common enough, in my opinion, to justify the development of a special method to handle it is this: replacing multiple characters in a String at once (in one go). There are three kinds of replacements that we want to handle: Replacing a character with another single character. This kind of replacement does not affect the length of the original string. Replacing a single character with a sequence of characters (a string). This kind of replacement w

Observable properties: A means to track state changes in Java objects

An example application of the Observer design pattern using Java In one of my recent pet projects I needed objects that should be "aware" that one or more of their properties had changed. The obvious way to do it of course is to write code inside the "setter method" of each property and call whatever code must be executed in the event of a change. Something like that: void setName(String name) { this.name = name; onNameChanged(); } void onNameChanged() { // do whatever is necessary here } But what I really wanted was to attach an "on change" event to some of the object's properties and handle this event in a systematic way. I thought this was a valid opportunity to use the Observer design pattern and have the properties of the object notify their owner that they had changed. We can assume that each property is not any more a simple object of a given type T, but an instance of an "observable object" that contains a value of type

Quicksort rewritten in tail-recursive form

An example using the Scala programming language I am currently learning Scala and I became quite intrigued by the compiler's ability to optimize tail-recursive calls. For those unfamiliar with the concept, a tail-recursive method can be optimized to be executed in constant stack space. This practically means that the recursion is not really necessary and that the method in question could be implemented as a simple iterative process! Nevertheless, it is nice to have the compiler do the trick of converting the recursion into a loop and let the programmers express their ideas using recursion. As an exercise, I set out to convert the renown Quicksort algorithm into tail-recursive form. But first, why would this algorithm need any conversion whatsoever? Let us see an implementation of the algorithm written in Scala. I am using the following piece of code as it appears in “Scala By Example” by Martin Odersky (draft of May 24, 2011). It is a straightforward implementation of Qui