I attended a weekly meetup organized by NUS Hackers last Friday, and on that day, the speaker was a professor from my very own university itself, Dr. John L. Gustafson. He talked about the problems of the currently widely use (if not de facto standard) IEEE 754 floating point representation, which he said the usage of it is dangerous, calling it "weapons of math destruction". He touched on some very interesting points, such as why they designed it such that it has a huge number of exponent bits, the existence of too many representation of NaN, how it didn't fulfil even the most basic mathematical properties such as commutativity, associativity, and distributivity. A little note on commutativity, he mentioned that compilers nowadays "solved" the commutativity problem by always doing arithmetic operation of "smaller <operand> higher", whether you write the higher or smaller number as the first argument, which I think is funny but at least it works. He also went on to tell stories of when IEEE 754 caused some accidents and mishaps to happen due to its inaccuracie, some are plain funny but others are somewhat tragic.
He went on to explain to us his proposed float representation, which he calls "posits" and "valids". Posits are very similar in terms of purpose to IEEE 754; the difference is just their ways of representing numbers. Valids are for those mathematicians who need precise, accurate answers and want to be sure to know if the number the floating point representation represent is not actually accurate; something the currently available representations cannot do.
I found the representation system he proposed to be mindblowing. In a nutshell, it uses much fewer bits to represent the same number as compared to its IEEE 754 equivalent, but with a much higher precision. Another interesting point is that it can represent integers and low decimal points floats very precisely, so there's no way you can end up with 0.1+0.1 != 0.2; 1 + 0 = 1.0...0234... and so on. There is also only one way to represent 0, unlike +0 and -0 on IEEE 754. NaN is also eliminated, leaving much more bits to be used to allow higher precision. It may sound too good to be true to some, and to be honest, I haven't seen it in action, nor do I understand fully how it works, but from the high level overview I understand from the talk, it sounds really promising.
For those of you who are interested in his floating point representation proposal, NUS Hackers had very kindly shared the talk slides on Google Drive, so go ahead and take a look! Let me know if the link is down so I can request for the new link from them!
Also, you can get a more comprehensive explanation on the floating point representation he is working on in his book, The End of Error. However, note that the representation he talked about in the book is "outdated". The one in the slides I shared with you earlier is his work which was just completed a couple of months ago, so there might be some discrepancies with what I have said and what you read on the book itself.
I really hope his proposal will pass the IEEE committee and it will be in the mainstream soon. I shall end off this post using Dr. Gustafson's own words, taken from the slides itself. Let's "Make Single Precision Great Again".
A blog about my journey in NUS School of Computing, my personal projects, and all things related to computing! =D
Monday, March 20, 2017
Monday, February 27, 2017
Setting PostgreSQL Environment Variables on Windows (pg_env.bat)?
I needed to have postgres commands available in the command line, and found this script called pg_env.bat when I was trying to add the bin directory into my
PATH environment variables. Running it from the command line does not produce any error message, and the postgres commands work fine too, however when I was running a make script it throws an error like this (truncated, I lost the actual, full error message): Error [WinError 2] The system cannot find the file specified while executing command git config --get-regexp remote\..*\.url
Turns out the answer is that I need to edit the bat script and remove the quotation marks on the line where it is adding it to
PATH (@SET PATH="...";%PATH%). Remove both of the " quotation marks and it should work.
Turned out it was reported 5 years ago and for some reason they have not acted on it. I hope they fix it soon.
Something interesting to know, I found another thread that requested them to do the exact opposite, so I do not know which one supposed to be correct, but in any case, without quotes
" works in my case.
Hopefully this helps anyone else facing the same issue!
Sunday, March 27, 2016
Comparing School-Based (Internal) and External Open-source Projects
This post is written for the purpose of fulfilling requirement for the Facebook Open Academy course I take in NUS.
For almost one semester now, I have been working on two open-source projects that are quite different in nature. The first one is an open-source project being used by developers who wanted to use WebSocket in their web application, and maintained by a handful of developers from different parts of the world; Socket.IO. The other one is also an open-source project, but it is being developed mainly by students (and a large number of them in certain period), and with lesser variety (and probably quantity as well) of users; PowerPointLabs.
For almost one semester now, I have been working on two open-source projects that are quite different in nature. The first one is an open-source project being used by developers who wanted to use WebSocket in their web application, and maintained by a handful of developers from different parts of the world; Socket.IO. The other one is also an open-source project, but it is being developed mainly by students (and a large number of them in certain period), and with lesser variety (and probably quantity as well) of users; PowerPointLabs.
Organization
Being school-based project, I found PowerPointLabs to be more organized in the way it writes the guide for contributing. This does not come as a surprise, as most of the developers are actually students who have little or no prior experience contributing to an open-source project. In contrast, guide for contributing to Socket.IO is practically non-existent; the only guide they provided in the website is the guide on how to use the Socket.IO itself, not how to contribute to it. This is also very normal because being a library, most developers who visit the website/Github page are probably intending to use the library instead of contributing to it.
Also, getting Pull Requests to be merged into school-based open-source project is somewhat more difficult than getting the same done in external projects. This is because for the school-based one, strict review is carried out to instil good coding practice to the students. On the other hand, most open-source project out there are not very particular about coding practice, as long as it is not detrimental to the functionalities of the project. Moreover, most people who contributed to crucial parts of the project are most probably experienced developers anyway so there is no need to have such a strict review system. If the project owner/maintainer is particular about certain coding standards, he/she can always incorporate linting to the project (which is what I did for the course).
Ease of Contributing
Ease of contributing is not quite the same as ease of getting pull request to be merged; ease of contributing here refers to having something to contribute upon in the first place.
Contributing to internal open-source projects are easy. This is because the projects are there with exactly that purpose; for students to contribute to it.
Contributing to external open-source projects are much more difficult as most of such projects are already mature. Usually contributions from external developers (not the project's core team) is in the form of bugfixes, which is arguably more difficult to do than implementing new features for internal projects. This is because the developers of the external open-source projects are usually experienced developers and thus bugs in their code are usually mistakes that can not be easily fixed.
This is in contrast to internal projects where non-critical bugs are left on purpose so that the students can familiarize themselves with the code base; there is no such a thing in external open-source projects.
Rate of Development
Most open-source projects out there usually have a relatively longer release cycle compared to school-based open-source projects. This is because most open-source project contributors have full-time jobs or other commitments, and thus cannot afford to work on the open-source project full time. This sometimes results in long outstanding pull requests (especially if it is not a critical bugfix). Also, the project's main developers come from different parts of the world, and thus the different time zones the different developers live in may impact the rate of development as different developers are awake on different timings.
On the other hand, students may be considered as working on the project full-time and thus the release cycle tends to be much shorter, and I have yet to encounter an unattended long, outstanding pull request in PowerPointLabs or any other NUS projects unless if it is the student sending the pull request ignoring the feedback from the core developer team.
Suggestions for Improvement
There is always a room for improvements, be it for the internal school-based projects or the external ones.
For the external projects, it may be good to have more than one person to be in-charge of a project so as to prevent long outstanding pull request if the person in-charge is busy with other commitments. This is especially important if the project is listed on university programmes such as Facebook Open Academy or Google Summer of Code, when the rate of development will increase tremendously due to the extra manpower during the period.
For the internal projects, I feel that there is not much suggestion I can provide in terms of workflow; I think the current workflow works well to serve its purpose. However, I have the feeling that school-based projects have features that is not very well-polished. It could be better to focus the effort on polishing existing features first before implementing new ones. I think doing a product that do a few things but doing it well is better than a product that can do a lot of things but not good at any of it.
Conclusion and Closing
In conclusion, I think internal (school-based) open-source projects are much more organized in terms of contribution guide, are easier to contribute to, and are faster in release cycle than external open-source projects. External projects can do better by having multiple people in charge of the development so that they can fill in the other person if he/she is busy with other commitments. Internal projects may try to focus more on polishing existing features, which I think is the better approach, instead of keep releasing new features.
Sunday, March 20, 2016
Git vs Mercurial workflow: History, Commit, and Branching
This is going to be another Git vs Mercurial post, which is already widely available on the cyberspace (this, this, this… I can go on) but I am writing another one nevertheless because I feel that many of such posts are written with so much hatred (especially those that is in favour of Git, unfortunately). So this post is going to be one of those Git vs Hg post where the author is in favour of Git but not trying to bash Mercurial (too hard, hopefully). Also, I am going to focus on the similarity and difference in workflow instead of functionalities, though differences in workflow will inevitably also bring about some differences in features into the discussion, but I will try to minimize it.
Note: This post assumes some basic knowledge of Git and Mercurial commands.
Attitude towards commit/changeset history
In Mercurial, history are “sacred” and not to be manipulated. The only command that a user can do out-of-the-box that can edit history is only
hg revert, which only removes the last changeset. To manipulate further down the history, Mercurial extensions are available, but they are tedious to use and confusing at best (speaking from my experience using Mercurial on a project 2 years ago). For Git users like myself, this is a huge annoyance as we are used to “fixing” history to make it look nicer and more easily traceable in the future.
Git, on the other hand, allows users to manipulate commit history to their hearts’ content. In fact, it seems to be encouraged, evident from how easy it is to do so (
git rebase, git rebase -i, git push -f, and many other relatively short commands that changes history). This allows the creation of a better-looking, more linear commit history. However, inexperienced user may break the entire repo with it. Luckily, Git keeps track of everything and one can go back to the exact state before the accident happened (provided it didn’t happen more than a month ago; plenty of time to realize something bad has happened, if you ask me).Commit workflow
In Git, there are 4 states a file can be in; untracked, unstaged, staged, and committed. To move a file (or more precisely, a change/modification) from untracked or unstaged to the staged state, use
git addand to move to the committed stage, use git commit.
In comparison, in Mercurial there are only 3 states; untracked, uncommitted and committed. To move a file from untracked to uncommitted, use
hg add and to commit use hg commit.
The difference here is that in Git, the user can choose not to commit all changes in the working directory (using
git add <filename> or git add --patch, for example). This is useful to make a commit atomic (which is part of Git’s or any version control system’s best practices), or if you have finished work in some files but not in others. In contrast, in Mercurial, there is no staging state and hg commitautomatically commits all changes in the working directory. If you came from Git background like myself, you will find yourself repeatedly committing unfinished work, and what’s worse, it is difficult to fix the messy history due to that mistake! That was the pain I personally went through in the Mercurial project I worked on 2 years ago.
There are Mercurial extension that mimics this Git behavior, but I have not used it personally so I cannot comment on it. However, from what I have found on the Internet, it seems to be a decent replacement for users coming from Git background using Mercurial.
Branching
In Git, there is only one way to branch (though there are a few commands to create a new branch but that’s beside the point). Any divergence in commit history is a branch, and the name of the branch is namespaced according to which repository the branch originates from.
For example, if I have a branch called
test which tracks a remote branch with the same name, if at some point in time my local branch and the remote branch diverges, when it is being merged, the remote one will be called remote/test. There is no other “branching” method.
In Mercurial, there are at least 3 ways of branching.
The first one is a clone-branch. This seems to be the initially-intended branching workflow of Mercurial, evident from the “local-cloning-optimization” feature they have called “hardlink” which makes cloning from a local repo faster. This, however, is not a feasible branching workflow for certain types of projects where dependencies need to be downloaded separately (through
npm or pip, for example) for each repo.
The second branching workflow that Mercurial supports is called named-branch. It is quite similar to Git branch in that one can
update (or checkout in Git terminology) to the latest commit on that branch. In Mercurial, however, named-branch is not a light-weight pointer to a HEAD just like in Git, but is something that is included in a changeset’s (or commit, in Git terminology) meta-data. There are some implications that people from Git’s world don’t really like (such as cluttering the revision history with short-lived branches and needing to “close” a branch with an extranous commit). On the other hand, it could be useful when tracing the history. But then again I have worked with Git for quite a while and I have never encountered a problem where I need to know the name of the branch a commit was from, so the usefulness is questionable.
The last branching workflow that Mercurial has is bookmarks. This is (claimed to be) the Git-branching equivalent in Mercurial. However, having used it in one of my projects 2 years ago, I find that they are not quite the same. In fact, I find that Mercurial’s named branch is more similar to Git branch than Mercurial bookmark is simiar to Git branch. In Git, you are always working on a branch, so whenever you commit, you commit to a branch and other people who pull your work knows that your commit belong to a certain branch. In contrast, you are not always on a bookmark in Mercurial, and thus people may accidentally committed when he is not on a bookmark, requiring the user to manually move thebookmark to the intended changeset. Also, when sending a pull request, the name of the bookmark is not shown. Instead, the hash of the changeset is written as the “branch name”. This makes me doubt the claim that bookmark is really the Mercurial equivalent of Git branch.
Arguably, there is another Mercurial branching workflow, which is simply not to do anything about it. If there is a divergence from a certain changeset, simply don’t do anything about it. Users can refer to a “branch” by the hash or revision number of the tip of the “branch” he/she intends to work on. This is good for quick fixes, but is not suitable for development branch as it will be difficult to keep track which “branch” is doing what. I am unsure if it is one of the intended way to use Mercurial.
Conclusion on Branching
In my opinion, Git’s branch workflow is better, as it is more consistent (i.e. there is only one way to do it). If I were to use Mercurial, though, I would probably use the named-branch workflow as it is much more manageable than all the other Mercurial branch workflow.
One may argue that Git also has some divergence in terms of branch workflow, namely "to
merge or torebase". In my opinion, it is actually what makes Git great; you have the option whether to preserve history as it is or to make a cleaner, nice-looking history. In contrast, Mercurial’s different branch workflows are not really “options” but rather inconsistency on Mercurial’s default development workflow. I mean, I can’t really think of the benefit of using the clone-branch workflow, or bookmark-branch workflow over any of the other options. But then again, maybe I have not used Mercurial enough to discover the different benefits and disadvantage of the different ways of branching in Mercurial.
Just to reiterate, I wrote a comparison of two of the most popular distributed version control systems in terms of their attitudes towards history, commit workflow, and branching. I found that Git’s way of doing things to be better than that of Mercurial’s because of the flexibility and consistency that Git provides.
Feel free to point out any mistakes in my post. I have not used Mercurial for quite a while so probably some information is outdated, but I did some research before posting this so it should not be too outdated.
Other references not linked on the post itself:
- Source on the different Mercurial branch workflows here.
- http://blogs.atlassian.com/2012/02/mercurial-vs-git-why-mercurial/
- http://blogs.atlassian.com/2012/03/git-vs-mercurial-why-git/
Friday, March 4, 2016
Git tips and best practices
This post is intended for you developers who have just started using Git, or perhaps have been using it for a while, but have not been using it optimally. Here are some tips to level up your Git mastery; to make your project more manageable and organised.
Note that some of the tips here are in the context of working with Git and Github, but Github can always be replaced with any other repository hosting website like Gitlab, Bitbucket etc.
Another note: if your team already has a Git policy, please do obey them if it is in confict with whatever I have here below. This is by no means is the only correct way to do things, but it is what works best for me so far.
Another note: if your team already has a Git policy, please do obey them if it is in confict with whatever I have here below. This is by no means is the only correct way to do things, but it is what works best for me so far.
Tips for Novice Users
Always pull (or even better, fetch) before committing locally
This is to prevent too many “Merge remote tracking branch …” commits which are not very descriptive and give more work to people who are investigating commit history , as they need to open the commit to know what changes instead of by just reading the commit message.
Just to give a brief explanation, this happens because the branch in your local repo and the remote repo has diverged. Let’s say the last commit on the branch when you were working on it was
A and then you go ahead and add another commit B. However, someone else actually already pushed a commit C to the same branch. Now if you try to push your local changes, the server (eg Github) will reject it because for all it knows, the next commit after A is C, however what you have after A is B, which is inconsistent with what the server has. If you do a git pull, because Git cannot decide which commit should come first before the other, it will just create an extra merge commit. (I will add a diagram to show this more clearly)fetch is potentially better if you are working on a shared feature branch that might be rebased once in a while. This is to notify you if the branch is being push --forced and you should handle it accordingly (hint: not pull) by either deleting the local branch and checkout the new one, or git reset --hard <remotename>/<branchname>. Make sure you are on the right branch before you do the latter!Each commit should be as atomic as possible
The most common bad practice of someone who just started off using any version control system is that they think it is just another way of saving and backing up their work to the cloud. While this is not entirely wrong, it leads to weird commit messages as the commit author has not actually finished what he is doing; it was just a commit to “save” his work.
A slightly better bad practice is that they commit only when the work they intended to do is done, and write what they did as the commit message accordingly. However there are more changes in the commit than what is described in the message. It may catch people who investigate commit history off guard because they did not realize some functionalities are incorporated into the branch. It also prevents the use of
cherry-pick. Of course, one can use merge in place of cherry-pick but as said earlier, merge commit messages are not very meaningful and so it is better to do cherry-pick.| Commit message is "added eslint" but there are some refactoring too |
There are many other benefits of committing atomically; another example is that it makes
rebase -imuch easier. If you are still a beginner, you most probably won’t be doing a lot of rebase and cherry-pick (if at all) but your more experienced teammates will thank you for this, trust me.If you are collaborating on a shared repo: always create a feature branch
No matter how small the team is, how small the project is, how small the changes you intended to make;
master branch should never be touched except for merging from feature branches or syncing with upstream repo (if you are forking another repo).Aliases
Sometimes writing git commands that is relatively long (such as
checkout, or log with some prettify options, etc) is just plain annoying, especially when we just want to get it done ASAP, otherwise we lose our train of thoughts. Git alias will allow you to do just that.
To add an alias to those long commands (or simple commonly used commands that you are lazy to write in full), you can go to your global .gitconfig, add a
[alias] section, and add the aliases that you’d like to use accordingly. The file is located in different places in different OS; C:\Users\<User Account Name> on Windows, ~/ on Unix (probably the same on Mac OS).Alternatively, if you are lazy to find it in your file explorer, `git config --global -e` will open up the file using your default text editor.| Adding alias to .gitconfig |
Push only the branch you are currently at
If you find yourself pushing to branches you did not intend to push, you probably installed your Git quite some time ago. To set push to only push the branch you are currently at (instead of all remote-tracking branches) change the push.default config to simple/upstream/current. For more info on each config options look here.
push, you probably installed your Git quite some time ago. To set push to only push the branch you are currently at (instead of all remote-tracking branches) change the push.default config to simple/upstream/current. For more info on each config options look here.Tips for more Advanced Users
git rebase -i before push and/or submitting a Pull Request/merging to master
If you have already been doing the good Git practices in the Beginner’s section, this will bring you up to the next level.
In the course of developing your feature branch, it is very rare that you will have a very nice commit history, as a lot of new feature will involve trials and errors. These failed attempts, however, are usually not useful to be stored in the commit history. One way to get rid of the failed-attempt commits is to use
rebase --interactive or rebase -i for short. There are quite a number of good resources covering that already (this, for example) so I do not intend to cover that again here.
Note that it is best to do this if you have not pushed your feature branch to remote, as someone else who pulled the feature branch will need to create the not-very-meaningful “merge remote tracking branch…” commit, if that other person did a
pull instead of a fetch.
git push --force-with-lease
If you are an advanced user, most probably you are quite familiar with
rebase -i above, and probably you know that you need to do push --force to replace whatever that is on remote with what you have locally. However, if you someone else happen to push to the branch and you do push --forceafterwards, that person’s work will be overwritten by your branch which does not have that commit yet.
There are many ways to solve this, but it is better to prevent it altogether, so introducing:
git push --force-with-lease. What it did is basically checks if the branch is exactly the same as what the one whopush -f expected, i.e. no extra commit from other people. It might be a good idea to set this as an alias as --force-with-lease is quite a mouthful (or a handful?) to write.
That is all for now. This post might be updated in the future (one that is in my backlog is
reflog) so do check back once in a while.Sunday, February 28, 2016
Ubuntu VMware guest stuck/hangs on boot
Apparently there is a bug in one of the recent Linux kernel update on Ubuntu running as a guest OS on VMware. To be exact, the affected kernels are versions 4.2.0-30.35, 3.19.0-51.57, and 3.16.0-62.82 (mine was Ubuntu 14.10 on Linux kernel v3.19.0-51.57). The bug report is here, and in this blog I am going to show the way to solve it (credits to the answer on this askubuntu Q&A forum).
First, you need to get into the
Advanced boot options, which you can access from the GNU GRUB menu.- Start the problematic Ubuntu VM. Hold the
shiftkey on your keyboard until you are redirected to the GNU GRUB menu. If you see the command-prompt-like log that you usually see when you boot your VM up, you missed the point where you should get redirected to the GNU GRUB menu. Restart and try again. Note that when you restart the VM sometimes the VM redirect your keyboard inputs to the host OS instead. Click the VM screen repeatedly to ensure that your keyboard inputs is sent to the guest OS. - Choose
Advanced options for Ubuntu - You will be brought to a screen where there are a list of Ubuntu you can boot into with different kernels and boot mode. Choose any that uses the Linux kernel that is not buggy (refer to the list of buggy kernels I show at the start of this post). You can just choose the default boot mode (no upstart/recovery mode).
- Congratulations! Now you have managed to boot up to your OS!
- There should be an update to the Linux kernel if you check your software updater (I was notified without needing to check manually). Just update and the problem should not occur anymore. If there isn’t any update, you can try Googling to make your VM to boot using the old Linux kernel by default for the time being.
That is all. Note that not all Ubuntu is affected; seems like only Ubuntu on VMware is affected, and only if you happened to update your Ubuntu with the buggy kernel.
Hopefully it helps!
Saturday, February 27, 2016
Integration or Isolation? That's the question
I happened to stumble upon this blog post written by a friend of mine who is also my group mate for the FBOA module I am taking in NUS this semester. The background of the post is actually that he deactivated his Facebook account sometime last year because he feels that Facebook is rather pointless and not the best choice out there as a platform to find information, share his thoughts, or to keep in touch with friends.
I agree with him that Facebook is one of the worst options out there to find information and share your thought. I mean, it is filled with people from all walks of life, and not everyone is as educated as you are, and not everyone is as thoughtful as you are by not sharing pictures of every cat or corgi they saw on the Internet, borderline explicit videos, and those "X things that only YYY understand; number N will make you shocked!" kind of posts. It can be toxic too, seeing the highlights of your friends' lives going for exchange, going on dates, outings, getaway to some exotic place etc etc, while you were there in front of your laptop in your room, living a boring life.
But those are not the main reason I am writing this post (maybe we can discuss about it another day). The post I am talking about is the first one I hyperlinked (or alternatively, here). It was about how one service is tightly integrated to another such that if one service for some reason, God forbid, is down, it will trigger a chain reaction and render us unable to access many of other services. The personal example he mentioned in the post was that he was then unable to use his Spotify because he used Facebook to sign up for his Spotify account.
That brings the question: should different services be isolated from one another? Or should they be integrated with as many others as possible? An argument for isolation is already mentioned above. An argument for integration is that it frees user from filling in the registration/sign-up form and verification hassle that is just way too common. Also, users do not need to remember yet another login ID, nickname, password, or PIN for the new platform he/she is signing up for.
There is no right or wrong answer to this question just yet. This friend of mine seems to be more inclined towards the isolation side, judging from that post. Me, I actually more inclined isolation too, but there are benefits of integration that I do not want to lose (such as no need to remember yet another password).
So what about you? You can just take my (and my friend's) post as fruit for thought, or alternatively you can express your opinion on the comment section! But then again this is just a personal blog that happens to be maintained as I am currently using it for one of my course in university, so don't expect too much discussion except perhaps with me :p.
Wednesday, February 24, 2016
SQL Server Management Studio installation error: "wait on the database engine recovery handle failed"
When I was installing SQL Server Management Studio 2014 a few days ago, I was shown a pop-up at the end of the installation: "wait on the database engine recovery handle failed", and followed by some of the SQL Server MS features failed to be installed.
To be exact, here are the screenshot of the error notifications (not on my computer, credits to the blog who provided me with the solution)
To solve this, the TL;DR version is to just uninstall it and install it again but when you are shown the Server Configuration page, change the Account Name of SQL Server Database Engine service to "NT AUTHORITY\NETWORK SERVICE". After that just click next and everything should be installed correctly.
For me, the above paragraph was sufficient to fix my installation. However, if somehow it does not solve your issue (something about validation error pops up, or anything else), go to the blog where I found this solution and try to follow the complete steps provided.
Hopefully it helps!
To be exact, here are the screenshot of the error notifications (not on my computer, credits to the blog who provided me with the solution)
![]() |
| "wait on the database engine recovery handle failed" |
![]() |
| Features failed to be installed |
For me, the above paragraph was sufficient to fix my installation. However, if somehow it does not solve your issue (something about validation error pops up, or anything else), go to the blog where I found this solution and try to follow the complete steps provided.
Hopefully it helps!
Tuesday, February 16, 2016
FBOA Module: Technical Expertise - Git workflow
As part of the CS3281/2 module requirement I am currently taking in NUS, I have to establish myself as an expert in a topic/field/technology of my choice. Because version control systems are going to stay, and Git is currently (arguably) the most popular version control systems out there, and I have had some experience in it, and I have friends who are good at it (I have one too many and's), it is just natural that I choose Git to fulfil that requirement. This is going to be the first of the series of Git tips and tricks that I will post in this blog, so stay tuned!
Officially, my tech expertise is "Git workflow" because if I declare as just "Git", apparently I am expected to know Git inside out or something. Nevertheless, my Git-related blogposts will not be limited to just Git workflow, but also Git tips and tricks in general.
Some topics that I plan to write about in the next 1-2 months (which is basically the rest of the semester):
1. Git workflow best practices
2. Git rebase + push --force safely
3. Git rebase vs merge, and what is happening in the background
To get the ball rolling, here's a neat trick I got from @rauchg's Retweet on Facebook if you need to find the first commit where a given string first appeared in the source code.
If you want to know what each option actually does, you can refer to git-log documentation page.
That is all for now. Stay tuned for more Git workflow goodness! Happy coding!
Officially, my tech expertise is "Git workflow" because if I declare as just "Git", apparently I am expected to know Git inside out or something. Nevertheless, my Git-related blogposts will not be limited to just Git workflow, but also Git tips and tricks in general.
Some topics that I plan to write about in the next 1-2 months (which is basically the rest of the semester):
1. Git workflow best practices
2. Git rebase + push --force safely
3. Git rebase vs merge, and what is happening in the background
To get the ball rolling, here's a neat trick I got from @rauchg's Retweet on Facebook if you need to find the first commit where a given string first appeared in the source code.
git log --source --all -S <string>
What it returns is basically a list of all commits that contains the string you input as changes (both as addition and deletion). The first commit where it appears is of course, the one at the bottom of the list. If you only need the commit's hash, you can shorten the output by adding the --one-line option to the command. Also, if you want a string longer than one word, you can put the string within quotation marks.If you want to know what each option actually does, you can refer to git-log documentation page.
That is all for now. Stay tuned for more Git workflow goodness! Happy coding!
Wednesday, February 10, 2016
ENOSPC error when running zuul locally
Today I encountered an error when I tried to running zuul locally. It throws an error on a function call to watch a file with error code ENOSPC.
After a quick Google search, I found out that ENOSPC just means that there is insufficient space (probably it stands for Error NO SPaCe). Apparently it happens when you are opening a large number of programs/files. However, at the time I received the error, I only got File Explorer, Terminal, and Sublime Text opened, which is not a large number of programs at all. Further research told me that Sublime is actually implicitly opening a large number of programs if you are using its Open Folder feature so what I did to solve the problem was to close Sublime whenever I wanted to run a zuul test locally.
Hope it helps someone out there who can't figure out what's wrong with their zuul!
After a quick Google search, I found out that ENOSPC just means that there is insufficient space (probably it stands for Error NO SPaCe). Apparently it happens when you are opening a large number of programs/files. However, at the time I received the error, I only got File Explorer, Terminal, and Sublime Text opened, which is not a large number of programs at all. Further research told me that Sublime is actually implicitly opening a large number of programs if you are using its Open Folder feature so what I did to solve the problem was to close Sublime whenever I wanted to run a zuul test locally.
Hope it helps someone out there who can't figure out what's wrong with their zuul!
Sunday, January 31, 2016
Migrating from Browserify to Webpack
As you might have read from my previous post, I am currently enrolled in FBOA and is working on Socket.IO. One of the tasks he gave us was to migrate bundling from using Browserify to using Webpack, and I wrote in my last post that I was not even sure if I was doing it correctly. Well, as it turned out, I was not, because I have not put any bundling options yet.
Anyway, so I start looking for solutions by Googling "webpack equivalent of browserify options" and got this useful link. However, it was not quite enough, because in the repo I was working on, there are some options that are not listed in that link such as browserify's insertGlobalVars option. After some digging, finally I found out that its equivalent in webpack is externals.
Hopefully it is useful to anyone out there doing something similar. Also, if anyone has any other useful webpack equivalent of any other browserify's options, feel free to comment so I can just add it in to the main post! Happy coding!
Disclaimer: It is not my intention in any way to encourage migration from browserify to webpack. I am just helping those who already made the decision. I am no web dev expert in any way.
Saturday, January 23, 2016
The Long Overdue Update: FBOA and Webpack
Hi everyone! Seems like I have only been updating this blog for once a year, huh? Sorry about that; nothing much happened in my life that can be written in this blog anyway. Just to get you all up to speed, I went for an exchange to Tsinghua University in China, which explains why I did not update the blog. I know, using VPN to access blogspot is like just a few clicks difference but then again, as I wrote earlier, nothing particularly significant from what I have been learning that can be put in this blog. During my semester there, I tried to redo an Android Development tutorial, this time from udacity. I also took a module in computer networks though if anything, what I learn is how to make a really fast (but not necessarily scalable) C++ programme instead of anything about computer networks itself.
This coming semester would be totally different. I am enrolled in the Facebook Open Academy (FBOA) programme via NUS under the module code CS3281/2, Thematic Systems Project. If you are curious, I will be working on the open source project Socket.IO. One of the grading aspects of the module is to write a blog post about my progress in the open source project I am working on. Because I am too lazy to create a new one, so I decided to just use this blog. Who knows, this might get the ball rolling for more frequent updates to come!
... And this post is going to be the first of those more frequent updates. My team is assigned to do migration from the tools currently being used by the project to (supposedly, debatable-y) better tools. For example, I am assigned to migrate from using browserify to webpack as the bundling tool. I thought it should not be too difficult (after all, it is our first task given by @rauchg (one of the guys behind socket.io) (I am using too many brackets here)). I guess it is not difficult if you are familiar with web development, but I am not (I should have, but no) so it took me one whole day to figure out how to do it, and I am not even sure if I am doing it correctly.
Learning new tools is never easy. The initial learning curve is almost always very steep, though fortunately it will only get easier over time. Webpack is no exception. I tried reading the Getting Started tutorial the devs provided but I still have no idea how it will fit into the project I am working on. Apparently previously socket.io uses browserify's node.js API and I did not know there is such a thing so I have been trying to integrate the webpack into socket.io's Makefile to no avail.... I thought the 2 tools are very different in terms of how it is being set up. But as it turned out, webpack also has its own node.js API, which I finally found somewhere in the docs. I tried to tweak the test initialization js files and finally managed to make the test runs and passes (yay!). I will probably push and send a pull request tomorrow to let my teammates check it first. After all, I should not be embarrassing NUS by sending some crappy PR, should I?
Sorry if this post is rather confusing or hard to read. It is 3 am in the morning and I just managed to integrate webpack into the project like literally 20 minutes after one whole day of googling so I do not want to have anything to do with it again for the next few hours and wrote this just for my own reference. Anyway, here's to more frequent and higher quality updates in the future!
Friday, May 22, 2015
NUS Module Review: Year 2 Semester 2
Hi everyone! Sorry for not updating this blog more often (in fact it feels like it is never updated at all). Anyway, I finally gathered enough will to post a module review of modules I have taken in NUS. For clarity and organization purpose, I will divide the posts per semester. So here goes the last semester's module review!
CS2102 Database Systems
Lecturer: Stephane Bressan and Zhao Jin
This module is not very interesting, but it is quite useful. You will learn how to CREATE, ALTER, DROP tables, SELECT, UPDATE, and DELETE entries, and some simple joins through the WHERE clause (equality of columns). You will also learn a bit about tuple and relational calculus, relational algebra, functional dependencies, and normalizations. The topics I wrote above is not covered in depth to be useful in the real world, but I guess it gives you quite a good overview of what to expect in higher level database modules.
I mentioned that the module is useful because you get to develop a simple web application as the term project. The project's default configuration is to use vanilla PHP, but the lecturers give us freedom to choose other web framework. Of course, we have to write the SQL queries by hand (instead of relying on ORM like what most web frameworks offer). I used Django (as a friend of mine in the group is highly proficient in it), overriding all ORM methods to write our own queries, but we use Django admin for managing the database (which is the most difficult part if you use the default project configuration, I believe). Luckily the grader did not say a word about it (or maybe he was not aware that we used it). Thanks to this project, I am not too clueless in my current internship, which is on web development.
CS2105 Introduction to Computer Networks
Lecturer: Zhou Lifeng
CS2102 Database Systems
Lecturer: Stephane Bressan and Zhao Jin
This module is not very interesting, but it is quite useful. You will learn how to CREATE, ALTER, DROP tables, SELECT, UPDATE, and DELETE entries, and some simple joins through the WHERE clause (equality of columns). You will also learn a bit about tuple and relational calculus, relational algebra, functional dependencies, and normalizations. The topics I wrote above is not covered in depth to be useful in the real world, but I guess it gives you quite a good overview of what to expect in higher level database modules.
I mentioned that the module is useful because you get to develop a simple web application as the term project. The project's default configuration is to use vanilla PHP, but the lecturers give us freedom to choose other web framework. Of course, we have to write the SQL queries by hand (instead of relying on ORM like what most web frameworks offer). I used Django (as a friend of mine in the group is highly proficient in it), overriding all ORM methods to write our own queries, but we use Django admin for managing the database (which is the most difficult part if you use the default project configuration, I believe). Luckily the grader did not say a word about it (or maybe he was not aware that we used it). Thanks to this project, I am not too clueless in my current internship, which is on web development.
CS2105 Introduction to Computer Networks
Lecturer: Zhou Lifeng
This module turned out to be very interesting (in my opinion, at least). We were taught the 5 layers of computer network protocol (Application, Transport, Network, Link, Physical, omitting Session and Presentation layers for some reason). There were 3 term assignments. The first one was to create a simple data transfer protocol on top of a reliable network. The second one was the most important one: to create a reliable data transfer protocol on top of an unreliable network. The last one was just to code out a simple encrypted network protocol using public key encryption.
I was really fascinated by how intricate and yet highly reliable the network protocols are, being built on top such unreliable channels. I am interested to take higher level modules in computer networks, but my friend (who knows better, supposedly) advised me not to. Have not decided whether to heed his advice or not.
CS2107 Introduction to Information Security
CS3241 Computer Graphics
Leturer: Alan Cheng Ho Lun
CS3211 Parallel and Concurrent Programming (dropped with W grade)
CS2107 Introduction to Information Security
Lecturer: Chang Ee Chien
This module is usually taught by Hugh Anderson, but for some reason another lecturer takes over for last semester. He is not very good at teaching, though I can tell that he knows his stuff. The midterm was super easy, as opposed to the finals which require you to understand the things taught in lecture, and think critically what was possibly being compromised, .
The "difficult" finals was to my relief, because I was so disappointed in the module for the whole semester as it felt so GEM-ish (general knowledge, not so into the CS aspect). To my pleasant surprise, the finals require me to apply what I know and give some creative answers (to some extent, because ultimately there will be a "correct" answer so that he can mark our paper objectively).
There will be an open-ended presentation at the second half of the semester. There will be topics provided, but you are free to propose your own. I took one of the given topic on TOR network. I'm glad I took it because I would not have learned about TOR if I did not. (I am lazy to learn new things if there is no benefit in the short run, unfortunately)
CS3241 Computer Graphics
Leturer: Alan Cheng Ho Lun
This module has been taught by him since forever, apparently. As the lecture notes, tutorials, and lab assignments are the same for the past few semesters. Regardless, this module is really good for various types of people: whether you are really interested into taking Visual Computing or Interactive Media focus area, just want to look around, or want to understand what those graphics settings in your games actually mean. I fall on the second and third category. The module goes for breadth instead of depth, which is why I said it is suitable for a wide range of people.
CS3243 Introduction to Artificial Intelligence
Lecturer: Low Kian Hsiang Bryan
Lecturer: Low Kian Hsiang Bryan
I hoped this module to be more interesting, but as it turned out, it was not really. It is highly algorithmic on the first half and very logic- and statistics-based on the second half. The first half we were taught many graph-search algorithms (which is how most problems are modeled for AIs to solve in the past, like the Enigma machine problem and most turn-based games like chess) eg Minimax, Constraint Satisfaction Problem, and A-Star search. Second half would be about logical agents, and last topic is on supervised learning. Despite the syllabus arranged in that way, the term project was on Machine Learning (creating an AI for tetris), so you need to learn supervised learning in advance (before it is covered proper in lecture) anyway, which I find quite stupid.
The midterms and finals are all about tracing the algorithms instead of solving problems. Although I would not like it on normal circumstances, the fact that I overloaded that semester (I took 25 MCs) means I did not need to study too hard for this module to get a decent grade (I hope, the grade has not been released yet).
LAC3202 Chinese 4
Lecturer: Doris Chen Poju (Chen Boru? I dunno...)
Nothing much to say. If you are going to take this module, most probably you have taken the other lower level Chinese modules. They are basically the same, except you need to write longer essays as compared to Chinese 3.
For the benefit of those who never take Chinese before (perhaps because you took the placement test and got Chinese 4 straight away), you are basically following the textbook (新实用汉语课本2, 第二十到二十六课). Learn vocabs (if you don't know it already), practice the conversations in the textbook, learn sentence patterns (or as they call it, grammar, though I feel that Chinese does not have a grammar the way English does). Exams are similar to workbook questions, except they are a bit harder. There will be 2 口语 at the end of the semester, one is in the form of presentation about Chinese culture, and the other is conversational 口语.
CS3211 Parallel and Concurrent Programming (dropped with W grade)
Lecturer: Hugh Anderson
I took this module with expectation to be taught how to write codes that can run on different threads properly. As it turned out, it was more theoretical than I hoped. Also, the burden of taking 29 MCs has gotten into me so I decided to drop this module in week 6. The lecturer himself is pretty good (I mean, this is Hugh, come on!), but it's just that the course is too theoretical to my liking. But I guess I should have practised myself instead. Considering taking it again next year (only offered in sem 2 =/)
So that's all. Sorry if it got shorter as it progresses as I got exhausted after a while writing it haha. Maybe I will edit it in the future if I have the time and willingness (unlikely, so don't count on it, unless there is a demand for it).
Hopefully the next post will be more useful for my portfolio, or at least for my own knowledge.
Monday, August 18, 2014
Idea 2: (NUS) Lost and Found!
This is an idea that I have just came up with yesterday. I was in the PC commons waiting for my friend to print some stuff, when I helped myself to a vacant PC there and found a(nother) thumb drive being left behind, still stuck into the machine. Any other day, I would have just ignored it as it actually commonly happens, but for some reason, on that day, I thought of an idea for a small Android app for lost and found!
The basic idea is that if we found something, we can take a picture of it and post it into the stream, where people who lost something can try their luck and find their lost stuff there. People can send a request to the founder to claim the stuff, and the founder should ask a question pertaining to the item to verify if the requester is really the owner of the item found.
I know this leaves so many loopholes (people can claim things that are not rightfully theirs) but what I need to do now is not a flawless app; just an idea of an app that I can work out. I do not know if this idea going to remain as what it is; an idea, but I have a plan. Now that I am already back in NUS, I just realized that I actually have the best platform to work on my ideas and getting help at the same time; Friday Hacks of NUS Hackers! We shall see if this project (as well as the previous one) can be done within this semester, with the help of Friday Hacks, or even a Hackathon, if my friends are up for it hahaha.
The basic idea is that if we found something, we can take a picture of it and post it into the stream, where people who lost something can try their luck and find their lost stuff there. People can send a request to the founder to claim the stuff, and the founder should ask a question pertaining to the item to verify if the requester is really the owner of the item found.
I know this leaves so many loopholes (people can claim things that are not rightfully theirs) but what I need to do now is not a flawless app; just an idea of an app that I can work out. I do not know if this idea going to remain as what it is; an idea, but I have a plan. Now that I am already back in NUS, I just realized that I actually have the best platform to work on my ideas and getting help at the same time; Friday Hacks of NUS Hackers! We shall see if this project (as well as the previous one) can be done within this semester, with the help of Friday Hacks, or even a Hackathon, if my friends are up for it hahaha.
Thursday, May 15, 2014
Idea 1: Transjakarta Route Planner
Sorry for spoiling the mood of readers that are expecting a lesson on programming (if there are any readers at all here), but this post is not going to be that. This will be just an idea that I just came up with, and I think I should take note of it somewhere that the future me will see in the future. So here goes.
As you may have known, I am an Indonesian, and I came from Jakarta. I usually go back to Jakarta every long holiday (those that last for a month or more) and do not spend my time travelling much. This summer, however, I decided to take up a challenge by interning in a university (Universitas Siswa Bangsa Internasional or USBI, if you are an Indonesian and want to know the name). It is really far from my house and my mother does not really allow me to find a place to stay somewhere nearby ("nge-kos", for the Indonesians out there). Of course, I can drive there, but the problem is, I've got no spare car to use as both my parents are using them everyday. (If you think I am rich or something just because my family owned 2 cars, it is actually quite common for the middle class in Indonesia to have 2 cars, but of course not luxury cars. For the record, my cars are a faithful Toyota "Kijang" (since ~2001!) and a Daihatsu Xenia (since ~2006). As you can see, both are not exactly expensive cars, and they are already quite old.) Thus, I need to find out a way to get there by public transport. Since it is impossible to find out the service route for most public transport in Jakarta (believe me, it is impossible), I tried to just use the best one, Transjakarta.
Transjakarta is basically like a normal bus, but with a better and more organized (though still extremely messy) service route. It is supposedly a solution the Jakarta government came up with to mitigate traffic congestion (though all it does is actually to worsen it). Nevertheless, I find that the website is not really informative (see it for yourself). The first thing I would need, of course, a feature that can tell me how to get to one stop to another. It is not available anywhere in the website, as far as I look. (If there actually is such a feature, please tell me!). Second, I want to check what stop is close to a certain place. Such an information is also not available! Even Google Maps let me down! (On their defense, Jakarta's public transport is indeed so chaotic that it is impossible to compile an accurate data to represent all the possible way to use public transport to get around Jakarta).
This idea of mine would be to solve the first problem. I wonder why hasn't it been implemented by anyone at all, since the idea behind it is quite simple. It is basically a graph's shortest path problem. Of course, I am oversimplifying things by ignoring distance between stops, travelling time, traffic, etc etc but hey, it's a start, right?
Initially, the program can assume that the distance to adjacent station is the same, so to calculate the shortest path, it will simply be the least number of hops (so we can use BFS). If successful, I will try to extend it to include a weight in the graph, which will be the travelling time/distance (I don't know which one would be better, any idea, readers?) Then if I've got the time (and knowledge), it can be merged with traffic information so that the accuracy of the travelling time will be better.
Just an idea. I think I can make the most basic version soon, but not sure about the most advanced one haha. Anyway, if you happen to be an Indonesian, and a programmer at that, and want to implement this too, feel free to do so! No obligation to credit me or something; I am sure I'm not the only one annoyed by this. =D
Edit: Found an app in the Play Store that has that functionality: finding a way to go to one stop to another for TransJakarta.Kommuta Komutta is the name. You can try finding it in the Play Store too. They decided to go for the pre-processed method, so any query by the user will be responded instantaneously, which I think is really good. I just thought their UI can be improved; such as by giving a map with pins on stops instead of a auto-complete text field, or perhaps even better, a combination of both.
Edit2: Komutta not Kommuta! Sorry!
Edit3: Here's the dev's webpage if you are interested to learn more about them. Apparently they are a mobile-based start up company in Indonesia. May want to work with them regarding the first project, but I think I am still too noob for them.
Edit: Found an app in the Play Store that has that functionality: finding a way to go to one stop to another for TransJakarta.
Edit2: Komutta not Kommuta! Sorry!
Edit3: Here's the dev's webpage if you are interested to learn more about them. Apparently they are a mobile-based start up company in Indonesia. May want to work with them regarding the first project, but I think I am still too noob for them.
Subscribe to:
Posts (Atom)

