As I came across the exception handling chapter, both code below should work as stated in the book (The Head First Python book, which is indented for Python 3.X, but I am running this code in Python 2.X), try: with open("man_data.txt") as man_file: print >>man_file, man with open("other_data") as other_file: print >>other_file, othertry: with open("man_data.txt") […]
Going thru the Head First Python book, which is intended for Python 3.X, although majority of the content work just as well in Python 2.X. First encountered with some variations between version 3.X and 2.X at the chapter about printing out nested lists, with tab indicating different nested level. To print a tab without a […]
I am developing a little application within instantrails, suppose to work in an intranet environment. The application let user book a part number, by filling some information. For better user experience, I plan to capture the username at the other end that make the booking, instead of creating another layer of login feature and require […]
Read about thin for a while (faster than webrick, faster than mongrel), but didn’t really get the chance to try it out, until recently. As I am looking for moving my little rails application out of instantrails to a proper production environment, decided to give thin a spin, too bad Passenger isn’t supporting Windows platform, […]
Understanding sorting algorithm by just reading text or still illustration takes a lot of mind gymnastic. Apparently, there are lot of videos online, trying to explain the concept. But not all explain it as good though, some with really boring animation, some with crappy background music, and some even both . Here are two that […]
It is a bit difficult for me to understand the difference between map and each, until I found out this in irb accidentally, irb(main):001:0> name = %w{guido knuth adrian dhh pg} => ["guido", "knuth", "adrian", "dhh", "pg"] irb(main):002:0> name.each {|n| n.upcase} => ["guido", "knuth", "adrian", "dhh", "pg"] irb(main):003:0> name.map {|n| n.upcase} => ["GUIDO", "KNUTH", "ADRIAN", […]
Okay, much better only in a relative term, comparing to my earlier sorting which didn’t take care of duplicate elements. Two major changes here. 1. I do away with the temporary variable for holding on the smallest number result from each round of the comparison, instead elements are now passed over directly to the sorted […]
Finally have the time to come back to the sorting exercise, here is a slightly better version of sort. It still doesn’t take care of duplicate elements, but compare to the first sorting version, this one is shorter, as the whole finding smallest element left in the array is now done by inject and a […]
Apparently you can have optional parameter listed in the middle for your method in Ruby version 1.9 C:\>pik switch 191 C:\>irb irb(main):001:0> def talk(a,*b,c) irb(main):002:1> p a,b,c irb(main):003:1> end => nil irb(main):004:0> talk ‘a’,’b’,’c’ "a" ["b"] "c" => ["a", ["b"], "c"]C:\>pik switch 191 C:\>irb irb(main):001:0> def talk(a,*b,c) irb(main):002:1> p a,b,c irb(main):003:1> end => nil […]
A beautiful visualization of sorting algorithm… via Hacker News