Monday, January 18, 2010

Website

After having this blog for what, 2 years now? And writing only 8 posts in the first two years, I've decided that I needed to actually start writing stuff here, not just any stuff, but good stuff, stuffy-stuff, you know what I mean? Well I have decided to actually put an effort into keeping this blog up-to-date with all the projects that I work on, and to share my code, so that everyone can benefit from my projects.

...The Big News
As part of this sort of New Years Resolution, I have decided to move away from a dedicated Blogger blog, and actually run my own website where I can have more then just a this very linear styled blog. Instead, now I will be able to post tutorials, and actually have dedicated pages for my code, implement nice syntax highlighting for the code I post, etc... So I'm very excited about this change. After nearly 6 months of working with Fatcow (a great web host IMO) on the www.spareourgreen.com project, I have figured out exactly what I do/don't want in a webhost, so now that I am getting a new website, I have been searching for the perfect host.

...A Perfect Fit
After hours of searching, reading review, visiting websites to look at every feature, and multiple talks with customer service reps, I was still unhappy with every option that I had found! I am being kind of picky, but I just knew that someone had to have everything I wanted (that also still has a reasonable price). On my list of need-to-haves were:
  • Shell Access (SSH)
  • Cron Jobs
  • FTP
  • Unlimited MySQL (but more preferably PostgreSQL)
  • PHP
  • Python
  • Perl
  • Ruby (would be nice, but can live without)
  • Some sort of SSL
  • IMAP & SMTP servers (or ability to change MX records to use Google Apps)
  • Some kind of control-panel / file manager
  • unlimited sub-domains
  • custom error-pages (preferably the ability to edit .htaccess)
  • And SSI would be cool, but not necessary
A pretty extensive list, nothing too arbitrary, but believe me its difficult to find all of that available in one package! Like I said, all my searching led me to nothing. Then after a weird Google search "php python perl postgre mx" or something like that, I came across yet another website that listed and compared web hosts, but this one was specific to finding good python hosts. I searched the page for "ssh" and found 6 instances, and clicked on all 6 of the links to the web host. The first 3 were dedicated python servers, then the 4th one I looked at had everything I wanted, and more! It has everything I listed above on my list, plus it has Git (and sub-version, but why use that if i have git) pre-installed, and they are already compatible with Magento!!! <3 This isn't all that important to me since I don't really plan on selling anything (at least not in the near future), but I just think this is really cool because about 2 or 3 years ago, I spent close to a week working on getting Magento installed on a home server with a bare-bone installation of PHP. It was such a pain in the ass, so that is why its just cool to see that they're pre-compliant with it. Now that you're all wondering who this amazingly awesome web host is, I won't be telling you!

Just kidding, the host I've been talking about it A2 Hosting. And all of this that I've mentioned above can be bought for as little as 4.77 a month is you are looking to commit for 36 months. I only chose the 6 month plan cuz I first have to prove to myself I'll actually use it, but if I can make it until the summer, then when I re-purchase the plan, I'll get the 36-month one.

...My New Website
Now I'm just waiting for the domain name to finish registration and be updated with the correct name-servers, and then I will start development of the site, and soon afterwards, I will be transferring this blog over to my site. The domain name is (just like this blog) bmbsquared.com. I look forward to developing this site, as I will try to include many new technologies, and make it very Web 2.0 ish. See you at the site.

- B-Squared

Sunday, January 17, 2010

Fun With AI

So at my robotics club, one of the other mentors and I are both extremely interested in AI, and he has been talkin with me about some different projects we're working on. Some of the younger kids became interested, and we started to describe to them the simplistic view of AI. He used the example of balancing a stick on a finger. Picking up an aluminum bar, he demonstrated how an AI robot would slowly learn to balance the stick. Then I gave the specific example of evolutionary algorithms (which i have the most experience with). He then said that evolutionary algorithms wouldn't be able to do that... but I was adamant that it could be done. So I've decided to prove him wrong by actually doing it.

...Starting Work
I've started writing a 2D simple physics engine to just be used for this balancing the stick problem. I will be utilizing the JGAP Java package to simplify the work I have to do, by providing all of the mutation and crossover algorithms. Basically this will boil down my work to providing it the correct functions that the program will be allowed to call.

...The Constraints
I have given some arbitrary constraints for this problem. I will allow it to work on a fake track that is a set length, probably 1 or 2 feet. Like i said, this demonstration will only be in two dimensions. As you can see this problem is actually not very complicated at all. Oh yea, this project will be in Java, and I'll post all code once I'm done.

I've been very lazy about coding over this break from school, so this challenge will hopefully kick me into gear and get me working much harder then I have been during my last week at home. To clarify, I actually program 40 hrs a week at my job, but outside of work, I haven't gotten much done.

Wednesday, January 6, 2010

third, second, FIRST!!!!!

Once again, all of our favorite robotics competition is about to start, and all of the teams are excited to receive this years unique challenge! Its FIRST Robotics. Every year, thousands of teams worldwide compete in this high school robotics competition.

...Atholton RAID
Last year was my final year at Atholton, so it was my final year competing on our HS FIRST team. But this year, I have come back as a team mentor! This evening we had our first meeting (no pun intended) and I had to catch up on a lot of information. Our club had nearly doubled in size from only 12 dedicated membors to 30! Everybody had already chosen their sub-teams, so we knew who would be focusing on electrical, design, programming, and hardware. On Friday we'll meet again, then Saturday is the kickoff. The whole club will gather and watch a live screencast of the presentation of this years game by famous inventor, Dean Kamen, and esteemed MIT professor, Woody Flowers.

...The Competition
This year, the game has been designed to make it much more interesting for spectators, such that there will hopefully be a non-technical audience to whom this can appeal! The game entails of teams of three robots, that face against each other. Each team has 2 goals on their side of the field in the corners. They can score 1 point by kicking a soccer ball into this goal. On the field, there are 12 soccer balls at a time. As they are scored, the human players must re-enter the balls onto the field through a ramp structure that is above the playing field. If you with to see more about the game, visit www.usfirst.org.

...Our Robot
Now just over a week into the 6 week competition, we have finalized the chassis design of our robot, all of the manipulators we'll be using, and have begun working on designs for the different manipulators. We plan on a long or short-range ball shooting mechanism, as well as a way to pull our robot up 20 inches off the ground using the tower that is built on the field. We are looking at linear pneumatic launchers, as well as potential rotational energy to launch the ball. We also will be using two camera's, one for ball viewing, and another for finding the target above the goals. This will help to keep the balls under control, and also to accurately measure distance from the robot to the goal. Our main objective with this is that we can have a "fire & forget" system. We will have a light on out driver station that will light up if the camera's see a ball and the target. If bot are seen, then the driver can just tap the trigger on our joystick, and the software will then move to get the ball into alignment with the target, compute its distance from the goal, and fire with accordingly. As far as our robot lifting mechanism, we are evaluating the feasibility of a scissor lift system that will pull up the robot. The final design concept that has been bouncing around is that of a system to pick up another robot, and carry it on top of us, as we lift ourself off the ground. This system would gain us an extra 3 bonus points at the end of the game, in addition to the 2 we get for pulling ourselves off the ground. I feel that if we can get this idea to come to fruition, it will most definitely be one of the top robots at the competition.

Tuesday, January 5, 2010

RPS Competition!!!

Anyone else as psyched as I am??? No??? Huh, thats weird. Well anyway, I have decided to host my own rock, paper, scissor tournament! Still not interested? How about if I told you that you had to program a RPS bot to play the game against another persons RPS bot? If you're still not interested then there's no hope for you... If you are interested though, then read on!

...The Idea
So after my daily reading of the Official Google Blog on Nov 25th, (maybe it was the student blog???) I saw that the University of Waterloo had hosted a rock paper scissors programming challenge. I was extremely interested. I looked over all of the sample code, and I read a few articles about logic that can be used in the game. This was my sole inspiration to hold my own tournament. As of this evening, I will begin to write the Java bot that will moderate the game. Hopefully I can finish the bot by the 23rd of Jan, so that I can make a website for it and begin to advertise around the UMD College Park Campus.

...The Competition
Then a week or two into February I'll open up registration so people will be able to test their robots. And every other day, I'll run the competition on all of the submitted code. For three weeks this will continue, and people will be able to tweak and re-upload their code to make it smarter. Then on the final weekend, (probably Saturday) I will host a big RPS party and everyone can submit their final programs and see who comes out to be the winner. I'll eventually think of prizes that the top three or so will win.

I hope that other people are as excited as I am about programming RPS artificial intelligence. I think it will be very difficult. As it gets closer to February, I will try to post some basic RPS logic so that people can get an idea of how to go about programming this.

Thinking about doing this competition also has me thinking about other AI competitions that I could run. If you have any ideas lemme know in the comments.

A Quest For The Holy Grail

...well, not really. But I am learning Python! After years of programming in just Java, I finally thought it would be a good idea to branch out. I then took on my website project I described in my last post, and from that have come to gain a good understanding of PHP and its useful libraries, SQL queries, and Javascript. But I wouldn't consider any of these a true full-functional language as they all are built on web infrastructure.

...Picking a Langue
Yes I know that language is spelled with a "age" at the end... but I meant to say langue. Langue's meaning is very close to that of language, the difference is that language is, well, a language, but langue (noun) means a system of conventions and rules upon which we communicate. So I would actually say programming languages are actually more Langue-like... if that makes any sense.

Anyway, after deciding that I needed to learn a new language I started researching all of the possibilities for what I could learn, based on which ones could possibly provide a benefit to my career. My final list was as follows:
  • C or C++
  • Python
  • Ruby
  • Erlang
  • Perl
  • LOLCode
First, I ruled out any with a lack of a true compiler/interpreter. KTHXBYE LOLCode :'( Now that I had 5 viable options I looked at things such as :
  1. Will I have to learn it in the future?
  2. What types of programs will it write?
  3. What kind of learning curve is there?
  4. How big is the user base?
My first question, will i have to learn it in the future, only targeted 1 of the items on my list. Since I am on the University of MD Robotics club, I will eventually have to learn C so that i can program PIC micro controllers for the robot. I will actually have to do this next fall. And this will also be needed for some EE classes later on in my junior and senior years most likely. For this reason, I ruled out C/C++. (Also, if needed I actually can churn out a small C program, i just never got further than any of the basics.)

Now I was left with Python, Ruby, Erlang, and Perl. I separated them into 3 categories: Perl, Python/Ruby, and Erlang because Python and Ruby are so similar. Next, I eliminated Erlang. Although I would have loved to learn a true multi-thread language, question 2 and 4, as well it being hard for me to find a legitimate use for it in my code, turned me away from Erlang. Although I have skipped it for now, I feel that the next time I decided to learn a new language from the ground up, it will be Erlang (hopefully in a 2 years or so).

...Python vs. Ruby vs. Perl
Now that I'm down to three, I once again grouped Python and Ruby together due to their similarity, and compared them to Perl. After looking at some code and reading all of the introductory tutorials, I felt much more comfortable with Python/Ruby then Perl. Then after reading other people's testimonials, such as this one, it wasn't a hard choice for me to eliminate Perl.

Choosing between Python and Ruby was difficult as they are sooo similar, and unlike the case of Python v Perl, no one was willing to say that one is truly better then the other. My final decision boiled down to the fact that Python is much more widely used (in my opinion), and more importantly to me, Google uses Python extensively. That pretty much sealed the deal, as I have an incessant infatuation with Google.

...Beggining to Learn
Now that I have chosen, it's time for me to begin to learn the language. I just purchased my book, and will be updating the blog on my progress and any interesting tid-bits now and then. But as this is my second project outside of my 40 hour work weeks, progress will most definitely be slow.

The New Year! ...and Correct PHP Code Design

Its been a while since my last post, but I've made it a sort of new years resolution of mine to start posting more regularly here. Now my focus will not be solely on AI stuff, rather I will cover any tech topic that I am learning about or using.

...Catching Up
So over the past few months, I have put a lot of time into developing my website, www.spareourgreen.com. If you actually want to hear about what the website does, go ahead and visit it, here I will just be covering the technology used. Never having written any websites other then straight HTML and Javascript, I was excited to learn PHP. After reading a book about PHP basics, I dove right in and started coding the first 5 or 6 pages. I finally got all of them working correctly, but then realized a problem I was having, every time I added a new menu item, I would have to add the new link to each page individually. ThenI came to the realization that I should dynamically load all of my web pages from the one centralized source, and keep individual page content in its own file. This way, updating the menu or the footer makes the change across all the pages.

...Another Challenge
Now, after nearly 4 months of working on this code, and having different pages load different content into their menu's and such, my code is once again a horrific mess! Now when a page breaks after adding a small new feature, I have to pick through hundreds of lines of unstructured code to try and find my problem. Usually I know where the problem lies, but even then it is still a pain to find. After recently adding a new section to my website that has vastly increased the complexity of my code, I have decided to wipe out all my old code (not really, never delete your old code, just .7z it and save it on your HDD), and re-write the website using well-structured, scalable, object-oriented programming in PHP.

With object orientation, making a broad change across all of my pages is as simple as adding a new function or method to an existing class, or adding a new class to my main .class.php file. Then, I can choose which pages this needs to be implemented on, and make 1 new function call on those pages. The way I am using the OOP actually could be implemented the same way I had done it previously by using just 1 php file and adding new methods, but like I saw, that can get pretty messy. Working with objects is much easier to keep tidy.

...Progress
Right now, I have just begun to undertake this new initiative. I have written a User class to store data about the person visiting the site, as well as a Page class which is what will be my initial call on every php page. So here is what a sample site could look like:

<php require_once(../classfile.class.php); $file = new Page(); ?>
........HTML or PHP page specific content goes here............
<?php $file->close() ?>

As I continue to work on this code, I will keep updating on my progress and try to provide information on any problems that I run into so that you may learn from my mistakes.