Programming Projects

Rails-Devise-Warden Token Authentication + Android’s Volley

Hi, recently I’m trying to make an android app that uses a rails server. I used to code REST server before, but that is for javascript apps. Not android. And now that I’m trying to do so, I found a problem. Whenever the devise authenticate_user! failed and it throw 401 to the android app, Volley complain that some form of challenge key is missing. It work fine with a browser and it responded with an error in json form. This is the normal Devise behavior, which seems to also have support for api server. Because of the error in Volley, I can’t get the JSON that contain the error in order to show the message.

For the impatient one, the solution is this:

Devise::FailureApp #Autoload it

# Patch failure app so that the WWW-Authenticate message is sent regardless if using http_authenticatable.
class Devise::FailureApp < ActionController::Metal
alias :old_http_auth :http_auth
def http_auth
self.headers["WWW-Authenticate"] = %(Basic realm=#{Devise.http_authentication_realm.inspect})


Put this in an initializer. Another thing is that, make sure that Volley tells Rails that it is accepting a json response, through HTTP Headers or ‘.json’ postfix.

The reason for the Volley error is that, when an HTTP server respond with HTTP 401, it is expected to respond with “WWW-Authenticate” header. The spec indicate that it MUST respond so. The problem is, the browser treat this header as an indicator to show user an HTTP Basic Authentication form, which is not always what we want. We just want to respond with 401 to indicate that the user is unauthorized for that particular resource. We can’t really use 403 because that means, Forbidden, a different meaning. Showing a 200 with an error message/json just feels too hackish for an api server. Because of this, devise did not send the header if the model did not enable http basic authentication.

By default, Devise sent out a 401 when it detect that the request is not of a ‘navigation’ format. By default that is [*,:html], which as far as I understand, every format and html. Or in another word, everything. For those of you who have problem with setting up Devise for an api server, change this to [:html] and make sure your client application properly indicate its accepted format. Using this, which basically means nothing else but the patch above, my api server seems to be working for now with no error on Volley (aside from authentication error, but that is expected). If the user manually send a request there from a browser, it will redirect to a login page.

Also, if you intend to use token authentication, checkout the devise-token_authentication gem. Devise developers for some reason (which seems to be security) removed the token authentication strategy from devise. This gem is a fork of the token authentication strategy.


Opensuse 13.2

Problem with it.

  • When installing, the expert partitioner is not very friendly. It by default already have various suggesting setting in which I don’t know how to change them, like remove the extended partition and make it primary again. Tips: There is a reset button.
  • VLC says, it can’t decode h264. Its VLC and it actually can’t do that if you install from official repository.
  • The Yast2 package manager is not very intuitive.
  • It is not obvious that Opensuse 13.2 version of packman repository exist. (13.2 is still new right now and the documentation has not been updated).
  • It is not clear how to change installed version of library that is also in packman repository to the packman repository version. Hint: change the repository priority so that packman has a higher priority (lower number) then run zypper dist-upgrade.
  • nginx is actually not in the official repository.
  • By default it does not use the usual NetworkManager. Causes confusion. And for some reason, I need to restart the network.service in order for it to work after switching the network backend in Yast. Shouldn’t it do that for me?
  • When I’m installing something, it keeps giving warning about low disk space on an unrelated ntfs partition I used to store various things. I checked the “don’t warn me again checkbox”, but it still warn me.
  • I have to update the repository on every startup of software manager.
  • I have to update the repository every time I want to install something.
  • I have to upgrade any upgradable software every time I want to install something.
  • FGLRX is not working. It just boot to terminal login.
  • The open source radon driver has a tendency to hang at some point.

Plus side.

  • systemd starts really fast.
  • One click install is literally one click install.
  • The repository has priority. Neat.
  • Delta updates.
  • Kde and Gnome desktop is more complete than in ubuntu.
  • zypper is very nice. zipper accept both package name and rpm file. Much nicer than ubuntu/debian separate dpkg and apt-get.
Programming Projects Uncategorized

Introducing, String2Regex

Assalamualaikum everyone. In this post, I’ll show you a (relatively) new project which I’ve created in about a week or two. It seems to be useful for greater good and so I’ve released the code under the MIT license. The code is available here

String2regex is basically a clone of but run entirely on client side and not as full featured. The concept is, given a sample string, generate a regular expression to match that string based on user’s selection of string groups. If you don’t know what is regular expression, you are probably not a programmer and this is effectively useless for you. If you are a programmer but you do not know what is regular expression, then you are missing out. If you know what is a regular expression, check it our here and you’ll understand what does it do. Screnshot

One significance of this application for me is that it is the first (I think) client side application I made that have some kind of automated testing. It is also the my first client side application that is made ground up with some nifty javascript tools such as bower and grunt. Styler and IIUMSchedule both uses grunt for concatenation purpose but not originally. In another word, String2Re is currently the most… what is the word?… decent? proper? … yes, proper web application I’ve ever made right now. 

This is largely due to some automated testing build with it. The testing is not perfect, as it does not test it entirely and it does not test the view, just the controller logic. However the controller logic is quite complicated (not really) so having some test for that reassure me that it will not crash easily. 

Article Linux

What to complain about linux’s desktop environment.

Ubuntu’s Unity:

  • I don’t like the virtual desktop.
  • When you click an icon of an application that opened in another virtual desktop, it switches to the virtual desktop.
  • I want it to open in current virtual desktop. So I have to use middle mouse button.
  • The virtual desktop does not show much separation.
  • I can’t really change much.
  • It keeps taking something from Gnome, which in the end, prevent me from installing full gnome environment.


  • It just feels unpolished.
  • For some reason it starts slowly compared to other DE.


  • I’m not sure if it is really bloated or just feels bloated.
  • Gradients and transparency everywhere.
  • Excellent add-on downloader, but no decent opaque theme.
  • When you click to open something, you just feel than annoying 300ms delay.
  • Feels advanced, but unpolished. The margin and padding is weird. Its like a prototype. You think that I’ll be awesome, but it keep staying as a prototype.
  • Gtk applications sometime does not work very well. 


  • Lack of taskbar and ability to minimize.
  • Sure, it have some nifty drag and drop trick, but sometime we just want an application to hide from every virtual desktop.
  • I’m using two monitor. To switch application I have to drag my mouse to the top left of a screen. So if I’m on my right monitor, its a long way there.
  • For some reason it does not save the monitor offset vertical offset correctly.
  • Virtual desktop only work for the main monitor.
  • Right now I can’t enable any extension.
Article Programming Projects

Perbezaan antara Python, Ruby dan PHP.

Assalamualaikum semua, apa khabar, dalam post ini, saya akan mencabar diri saya untuk memperjelaskan perbezaan antara Python, Ruby dan PHP dalam kontext pengatucaraan laman sesawang. Cabaran sebenar saya dalam post ini sebenarnya adalah menggunakan bahasa melayu sebanyak yang mungkin. Sesuatu yang sukar dilakukan memandangkan ini adalah bidang perkomputeran yang mana kebanyakan dokumentasi adalah dalam bahasa Inggeris. 


Student Admin Dialogue

[tweetpost postid=5649050225344512]

Personal Projects

Thank you for using SemiAutomatic IIUM Schedule Maker

Assalamualaikum everyone. How are you guys? First of all I would like to say thank you very much for using my newest application SemiAutomatic IIUM Schedule Maker. I expect it to get significant traffic, but not this much. For the record, between 19 April 2014 to today 27 April 2014, the application got 9089 visit or 16928 pageviews, 80% of that is from schedulemaker, 10% from scheduleformatter. In comparison, from january 2012 (the start of the application) to 19 April 2014, it received 9335 visits or 19128 pageviews. Within one week, schedulemaker almost surpassed the amount of traffic generated by scheduleformatter for two whole years. 


It is THAT significant. In fact in the first hour after my friend share it, the server’s cpu peaked at 100% for almost half hour. The traffic steadily decreases after that. One interesting fact is that for every day on prereg, the traffic peaked at 11 PM. Assuming that IIUM Student start sorting their schedule at 11 PM is one thing, but actually having the data to say so is a totally different feel.

Frankly I never though that the tools I make because I’m too lazy sort my schedule or make a timetable would get this much traffic, let alone my website with the highest reception. I mean, the number of IIUM student is approximately 20000, google analytic say that there are 5240 users. Lets assume some of them also use their phone/tablet, so the actual number of user is about 4000. So one every five student in IIUM use this application. Someone actually use this. 

One again I would like to say thank you very much for using the application. This will look brilliantly in my CV. And thank you to all my friends who share the application. Like usual,  if I’m the one who share it, it does not work, but for some reason, if someone else share it, it get hundreds of like. It happened with schedule formatter , it happened with this one and it will happen again in the future. That’s it for now, good bye and Assalamualaikum. 


SemiAutomatic IIUM Schedule Maker!

Assalamualaikum everyone, how are you? So, lets get straight to the point. The purpose of this post is to publicly kinda-announce SemiAutomatic IIUM Schedule Maker. Given that it does not have an official readme page, I cannot confidently say that I’m releasing it to the wild. However, given that prereg is next week, and I don’t feel like making an official readme page any time soon, I’m announcing it now in this post. Also, this post will act like a readme page for now. 

So what is SemiAutomatic IIUM Schedule Maker? Basically it is a single web page application that helps you plan/sort your schedule for the next semester. Given that I miss several subject already, I think this should be very useful. How does it helps you? Well…. it:

  • Show your schedule in a day-to-day table like in Automatic IIUM Schedule Formatter in a preview.
  • When you hover the add/replace section button, it show your section as highlighted in the schedule preview.  
  • When a section collide with another section of another subject, it will show that this section collide with the other section. 
  • It has a generator function in which you select all the subject that you want to enroll, then it will list down all possible section combination. Then you just select one of them, and the changes is applied. 
  • It does NOT automatically register the subject. It is just an aid to help you sort your schedule. Don’t blame me if you did not prereg the subject.

How to use it. 

To use it, first go to which is the schedule maker. The first thing you see is that it ask for the session of the schedule and student type. Just enter the session for the schedule and the student type.



Click submit, and it will enter a loading page where it will fetch the subjects for that particular semester for that particular student type. Then you will see this page. 

SemiAutomatic IIUM Schedule Maker

The page is divided into two part. The left part is the preview of current schedule, with the added section as a table. Click on the big red button to remove the section from current schedule. There is two bottom button, the Schedule Generator and the Schedule Formatter which will be explained later. The right section will show all the subject available.



Keep in mind that the subject list does not necessarily reflect the current subject available in IIUM. The server will attempt to update the list every week. However it may fail to do so. Just now I tried to update it manually. However, it seems that IIUM server is currently under heavy load and does not response to a request. 


The right panel has a list of kuliyyah. Click on it to filter down the subject list to subject on that particular kulyyah unly. Click on the kuliyyah again to cancel the filter. It also have a search input on top which you can use to search for subject. Click on a particular subject to fetch and show list of section for that particular subject. The section list have an add button. Hover on it to show preview on where it is in the schedule. Click on it to add the section. If the section collide with another section, the add button will not show up. 

Schedule Generator


Click on the schedule generator to open the schedule generator page. On the left of the generator is also a subject list. However you cannot select a section over here. You only select subject. Several of them, which is which subject you want to pick. After you select the subject, it will generate all possible section combination of the subjects. In another word, several possible schedules with no section collision.


Beware, the application still need to fetch the section list from the server. So wait a few second for all combination to appear. The top button list down the selected subject and the number of section fetched in the black circle. Pick the schedule that you like using the ‘Use Schedule’ button, and it will go back to previous page.

Schedule Formatter


After you are done with picking section, you can save your schedule through Automatic IIUM Schedule Formatter. Click on the “Schedule Formatter” button to open another page. This page will ask you to input several more information that is needed by the formatter. Just fill it up or leave empty. Click “Save Data”, then it will show notice of saving the data, then another button will appear that say ‘Go to Automatic IIUM Schedule Formatter’. Click on it to open schedule formatter.


That is It

So that is it. It basically does that. I probably should mention about the list limitation I put for performance reason. But its not a big deal. By the way, the whole source code is now available at github. So you can now see the source code. Which means that now, if you have a problem with this thing, or if you want a new feature to be implemented you have two choice. First, the less recommended one, you can email me at, then wait indefinitely. Or a (much) better alternative, fork the code repository, do the modification yourself, then send a pull request. Anyway, that’s it for now. Good bye and Assalamualaikum. 

PS: You can now share your schedule using a link right above the schedule preview. Just share the link with your friend. The link change every time you add or remove section. 


Programming Interest Group Talk

[tweetpost postid=5668600916475904]


Past, Present and Future of IIUM.

This is an assignment for my leadership and management course last semester. 

Years ago, when I was stil in secondary school, the name UIA (Universiti Islam Antarabangsa), which is what IIUM is called back then, has a special feel of its own. As you would expect, ‘International Islamic University’ brings great impression on the university. Other university have the impression of having a lot of student or making beneficial research or becoming the best of what Malaysia has to offer. IIUM on the other hand, would hold the hope of Muslim everywhere around the world. After all, at that time, IIUM was one of a kind with a very general name of IIU. We would all expect every IIUM student to be able to speak Arabic and teaches religion. I myself once said that I’ll never enter UIA because I have to learn Arabic. Being a student from a normal secondary school, not even a religious school, IIUM is not the first university to come up to my mind. I would even joke about entering IIUM. And yet here I am, preparing an assignment for my leadership class.

Before I came here in main campus Gombak, I went the usual Malaysian student route to a degree, matriculation or foundation. IIUM has its own foundation located in Petaling Jaya. It was in fact, the old IIUM main campus, which itself was the old Islamic Faculty of University Malaya. On the online public university registration system, I pick UIAM as one of the university. I pick it as first choice randomly, not knowing what I’ll find. Eventually the result of my application is a foundation program in IIUM. I also get an offer from Selangor Matriculation Center, but by the usual convention of picking foundation over matriculation, I opt for the former. My first impression was mixed. Most of the students are not as religious as I thought. They came from schools all over Malaysia. Most of them came from boarding school and some came from famous schools like KISAS or Victoria Institution or MARA full boarding school. Only some student came from normal school like me. Some even schooled outside Malaysia, in Egypt for example. Bare in mind, this is foundation center, almost all student are Malaysian. All student does look similar and usually does not show much different. It does have its own uniqueness. Out of the usual appearances of the student, it is not very rare to find a Hafiz. One of my roommate is a Hafiz. Who knows if the person next to you is a Hafiz? And if he is, it is nothing unusual, unlike back at my old school. Another strange thing I notice is that, most of the student are not exactly performing student. Sure, I have a friend who is the head prefect of Victoria Institution which by my secondary school standard, that is very impressive. I know one of my roommate is an Assistant Head Prefect. Who knows what others are hiding? But academically, I have to admit, I expected more. I was among the top student at my school, but it is a normal secondary school. Which cause me to think, ‘Why do they left normal secondary school to a boarding school if your academic will end up normal just like this?’. Back at my school people keep saying its not easy to enter IIUM, you will need really good grade. In reality however, that is not really the case. Most of the student here are just above average, if you compare to most secondary school student, but not really creme de la crop. I keep asking , ‘what am I doing here?’ being not so religious , on a religious university where most of the student is not as religious as I thought, academically excel except on religious subject in a university where I thought everyone would be some kind of a genius. I could probably have more competition and yet perform better on University Malaya for example, where I don’t have to take religious subject. Eventually I start to think, ‘lets just get through with this’. Think of IIUM, like UITM with less people and more religious subject.

One and a half year later, I enroll at IIUM Main Campus Gombak. I was an ICT student so there is no such thing as ‘will you get the course?’ issue because requirement for Bachelor of Information Technology is quite low. Effectively all foundation ICT student manage to enroll in BIT. Some foundation engineering student however, will have to take BIT because of their low grade. Gombak Campus has an entirely different environment. Student are able to get in and out of campus freely unlike in CFS. The area of the campus is huge compared CFS campus, yet smaller that most university in Malaysia. It takes me half hour to walk from my mahallah to Kuliah of ICT. Gombak Campus is quite compact. There is not much space for more development. The climate is cold and it location is close to the jungle. The place is beautiful. Some mahallah even look like a resort. It can be characterized by one large circle of one way road surrounding a central complex of buildings where most kuliah is located. I said most because kuliah of ICT is not in the circle. In the middle of the complex is a mosque. The architecture is also a bit different then other university. It feels… less like a public university, and more of… a garden actually.

One really big different between CFS and main campus is the international student. Almost 30% of the student are international student. I personally thought the percentage would be more than that. Later on, I learn from another student that there were more international student back when the university was founded. But it has decreased. I guess Malaysia is a good country for foreign student because we already have many foreign worker so its not really a strange situation to see other nationalities. Except for African student. The dark skinned one, even darker than indian. These are very rare in Malaysia, but not in IIUM. Unfortunately international and local student does not mingle much with each other. Much like Chinese and Malay in Malaysia. A bit separated but not particularly hostile with each other. I’m not exactly sure why. I’m guessing its a Malay thing. Another thing I realize is that students can’t speak Arabic. Which is not really what I expect in the first place. It seems that IIUM used to have an Arabic requirement of level 4. But now it has been reduced to level 2. It seems that Arabic is not particularly considered important, which is a shame, considering this is an Islamic university. For example, I am currently writing in english. I guess the administration think It is best to use a language most student are able to comprehend. No, the situation is also the same among international student. Most of them can’t speak Arabic too (or can they?), although the percentage are probably higher than local student. Fortunately the friday sermon is usually conducted in Arabic and English. And this Arabic is not the scripted one we usually found in normal Malaysian mosque. The khatib really speak and speak in Arabic. If you want to know how is a friday sermon conducted in real arabic, come to IIIUM. The university also has some required courses which is tailored towards Islamization. For example, tilawah Al-Quran and Islamic World view. But these subject is not really hard or have high credit. But it is still more than what you find in other university.

Another thing I realize is the solidarity of the student. IIUM has always been known to be a politically resisting university. What I do not know is how much exactly, and what kind of things happen. Before I went to Gombak main campus, I knew one event from my friend. My friend went to Gombak campus because he was one of the committee for a sport carnival. He said, ‘heavy traffic jam. The student are holding a demonstration.’ . I’m not sure exactly why, but if I’m not mistaken, it is due to some fault in the student representative counsel election. So last year, the election actually happen twice. Once with electronic machine, and the second one with manual paper vote. So that is interesting. The newspaper however, published only 20 student in the demonstration. But based on what my friend told me, I’m very sure there were more than 20 student. The central government has a tendency to involve in administration of IIUM especially when the 13th General Election is hold early this year. One interesting fact, both the opposition leader, Anwar Ibrahim and government leader, Najib Razak, were president of IIUM. So we can say that GE 13 is the battle of two IIUM President. Some notable figures which is not directly in politic, but has been known to be on the opposite side of the government, like Ustaz Ahmad Idris is basically banned to from entering IIUM. Even the previous deputy rector of student affair who is known to be biased against the government cannot enter IIUM. Several talks were canceled after being approved, for example ‘GE13, What is Our Hope’ which was originally intended to be held in IIUM, but later on the venue had been changed to public hall outside IIIUM. And recently with this year SRC election, the deputy rector of student affair made a very suspicious method of election for the SRC president which resulting in a widespread bitterness throughout the university. So this university is not really independent and not really of a say…. university. In conclusion, the International Islamic University Malaysia is less than 30% international, not as Islamic as I thought and is not as a university as a university should be. But it is in Malaysia.

The topic for this assignment is past, present and future of IIUM. I’ve briefly talk about the past, and the about present. So now I’ll have to talk about the future of IIUM. In my first semester, I’ve attended a talk entitled ‘talk with admin’. There, the administration has presented several plans they made. For example, the new CFS center, a solar farm near KICT, a multilevel car park, a centralized cooling system, a cultural village near the lake and an automotive museum. Sounds awesome? It is, but is the plan just for presentations? With various government budget cut after GE 13, and the failure of IIUM to reach a status of research university this year, I’m feeling skeptic. What I can say is about the solar farm. Which If I’m not mistaken, the budget for the first phase has been passed. And If you go to KICT, you will see that behind the new expensive mahallah, there is an empty land, where the solar panel suppose to be. But it should already be there by 2013, and now its December 2013. What about the solar panel at the car park in ECONS? Again, I’m very skeptic. The new CFS Center in Gambang on the other hand, had recently been partially open. It should be fully operational by 2015, but it seems that it is ahead of schedule. The rest of the plans seems to be hopes and dreams, looking at the current geographical limitation and the situation of the lake which is more of a field right now.

Recently, again if I’m not mistaken, the rector said that we will be gradually increase the number of international student up to the limit allowed by the government. Which is 30%. Which means that the number of international student is actually less than that. I personally would recommend they set the quota to at least 50%. Not to mention IIUM is technically a company instead of a public university. So we should not be entitled for that quota too. However, I was hoping for more changes in the environment. I wish there were more program to empower the student to be more open minded and not being restricted thinking ‘will the admin approve it?’. Also, I hope that one day when I graduated, I can speak Arabic. Sure, its not what I’m good at, but how can I say I graduated from an International and Islamic university if I can’t even speak Arabic? I hope the administration will reconsider the minimum Arabic requirement. It might even also solve the integration problem between the local student and international student. Overall with the trend from what I know previously, the future of IIUM seems to be more restrictively international, less Islamic and more performance. However budget cuts could mean some plans will have to be cancelled. The future does not holds very good for IIUM. Especially considering that IIUM can be considered as a ‘fortress’ for political student. The future fate of IIUM may be similar to the Insaniah University in Kedah.