Wednesday, 16 December 2015

Alexa! How art thou?

As some of you might know, I will be moving into my own new home with my wife very soon. I have been looking forward to it for the past three years - Yes! that's how long HDB now takes to complete a 16-storey flat. Those of you still waiting and planning for your home, ROM and wedding, I'll suggest that you plan it early as your home keys will most likely arrive much faster than expected.

Okay, HDB flats aside.

Lo and behold, the Amazon Echo, also known as Alexa, arrived in my mailbox about a month ago. I purchased it during the Amazon's Black Friday sales (USD 149) and its amazing...

The Amazon Echo (aka Alexa)

Consideration #1 - Alexa is designed for local content in USA


One of my main considerations into getting Alexa was that it's designed mainly to be used in the United States. That means that getting Alexa to work on local content will mostly be locked to USA contents (e.g. Timezone, weather and news). This can be fixed by specifying "Singapore" in your commands. Say "Alexa, how's the weather in Singapore" or "Alexa, what's the time in Singapore". There's also a setting in the companion app that you can use to indicate distances in KM instead of Miles, and temperature in Celsius instead of Fahrenheit.

[update]
Maybe you are fellow techie, you could hack it (see here for details) to change the time zone to Singapore instead. Then, you will get the correct local time when asking Alexa. However, not much luck at the moment for the weather information, you still need to ask Alexa by specifying "Singapore" in your command. Note: If you followed the link and have tried it, you can use "Asia/Singapore" for the timezoneid parameter.

Consideration #2 - Power voltage requirements


As most travellers would know by now, the voltage in USA is 110V, whereas most of the rest of the world uses 220-240V. Fortunately, Alexa is a dual voltage appliance, it means that it can accept the voltage here in Singapore too. You just need to get a plug converter to connect it to our 3-pin socket.

Summary

So there you go, Alexa is a niffy virtual assistant that works pretty well in recognizing our Singapore English accent and do its stuffs. To show the other useful features of Alexa, I will be writing a separate post about the home devices/appliances that are integrated with Alexa.




Tuesday, 6 October 2015

Coursera: What it is like


Founded in 2012, Coursera is a Massive Open Online Courses (MOOC) platform. Yes, the term MOOC itself is worthy to be a subject of another post altogether. Without digressing too much, I shall keep this post focused on my own experience with Coursera courses (what about MOOC? perhaps I shall write another post on MOOC in future). 

So, if you have been sitting on the fence and pondering whether should you start signing up for online courses. Here, I hope this post aids you in your decision to take up an online course, a Coursera course.

Okay, So I've heard of Coursera, what exactly is it?

Basically Coursera works with top universities and educational organisations to make some of their courses available online. In this regard, it has a really wide range of courses in multiple disciplines; such as Computer Science, business, mathematics, humanities, sciences, marketing, etc. In short, you could almost always browse through their catelog everytime and might still be able to pick out one or two courses that are of interest to you.

That sounds good. But is it free?

So far, most courses I've found are "Accessible for free", this means you have access to the lecture videos, notes, quizzes and exams (unless not applicable for the course) after signing up for it. 

The course materials alone should be sufficient for one to kick start their self-study and exploration into the topic of interest.

Does it come with a certification?

Most courses have a "Signature Track", which you pays a fee to get verified certificates, often useful for career development. However you do need to verify and authenticate your work submissions by sending webcam photos and having their typing patterns recorded.

But I don't have much time for a course..

For one, taking a Coursera course is an easy way to work out your brain, in terms of learning new domains of interest. That's all good things, but, in order to enjoy a course effectively, however, you have to be fully committed to the lectures, review material, quizzes, and must be interested in the topic.

With that said, do expect to commit at least 8-10 hours per week attending lectures and completing assignments and perhaps, exams. 

As a first time user myself, initially I have signed up for multiple courses that was really interesting to me (hey, its free anyways). But I soon realised the difficulty of keep up with all the lectures, assignments and coursework. Then, the necessary decision came for me to start dropping courses in order to ensure maximum efficiency in those that I was most interested in.

In the end, I took "Cloud Computing Applications", provided by University of Illinois Urbana-Champaign. This was a 5 weeks course, with video lectures (about 10-25 minutes long) which were packed with material and content being taught by college professors. 


Interaction with other students?

The forum is one of the main avenues for course participants and staffs to get in touch and help one another (apart from their course Facebook page which I decided not to join). 

In the forums, detailed explanations of concepts and tips for the assignments or coursework can be found there. Hence, I highly recommend one to contribute to the forum to help others as you also would find help there too.

Any final tips?

Picking the right course is especially important if you are working full time at an organisation, or a full time student at a university. I recommend picking just one course that you know you'll enjoy most and that you will get a lot out of.

For this first course, experience the course mechanics and understand its requirements first, before determining if you can keep up the course commitments. Of course, spending time on the course is also important as like any regular class, they require revision, focus and studying.

Ask questions in the forum and discuss the topic with other students. You will find that you learn best when you contribute in helping others and getting help yourself at the same time. Rest assured the teachers will look at the posts and answer promptly.

Lastly, try it out. And I hope you have a good experience at Coursera, just as I did. 


Monday, 5 October 2015

Best Practices for Software Version Control

This post contains some of the best practices for using version control systems in your project (for ease of reference, I shall refer to it as SVN). As a software developer, you will almost definitely used one of the variants of version control systems (e.g. JDeveloper's SVN plugin, TortoiseSVN..), thus good version control practices are as important as good programming practices. The recommendations listed in this wiki are by no means exhaustive, but the principles should easily transfer to other systems as well.




Here are 3 tips:

1. Commit often and in logical chunks

The basic work cycle is always update your working copy before doing any changes to files. By doing “update to head”, resolve any conflicts, run a build and make sure there are no failures before checking in code. In general, it is preferred to commit changes in logical chunks. This means that changes that belong together should be committed together, changes that don't shouldn't.

If many code changes are done to a project at the same time, split them up in to logical parts and commit them in multiple sessions. This makes it much easier to track the history of individual changes, which will save time when trying to find and fix bugs or doing code reviews.


2. Write meaningful commit comments

Although often under-utilised, comments should be brief but detailed enough to describe what was changed. If several changes were made, write one line or sentence about each part. If the list of changes gets too long, consider splitting the commit into smaller parts. Otherwise, it can be problematic when code commits are not fine-grained, e.g. submit a week's worth of changes to multiple modules in a large pile. Thus, comments can be very useful to distinguish trivial from non-trivial changes in the repository.

Prefix your comments with Identifiers

Prefixing commit comments with identifiers is a good way to indicate the type of change made. It also allows easier filtering of content later when we do code reviews.


Identifier 
Indication 
FIX
Issue fixes / Improvements
ADD
Change Requests / New files
REMOVE
Delete files
TEST
Add/remove logs for debugging purposes
DOCS
Documentation only changes e.g. code comment
STYLE
Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)

Reference the Bug ID


If the change is about fixing a specific bug, do reference the bug number in the commit message (assuming your project has some sort of bug tracking database or system).

3. Do all file operations in SVN

Whenever there is a need to copy, delete, move or rename files or folders in the repository, do so using the corresponding file operations in the version control system. If this is done only on the local file system, the history of those changes will be lost forever.

Conclusion

Consider giving the above suggestions a try, you might like it. Please share your thoughts and feel free to add on to the list of best practices too. If you are interested in more practices on working with SVN, this is a recommended book:

Version Control with Subversion, by Ben Collins-Sussman, Brian W. Fitzpatrick and C. Michael Pilato

Wednesday, 30 September 2015

Virtual Reality on Budget

Virtual Reality is a term that we are all familiar with, and would glad-fully be better off experiencing it ourselves. Until recently, VR has been an experience that's not very often associated with the word "Budget".

A couple days back, I purchased this VR headset for less than SGD25 from an online store, with shipping of course (may cost lesser elsewhere if you do more searching online).

VR Headset


This headset claims to turn your smartphone into a 3D cinema in an instant, and that you could enjoy virtual reality anytime and anywhere. This fits most smartphones with screen size 3.5 to 6 inches. Thus, compatible with my trusty Samsung Note 3 (tempted to remove my privacy filter on my phone to improve the visuals).

VR Headset (Open)

The Experience

Well, it was indeed an experience worth spending my 25 bucks on. The phone mounting is steady and holds up well to minor head movements while wearing it. With my Note 3 in there, the weight of the entire headset was acceptable and not too demanding (of course larger sized phones increases the weight of the whole thing).

Using it with my headphones (or earpiece) complements the immersive experience. You might want to use a phone with a decent screen resolution that still looks good while viewing up close, without looking too pixelised. For comparison, my Note 3 has a screen of 386 ppi (pixel density) and 1080 x 1920 pixels (Screen Resolution). Yes, most of the current latest phones would beat that, but hey.. its from 2013 anyways.

What about the apps? I would recommend some of these apps below, as I've gotten a fairly decent experience with them for the past couple of days.

"An expanding universe of Virtual Reality experiences. Viewable with or without Cardboard. Fully immerse yourself in 3D VR or full screen 360 featured stories, with dynamically changing directional binaural sound."
Comment: The downloadable original videos are of very good quality. The videos are quite generally quite large (200MB to more than 1GB). Ensure you are on wifi and not on cellular data, hopefully.

2. Mad Race VR
"Take part in the incredible race! Make dizzying jumps and unbelievable stunts! Feel yourself like a virtual pilot of buggy!"
Comment: Pair it with your headphones and enjoy the immersive yet crazy car race through obstacles. 
3. VR Cinema
"Imagine you are watching an exclusive motion picture. Feel complete penetration into the film, on a large screen, right at home, in your favourite cosy arm-chair."
Comment: One of my favourite. Download some video files onto your phone and watch it on the virtual cinema big screen, all in good virtual reality. While at it, remember to look around you and see the cinema surroundings and seats (you are alone in the cinema, so don't expect to see anyone else). 
One handy feature though, it auto corrects and centralises the big screen in front of you, so it has less drifting issues that might be found in other cinema apps.
4. YouTube! 
A simple search on YouTube for "side by side 3d" could get you some pretty awesome 3D experiences.
So there you go. If you are a VR fan too, do feel free to share other good apps for VR/3D. 

Tuesday, 29 September 2015

ConcurrentHashMap over Hashtable for cache lookup

A Legacy Class?

Hashtable is a legacy class before Java Collections Framewpork (JCF) was introduced. The synchronized methods of Hashtable obtain lock on the entire hashtable object during any retrieval or update operations. This can lead to increased response time under heavy load and impacts performance.

A better alternative?

Java SE 5 introduced ConcurrentHashMap, a map implementation which provides better concurrency and scalability as compared to Hashtable. Since the underlying data is stored in a series of buckets in a hashmap (note that a hashtable is also a hashmap implementation), it would be more efficient to lock only a bucket while accessing a map instead of obtaining lock on the entire map.

In other words, ConcurrentHashMap uses this mechanism which provides multiple bucket locks and reduces lock contention when multiple threads access a ConcurrentHashMap object concurrently. This improves performance over a Hashtable, especially in a highly concurrent system.


Multiple internal buckets of ConcurrentHashMap 

Simple Benchmark (in milliseconds)

Hashtable
Cache put (100,000 objects): 626.8
Cache get (100,000 objects): 0.45
Cache put (500,000 objects): 3,544.6
Cache get (500,000 objects): 0.47

ConcurrentHashMap
Cache put (100,000 objects): 501.2
Cache get (100,000 objects): 0.22
Cache put (500,000 objects): 3,159
Cache get (500,000 objects): 0.24

Summary

In summary, both classes are thread-safe. In terms of performance, ConcurrentHashMap also performs better than HashTable with improvements in object put/get in/from cache. Developers should consider replacing usage of Hashtable with ConcurrentHashMaps in projects to improve performance and efficiency.

Monday, 28 September 2015

Double alternatives for precise arithmetic

We sure have used double data type in our programming while performing simple or complex arithmetic calculations. Doubles tend to be good enough for most applications (not involving money of course), because if you are dealing with money, you need exact precision. 

Consider this:
double first = 2.00; 
double second = 1.10; 
System.out.println(first - second);
The result?
0.8999999999999999
The problem comes when double suffers from a "loss of precision" and becomes very noticeable when working with either very big numbers or very small numbers. You may be tempted to use print formatting to set the precision in terms of decimal placings, but that still do not solve the root issue.

Especially for monetary-critical applications, (i) you may want to consider using BigDecimal as it is an exact way of representing numbers. With BigDecimal this would not happen. (ii) use int or long to represent cents.

1. Using BigDecimal

Example
BigDecimal first = new BigDecimal("2.00"); 
BigDecimal second = new BigDecimal("1.10"); 
System.out.println(first.subtract(second));
Returns 
0.90
When using BigDecimal, note that it'll take up more memory, creates more garbage and is probably slower for most operations, as compared to using primitive types.


2. Using int or long

Example
System.out.println((200 - 110) + " cents");
Returns
90 cents 
In summary, avoid floating point calculations (e.g. float, double) when working with monetary or precision-critical applications. Consider greatly the use of int, long or BigDecimal instead.