Sunday, April 29, 2012

Web development: HTML, PHP, and SQL


First thing’s first, lets set up our environment. My IDE of choice is Netbeans, but that’s of little consequence. Next, install your PHP stuff. Later down the road, when we use MySQL, these tools will make yourlife a lot easier. In your php.ini file uncomment - extension=php_curl.dll to activate curl.

This post will tell you how to set upyour project. The easiest thing to start with is how to scrape a feed, basically cut and paste, see here. Quick posts to brush on your PHP:






Now let’s tap into Google APIs. Sign up for your Google License Key. Read how to use the Google API here and here. The Google News API is similar.

Next API were going to use is Twitter, well technically 3 Twitter APIs. The first is to get trending topics, seehere. Next, twitter searches, similar to Google’s search API, but you don’t need a key, see here. The third is a bit trickier, see here for help. Basically download Abraham's TwitterOAuth library add it to your project and go to http://dev.twitter.com/apps, register your app and get your keys.

Now before we jump in and start using SQL, I feel it’s important that you keep in mind the scope of your project. If you simply want to store a small amount of information with no respect to order, you might consider plain text. There’s a certain cost to setting up and maintaining a database and it may even hurt performance if you are just doing a simple project.

OK, ready? Start your server. Open up MySQL Query Browser. Right click on a Schema, create a new one or use a default, and create a new table. Now, let’s connect our new table to our PHP, see here. We’ve been getting json objects for our searches, so let’s store those in the database. For help see here, here, and here. I managed to get away with just using serialize() and mysql_real_escape_string() but not addslashes().

And there you have it. You are now the proud creator of a web application.

Sunday, April 15, 2012

Free Energy: E=MC^2


I’ve been interested with some of the more exotic aspects of physics since watching NOVA’s The Elegant Universe. It was mostly about the up and coming String Theory, but also covered the history of the field. By the way, interesting thing about String Theory, it proposes that there is a small chance that you can walkthrough a wall due to quantum tunneling. However, the probability is so small, the time it would take you to try is longer than the projected life of the universe.

E=MC^2 is probably one of the most famous equations in the world. Everyone’s heard of it, but few actually know what it means. Energy equals the product of mass and the speed of light squared. Now the speed of light is a very big number (299,792,458 m/s). So, this means any mass can be converted to energy (a lot of energy!).

Nuclear reactions rely on this principal to create energy. In a nuclear reaction that produces energy, two atoms combine (fusion) or one atom splits (fission) and at the end of the reaction the products weigh less than original reactants. That lost weight is responsible for the sun’s energy and the destructive power of an atomic bomb. That’s a lot of free energy.

Now, when I say free energy, I don’t mean G, although some of the energy that is released is. I mean using the dirt on the ground or particles of air to power our cities. But we’re not there yet, and perhaps we never will be.

You have probably heard of the second law of thermodynamics. Basically it says that entropy can never decrease. When energy is used to do work, some of it is lost as heat and friction and can never be used again. There is an absolute limit on the amount of work that can be done in the universe. One day, the universe will be nothing but entropy with no organization. Rather depressing isn’t it.


I would like to leave you with a story: The Last Question by Isaac Asimov. Perhaps a bit optimistic about the future of human race, but an amusing tale nonetheless.