From the left flank

Keep Going

leave a comment »

I showed Dan my palindrome program over the weekend and she said that I had to put in a loop for it to look more useful.

“Do you know how to do that?,” she asked. Ughh…in Java yes. As I have found out, it’s simpler in Python:

keep_going = 'y'
while keep_going == 'y':
      #code here

Here’s my new palindrome program

def palindrome():
    word = input("word?")
    word_first_half = list(word[:len(word)/2])
    word_second_half = list(word[len(word)/2+1:]) if len(word)%2==1 else list(word[len(word)/2:])
    word_second_half.reverse()
    output = "palindrome" if word_first_half==word_second_half else "not a palindrome"
    return output

keep_going = 'y'

while keep_going == 'y':
      print palindrome()
      keep_going = raw_input('keep going?')

Written by Jose Asuncion

February 7, 2010 at 7:26 am

Posted in Python

Tagged with

Back

leave a comment »

Over the past eight plus months I have been working extra hard at my special problem. Putting my mind to an endeavor is something I really missed. I have been galvanting aimlessly ever since I came to Diliman. I wanted my last year in college to matter.

But I was really rusty at it. I wanted the best for the project. I spent a lot of days coding till 5 in the morning. In the afternoon I would read up on the technologies we were using. Then I would go home and start coding again. It was a vicious cycle. Oh and did say I would sneak studying my other subjects in between?

I paid…my dad paid a steep price for it. Literally. And for that I can’t help but feel bad.

Last Wednesday I was discharged from the hospital after a bout with excessive stress. Well technically I contracted an infection. But my body was too tired and though I really hate the idea of lying around doing nothing, I just had to give my body a break.

What followed was six days of catching up on sleep and a peace of mind I hadn’t had in a long time. Lately I’ve been telling my friends that I just came from an early “vacation”. My room was like a hotel.It had wooden floors, a private bath, a couch, a tv, an extremely hard working air conditioner and a nice view of the sprawling greens of Wack Wack Golf Club. I had five meals a day — breakfast, merienda1, lunch, merienda2, dinner. What I liked most about the food was the presentation. I have to say it has been the closest so far I have been to a five star meal. Everyday the staff would do a room service while I watched the Simpsons.

I thought my condition was rare. Everyday a doctor would come in to check me, followed by five other doctors! While the former would ask how I was, the other five would take notes and nod their heads. Then another doctor would come with his class and another and another. I wonder how much they charged for those visits. They should have given me a discount because I was a rare case.

Some of my friends from school lab paid me a visit every night. It was amazing. I treated them to pizza one time. I’d like to thank Dan for organizing them to come.

I always looked forward to when nurse Tin or nurse Jamie would come to check on me or bring me my meds. They were both pretty and we would have amicable chats everytime. I should have given them a cake when I left but I couldn’t because seeing the medical bill held me back.

Today, Saturday, is the first day I did nothing productive this school year. I watched Glee and caught up with some friends. I also slept…twice.

Well a day from now, I’ll be going to back to work but with renewed priorities and fine tuned expectations from myself. I still want to make my last year in college matter but this time I’ll have to take care of myself along the way.

Written by Jose Asuncion

January 30, 2010 at 6:07 pm

Posted in Jeune

My First Python Machine Exercise

with one comment

Recently I have found out about a faster way to learn Python where before I was nosebleeding at Dive Into Python or dragging myself with Starting out with Python.

Now I am into Strings and I am loving the pace at which I am learning. In the middle of it all, I fancied doing an exercise to apply what I’ve learned. Without looking very far, I remembered the C exercise we had in first year about palindromes.

I remember having many lines of code for C. But not with Python:

def palindrome():
    word = input("word?")
    word_first_half = list(word[:len(word)/2])
    word_second_half = list(word[len(word)/2+1:]) if len(word)%2==1
        else list(word[len(word)/2:])
    word_second_half.reverse()
    output = "palindrome" if word_first_half==word_second_half else "not a palindrome"
    return output

Written by Jose Asuncion

January 17, 2010 at 3:34 pm

Posted in Python

Tagged with

Using Factories for Unit Testing

with 4 comments

I got tired of populating my database with domain objects when I am unit testing my DAOs so I decided to use a static factory method that returns an instance of a domain object. Now, I just need to call the factory every time I need a new object.

Before I used to do this:

	public void setUp() throws Exception {
		super.setUp();
		...
		course1 = new Course();
		course1.setOwner("Jose");
		course1.setLearningObjective("to learn football");
		course1.setTitle("Football");
		course1.setTags("Football Soccer");
		dao.insert(course1);
                course2 = new Course();
		course2.setOwner("Mayee");
		course2.setLearningObjective("to learn football");
		course2.setTitle("Football");
		course2.setTags("Football Soccer");
                dao.insert(course2);
		...
	}

Now I just used do this

Course course = CourseFactory.getCourse();

This gave me the chance to finally put interfaces in my daos. With this improvement, I was able to disinfect some code smells. For one instead of injecting a dao to unit test a controller that gets info from the database, I just implement a dummy dao and get an auto generated domain object.

Course course = CourseFactory.getCourse();
	public LearnModuleControllerTestCase() {
		courseDao = new CourseDao(){
			public Course getCourseById(Long ID) {
				return course;
			}

			public List<Course> getCourseByTag(String tag) {
				return null;
			}

			public List<Course> getUserCourses(String nickName) {
				return null;
			}

			public void insert(Object object) {

			}

		};
	}

Written by Jose Asuncion

December 4, 2009 at 9:32 am