A place for my personal musings, about programming, design or whatever come across my mind

Another way for factorial, extending the integer class, so the function will feel more natural, instead of fact 6 for example, you just call it by 6.fact. Also, added a function to sum up the factorial value, counting down. Example, for 6!, it will be 6! + 5! + 4! + 3! + 2! + […]

Hours ago I got a programming test question about factorial, which I didn’t do really well, only completed with the help of the interviewer. Damn. The worst thing is that I have done this question before, and I know in the head I can use recursion for it, but I totally go blank on how […]

And so not to forget this again. This is how to clear the console screen in rails, type this, In Ubuntu, system ‘clear’system ‘clear’ In Windows system ‘cls’system ‘cls’ from stackoverflow

Am running through “Learn to Program” from Chris Pine, again. I have been cracking my head on the exercise to write a sort method instead of just using the array#sort come with ruby. As the exercise actually came at the stage of the tutorial that more advanced techniques like ternary operator is yet to be […]

a = [9,5,6,3,7] a.sort { |x,y| x==5? 1:x<=>y } [3, 6, 7, 9, 5]a = [9,5,6,3,7] a.sort { |x,y| x==5? 1:x<=>y } [3, 6, 7, 9, 5] So, I sort the array consisting 9,5,6,3,7, run it through a block, put the elements to x and y then sort it in ascending order, except for the […]

And so I always understand it wrongly, 1 2 s = "hello" s[0,2] = "He"s = "hello" s[0,2] = "He" That I thought the second operand is the ending index, and that somehow it works like range, where 1 2 a = [1,2,3] a[0…2] = [1,2]a = [1,2,3] a[0…2] = [1,2] So, the last index […]

So glad when I come across rvm, but then I learned that it is only for Linux and OSX. I do work in Ubuntu sometimes, but other time I have to work in a Windows environment. Then, I discover pik, hey, doing the same thing for you, but in Windows. So now even in XP, […]

With all the branching, go back and forth between future and the past, shouldn’t someone already start using Terminator as an tutorial for learning Git? from terminator.wikia.com

So I have a whole list of data which is already in excel and need to put into the Rails application. I could either manually type them into the database, or there must be some plugin out there dealing with this. Just a quick google bring me to Unixmonkey blog talking about fastercsv. All you […]

The explanation from api.rubyonrails.org is rather baffling for a newbie like me, collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) Still managed to get the dropdown menu working for my application after searching through the web. There are already quite a few […]