The following are the blog posts under the category Programming
May
29
2010

Summer of Code

Summer isn’t over yet but I’m afraid that this summer season will be my first summer without experiencing saltwater.

I spent most of my summer taking summer classes (Physics 72 and PE 2 Weight Training). Aside from that, I spent a some chunk of my time in DilNet Help Desk answering phone techs, fixing networking problems on-site and fooling around with my co-applicants and student assistants. I also attended some interest-related events such as the UnPLUG Precinct Mapping Party and Ubuntu 10.04 Release Party.

The final leg of my summer, for me, was the most exciting. I accidentally got involved in a project while eating with my DilNet friends at a food stall near the Main Library. We had to develop an application to be used by a unit in UP.

Developing the app was exciting. Although I had previous experience with CodeIgniter (a PHP web-app framework that uses the MVC architectural pattern), it was my first time to use it for an actual project. It was my first time to use jQuery since the project required some realtime checking of constraints.

I also experienced roadblocks in making my part of the project. Three days before the deadline everything I coded for around a week got lost. After doing some research, I can attribute the loss of my folder to the way ext4 writes a file. I also found some solutions on how to recover my folder but I decided to do it again from scratch since recovering it will entail more work than actually rewriting the code. Here’s a more detailed explanation on what might have happened to me.

To catch up, I had to do some sort of coding marathon. I was awake for some 57 hours minus some short naps. During that time, I learned a lot from my co-developer.

It was a very fun experience and I am looking forward to working on more projects in the future.

And up to now, I am still looking forward for a beach outing. XD

Posted in Programming


Jan
18
2010

Searchable UPCAT 2010 Results, Student Number Database, etc

UPCAT 2010 Results (University of the Philippines College Admission Test) were released earlier today, January 18, 2010 both online and offline.

The new official results page is now non-searchable, I wonder why. But that’s not a problem because I made a searchable version of the one’s in the UP website.

I also made a super lightweight web app that checks if your 2010 counterpart passed UPCAT or not. In my case, 201041437 either didn’t pass, still has deficiences or a pending case. His or her name was not on the list. :(

Aside from this, I also made another one last night which is not related to UPCAT. It’s a searchable database of UP student numbers. I got those student numbers from various sources from the Internet, including past UPCAT results. Hahaha.

I really missed scripting. :( All those stuff above are hosted on my laptop therefore they’ll be down whenever my laptop is sleeping. LOL.

Tags: ,  
Posted in Programming, Random


Oct
24
2009

The 2009 ACM-ICPC Asia Regionals Experience

ACM ICPC

Several hours ago was the 2009 ACM-ICPC Asia Regionals Manila Site hosted by the Ateneo de Manila University. ACM-ICPC is a programming contests in which college students are to solve a certain number of problems in a limited number of time, in yesterday’s contest ten problems in five hours.

UP Diliman had ten teams in total, seven SOGO teams from the University of the Philippines Programming Guild and three teams from the UPD Department of Computer Science. I was a member of one of the SOGO teams, the SOGO Virgins.

Results, results and results!!

ACM-ICPC

Our team only ranked 26th out of the 55 teams, which was quite disappointing. Among the 10 problems given, we only had three accepted solutions out of the five problems we attempted.

The champion was from our guild (UPPG), the Mga SOGO ni E.T.. They solved all 10 problems in 1 hour and 59 minutes. They will be competing for the World Finals this February 1 to 6, 2009 at Harbin University in China. Other teams who solved all 10 problems sorted by time were teams from Ho Chi Minh City University of Science, National University of Singapore, Hong Kong University of Science and Technology and another team from UP Programming Guild, SOGOng Long Ong Moy Poso. The freshie team (2 Young 2 SOGO) from our guild beat us as they solved 5 problems in all. Woot! :) For more detailed results, you may check out the contest director’s blog.

Problems encountered!

Experience is the best teacher. We encountered problems on some problems. :)

Problem A. Given three points on a parabola, get the maximum height of the parabola. Since we don’t have a mathematician in the team, we had a hard time finding an equation with degree one for all variables. We had to force one of our teammate (out of 3) to squeeze all his knowledge on parabolas. When he found one, I immediately coded Gaussian Elimination Method for two variables and two equations. Gladly, our solution was correct thus accepted by the judges.

On the summation problem, we got correct answers for the sample inputs but it was too slow that testing it on borderline cases (worst case scenarios) won’t yield a result in a reasonable amount of time. Since no one in our team was a mathematician, we had trouble limiting our search space. :( Our program was so inefficient but right that we were not able to have our solution accepted.

The other problem we attempted was the A(H1N1) problem. Given a set of N people in a community with their locations and radius of contact and a person infected by A(H1N1), we had to compute the number of levels of transmission until the virus is contained. We recognized that it was a graph problem; people as nodes then connect an edge to nodes within the radius of contact of an infected person. We just have to perform a BFS (Breadth-First Search) on the graph and find the  level distance from the root to find the maximum level of transmission.

The algorithm above was correct but I made a mistake in coding BFS. I colored the node after dequeuing it from the queue instead of coloring it while putting it on the queue as seen in my code below.

Breadth-First Search

Damn. I admit that it was my fault, not anyone else’s. Hmmmmf. :( Waaaaaa. What a shame. On the other side, it still yielded the correct answer for the sample input.

Lessons Learned

  • Never spend too much time on a single problem. We spent too much time debugging the A(H1N1) problem.
  • A team needs a mathematician. There were quite a number of Math problems. We were only able to solve one out of all the Math problems.

Random Stuff

Even though we did not rank well, I was still happy of the outcome. Because of this contest, I will never forget BFS anymore! Hahahaha.

I am looking forward to joining the same contest for the next years if fate will permit. :D

Tags:  
Posted in Programming


Mar
04
2009

Calling all geeks out there!

I admit that I am bitter with the results of the Mensa IQ Challenge I took sometime last month. It was a BIG slap on my face, after self-proclaiming myself as a geek. I don’t believe you have to pass Mensa to be a full-pledged full-fledged (as corrected by Aldrin, point well taken) geek. Hahaha. Here’s something geekier than Mensa.

After two sessions of training on our new “programming guild”, I’ve encountered tons of intellectually challenging programming problems. The spectrum of problems were very wide; from counting descendants of a person in a family tree, to beating a greedy opponent on a game, to getting the height of a rocket model using three ground observers using a theodolite, and the list goes on and on.

I admit those problems were new to me and I think it was the best answer for my hunger for knowledge. Those problems squeezed my neurons to the highest level, thus greasing up my brain. Those were the problems that made me realize I still have a lot lot lot more to learn. I mean, A LOT!

ACM-ICPC logo

To all other geeks out there who have a background on any programming language (preferably C or Java), I dare you to solve the problems on real ACM International Collegiate Programming Competition (ACM-ICPC). There are a lot of problems available there from ACM-ICPC contests around the globe.

So far, I have only solved four ACM-ICPC problems. My goal is to solve at least one per night. Good luck to me and have fun with those problems.

Tags:  
Posted in Programming


Feb
28
2009

I’m part of the world’s Top 3% + New Knowledge

Last Sunday, I took the Mensa IQ Challenge at Fully Booked in Bonifacio High Street, Taguig City. The first 30 items of the exam were super easy that missing out a point for a problem was a big deal. The next items (I won’t say how many) were moderate. The only enemy I had was the SUPER limited time.

The only criterion for membership in Mensa, is to score within the top 2 percent (98th percentile and up) on an accepted and properly supervised qualifying test. -Mensa Philippines website

Earlier today, the unofficial result of the 2.22 exam was released via web. Mensa posted the good and bad news. To maintain a level of privacy, they posted the codenames we picked from a fishbowl before the exam. My lucky word was MAGELLAN. Waaaaaaaa.

After checking the super cool good and bad news, I found out that I belong to the world’s top 3% IQ-wise. Hahahaha. Yes, I am a genius.

Yes I am a genius.

I am a genius.

Yeah, right!

Security Holes

Anyway, proceeding to the next item I’ll be sharing. I’ve recently shared to you that I have a hunger for knowledge and today, I was fortunate enough to learn something new. I love learning new things! It was a file transfer thru SSH crash course. :D

My orgmates asked me to generate reports of the recently concluded Computerized University Elections here in UP Diliman. All they gave me were the login credentials of the server where the database was stored and the I.P. address.

The account they gave me did not have any write access to the www folder so uploading the script thru FTP and dumping the results thru HTTP was not an option. I asked for more options and one of them suggested that I use SSH. What the heck?! I’ve never used SSH for uploading and downloading files, seriously. I never thought it was possible.

Since the only thing I knew was to login to the server thru SSH, I had to ask for help. Gladly, kuya Prem extended his help despite his busy schedule. I was also able to apply my newly acquired (last year) Linux shell skills like dumping something to a file. It was so much fun.

Yey, I am a genius. Yes I am a genius! I AM A GENIUS!! Mikko is a GENIUS!

Tags: , ,  


Feb
18
2009

In need of expanding my knowledge

Geek
(from XKCD)

Offtopic: In line with the comics above, I always find my self in the same situation. I love to do this with plate numbers. :D

These past few months were the most dormant periods of my geekiness. I badly need to expand my knowledge.

I have hunger for knowledge. Some people may find it weird but it’s actually true. It’s fun to have passion for learning stuff you’re interested to. Don’t think of me as a college nerd reading all those Bio, Chem and Physics books. I’m not interested on those stuff  except those rare moments when I felt geek enough to make simulation of scientific concepts (so far, I’ve made a simulation for freefall and projectile, road traffic and matrix multiplication).

The latest bit of geekiness I got was from my Computer Science class. It’s only this semester when I got a pretty good picture of real Object Oriented Programming. I knew about it before but I only had the chance to get a clearer picture of it on our class.

Currently, I’m interested on studying Python, Ruby on Rails and JSP. I’m tired of PHP, seriously. I’ve been obsessed with the language since I learned it three or four years ago. I’m also interested on making an application using any API. I’m thinking of making a web application that has something to do with geographical information (so that I can use Google Maps) like generating a map, like a Map of Misfortune [I'll discuss this later].

The BIG problem now is where to start. Do I start with Ruby on Rails or what? That I still do not know. I need help.

To the other geeks, feeling geeks (like me), aspiring geeks, retired geeks and non-geeks out there, I need your suggestions. It could be a programming language or an API to explore. Please respond thru the comments section. I am THIS pathetic to expand my knowledge. Waaaaaaaaaaaaa.

Tags:  


Dec
23
2008

A Geek Day with PHP, Magpie RSS, Cron, mail function and Everything Niice

DISCLAIMER: For those who are not interested in PHP, you better not bore yourself with this post.

It was ages ago since I made posted some really geek stuff. I think I had to live up with my blog title, Build that Geek — and so I had to rebuild the geek inside me.

bot

Overview

An hour ago, a brilliant idea was distracting my sleepy brain (it was around 4am). The idea was shining so much that my eyes were blinded by it (my pair of eye was facing the inside of my head). At first, I was hesitant to do it by I eventually gave in.

The idea was to create a PHP program that would notify me thru SMS and email every time a PRC Board Exam result is released. The program would ran every five minutes by means of creating a cron job that would execute it.

The program flow are as follows:

  • START
  • The program, thru the PHP server would contact an external source requesting information.
  • The external source would feed the requested information back to the PHP server.
  • The program would parse the data in a PHP-readable format.
  • The parsed data will be filtered (non-PRC related stuff would be dropped).
  • CONDITIONAL: Was the parsed data previously been sent:
    • if yes: END.
    • if no, continue.
  • The program will notify me regarding the PRC Board Exam result release thru SMS [thru an SMS Gateway] and email [thru PHP's mail function]
  • END

The Search for Source of Information

gmanewstvlogo

I strolled around the Internet. The most reliable source I could have is the PRC Official Website. I visited the website and tried to search for an RSS or a well-organized XML file. Too bad there weren’t any. I thought of extacting information from the website the dirty way (using eregi, str_replace, and other string manipulation functions) but it was too much for my tired brain.

The next one was Philippine Daily Inquirer’s inquirer.net. I immediately searsuched their site and poof, there’s this XML feed. I thought it was all fine but when I checked it, it was pretty outdated. If I’d use it, the program would defeat the purpose of informing me really fast of the latest news.

Next was ABS-CBN News. In their Public Service area, they served PRC Board Exam result news. They supplied an RSS feed, but sadly it was blank. It contained no information.

The last one who successfully won me was GMANews.tv. I checked their site and they were also serving PRC Board Exam result news. I learned that they publish it on-the-go on their Nation section. Their top stories section had a usable RSS feed, woot. Finally, I’ve got it.

Data Parsing and Extraction

The next thing to do was to extract the data. How could I parse the RSS feed in such a way PHP would understand it well. Since Google is my friend, I tried googling my problem. Google (search engine) introduced to me Magpie RSS, the program I was looking. Just feed an RSS feed to Magpie RSS and it would break the individual feed items into arrays.

Implementation of Magpie RSS to the program was easy since they have posted a simple how-to on their website.

Filtering the Data

0002_thebigloser_billjunk

Since it was a Nation section feed, not all items on the feed were regarding PRC. There was a need to filter it out. The easiest way that came into my mind was to match either one of the following string “prc” or “professional” to the feed descriptions. If the feed description contained the said strings in a non-case-sensitive way, then retain the information; else drop them. What I used in this part was the eregi function.

Notification and all sorts of stuff

The next thing to worry about was on how to notify me. I also realized that previously sent news did not need to be sent from time to time. For this, I made a MySQL database that would save previously sent information. If the information about to be sent is not on the database, then send it; otherwise, don’t.

The email notification was easy. Gladly, PHP has this easy-to-use mail function. For the SMS notification, I used a free SMS gateway.

Keep it running, indefinitely

Since the program needs to run from time to time, I made a cron entry that would command the server to run it from time-to-time.

Conclusion

The idea was possible. Barely 30 minutes were spent doing it. Source code may be requested by contacting me thru my contact page (accessible in the header and footer).

Tags: ,  
Posted in Programming


May
26
2008

Google Treasure Hunt 2008 Robot Maze

All images and questions from Google Treasure Hunt 2008.

Question:

A robot is located at the top-left corner of a 58 x 64 grid (marked).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’).

How many possible unique paths are there?

The image is not drawn to scale. For illustration purposes only.

Solution

Since I love PHP, I will be attempting the solve the problem in PHP.

Here’s how I am gonna do it.

Since it is a 58×64 grid, to reach the 1,1 location the robot needs to go down 57 times and go to the right 63 times yielding a total of exactly 120 steps to reach its location.

So the rule is:
Number of times to go down = Y coordinate origin of robot – 1 = numdown
Number of times to go right = X coordinate origin of robot – 1 = numright
Number of steps to reach location = Number of times to go down + Number of times to go right = maxnum

The Plan

Generate

Generate strings maxnum length using two characters of my own choice which will be 0 and 1. 0 will represent movement to the right while 1 will be movement downwards.

I will generate the strings 0000…001, 0000…010 to 1111…111. All must be of length maxnum or in my case 120.

Screening

On the course of generation, one conditional with two arguments will be made.

These are, if the number of 0s and 1s in the string being generated exceed the number of allowable 0s and 1s (numright and numdown), then throw the string and proceed to the other.

Increment the Counter

If it passes the screening, then increment the counter. After the generation of possible combinations, echo or print the number in the counter. The number represents the number of possible movements.

Optimization

The code to be used could be optimized by:

  • screening should be done every after generation of a complete maxnum length string instead of screening the string while generating it character-by-character.

My head is already aching! Waaaa, I wanna solve it during the week. I won’t stop until I solve this. Amf!!

Try to play it here.

Tags:  
Posted in Google, Programming


Mar
29
2008

I’m Loving Microcontrollers, again?

Waaaaaaaaaa!

Free Fall Motion TimerLately, I’ve been busy finishing our research project with the great help of Kuya Franz. Our graduation is over but still I lack some requirements which I need to get my high school diploma.

During the process of finishing it, I started to love microcontrollers, again, for the second time in my life. It was a really fun experience; especially the learning process. I learned a lot of things from kuya Franz; from Hi-Tech C (a C compiler for embedded systems) to active pull-ups and pull-downs, to Proteus VSM and a lot more.

Before, I only knew programming PICs and 8051s using assembly language; now I can do it in C (in just three days; but I’m still not that good at it). I found it lot easier to do it in C rather than doing it in assembly because there’s no need to worry on 16-bit to 32-bit operations, no need to assign variables to RAM addresses. It’s also a lot better ’cause it saves you a lot of your previous development time (that’s the best thing in programming microcontrollers with C).

Circuit-wise

It was also my first time to see an oscilloscope work. I was amazed of its function and how it measured the period of the signal’s transition from high to low and vice versa brought by the counting of the microcontroller’s internal timer. We (kuya Franz and I) were able to make the timer accurate (not precise) up to the fourth-decimal-place (0.0001) as attested by the Philips oscilloscope.

Neat BreadboardI also learned how NOT to make a spaghetti circuit in a breadboard. I was able to put some stuff in the breadboard in a much neater way than I used to. (in the picture, kuya Franz cleaned up some of my dirty connections).

I also saw an In-Circuit Serial Programming (ICSP) programmer, again for the first time in my life. It was a nifty useful. With ICSP, there’s no need to remove the microcontroller from the circuit to program it thus reducing the risks of microcontroller breakdown. I also saw a Zilog development board; which according to kuya Franz costed approximately PhP 90,000.00 when it was still out in the market (fortunately he got one for free courtesy of Zilog).

I also found a PIC Simulator alternative; it’s called Proteus. Proteus is a package of ISIS (circuit designer and simulator) and ARIES (circuit [the real one] CAD). With Proteus, you can test a lot of microcontrollers. It also gives you the freedom to simulate your own circuit. It has a wide library of microcontrollers, resistors, transistors, power sources, LCDs and other electronic components. :D It’s the best simulator and circuit design tool I’ve ever met in my entire lifetime. :D

I got a lot more jargon to say, I warn you. Another thing, I used to be familiar only with Atmel products specifically its 8051 line. But our research study forced me to learn PICs. I studied its white-paper thoroughly just to get familiar with its SFRs or special function registers. I’m amazed cause I learned that PIC products’ timer0′s don’t have a timer run bit. It’s a free-run timer and runs all the time. I also learned that their operating voltage ranges from about 4.5 to 5.5 volts. Amazing!

I also loved the way we ate our merienda. Yesterday, we ate our merienda with a calculator. We discussed on what prescaler to use for timer0. We ended NOT using prescaler so we had to set a bit to a particular logic just to realign the prescaler to the WDT (watchdog timer). It was a nerdo moment!

Hahaha. I really learned a lot from kuya Franz, and it was a nice experience. He told me that I can go to their house if I want to learn something new from his projects. He encouraged me to continue learning embedded systems; which is a part of my plan for this summer. Weeeee, microcontrollers are the best.

That’s all for now!

Posted in Programming


Mar
22
2008

PHP Function for Checking Google Pagerank

Hey guys, I found this nifty piece of PHP file. It contains a PHP function for checking Google Pagerank. I had a hard time finding for a good code. I saw some working codes but too bad they were PHP classes which I’m not very familiar with.

The PHP file’s homepage can be found here.

Anyway, please don’t abuse the use of this Google Pagerank check PHP function. It has been reported that Google bans I.P. addresses of abusive servers.

Have fun with the code! :D

Tags:  
Posted in Google, Programming