Tuesday, March 26, 2013

Programming with Java on Google App Engine

I wrote a draft post about Google App Engine many moons ago when it was Python only. As I’m not a Python man, the post isn’t very technical. Anyway, things have changed and GAE now supports Java. Albeit a customized subset of Java, which I’ll go into later.
Google App Engine is a cloud computing service: run your programs on their servers and pay by CPU usage. It’s similar to Amazon’s EC2 and Microsoft’s Azure, but unlike them in there is an absolutely free trial. You’re only required to provide a telephone number when signing up.
Step 1: Create the proper account
Sign up for a Google account here and a Google App Engine account here. After the GAE account is created, you should be prompted to create a new Google App Engine ID.
Now, if you’re like me, I won’t want to have to download and install the various SDKs and IDE to make your GAE app. So, I suggest Codenvy. Be sure your logged in to your Google account and click “Connect with Google”. Be sure you’re not using Internet Explorer, Codenvy seems to have issues with it.
Step 2: Create a project
On the welcome screen, choose “Create a New Project From Scratch”

Choose  Java Web Application (WAR) -> Google App Engine

You have to select the sample project, but you can skip using the JRebel plugin.

Use the Google App Engine ID you just created.

Step 3: Clear out the sample code

Click the project tab in the left menu (next to the Package Explorer tab)
Delete the src\main\java\com folder.
Delete the src\main\webapp\display.jsp file.
Open src\main\webapp\WEB-INF\web.xml and empty the “servlet” and “servlet-mapping” items. You can add java code to the src\main\java folder at a later time and add the proper information in these tags to specify it as a servlet.
Add the following in the “web-app” item after the “servlet-mapping” item:
<welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
Open src\main\webapp\WEB-INF\appengine-web.xml and make sure the “application” has enclosed your Google App Engine ID
 Customize src\main\webapp\index.jsp as you wish.
Step 4: Run your app on Codenvy servers
Make sure you save! Codenvy does not auto save changes when building.

Run -> Run Application

Step 5: Load your app into Google App Engine:
Make sure you save! Again, Codenvy does not auto save changes when building.
Go to Project -> PaaS -> Google App Engine

Select Application Update


If you get an Oath token error:

PaaS -> Google App Engine -> Logout

PaaS -> Google App Engine -> Login

Also, see this link for setting up cron jobs.

Monday, August 6, 2012

The Job Search

I’m going to be writing some new types of posts, and therefore introducing a new tag. They’ll be about the time I spent on my job search. I’m now (luckily) employed, but I was on the job market for about 9 months, not including the job searching I did while in college, and have quite a few tales to tell.

I was speaking to a friend recently about our job hunting experiences, and the one thing we immediately agreed upon is that job hunting is a soul crushing experience. Between making cold calls to doing interviews to following up, it’s all a massive time sink. The worst of it is, even if you put in all that time, you have no guarantee of success, just better odds.

The one comfort you can have is this: You have a skill. If you’re in a technical field and you’ve gotten proper training, this skill should be easily identifiable and valuable. Maybe you can program or cook well or can translate another language. And as a job seeker, this skill will be something employers are in need of. And if a business is hiring, they obviously have a need for that skill.

Thursday, August 2, 2012

Technological Singularity: an Unrecognizable Future


Do you ever feel like technology just moves too fast? I’ve already posted on how technology has past me by in many ways. But there might be more to it than people falling behind current trends. There’s the idea of a technologic singularity.

The technological singularity is an event in the future when technological progress becomes so rapid that it makes the future “different”. Central to this concept is the concept of accelerated change: technologic breakthroughs allow the next technologic breakthrough to occur sooner and easier. For instance, our technologic improvements in computers have allowed us to study genetic data faster and advanced our knowledge in genetics.



(Ignore that calculations per second, they are a poor measure of intelligence)

Some interesting consequences occur. As we build faster computer and create better algorithms, it allows us to create faster computers and better algorithms. But, that’s really all just an evolutionary trend, when our computers reach a high level of AI it will become revolution. It will be a paradigm shift: a social change so large that will occur and a new generation will be created.

And after the singularity? We will be able to construct machines smarter than us. And in turn, we will become more intelligent. We will become something else.

Before I finish, I would like to recommend The Gentle Seduction by Marc Stiegler as a look at what our future may become.

Monday, July 16, 2012

Loss Leaders

I’m a big fan of Valve’s Steam service. It took me a while to come around though. Even today I still keep local copies of all my games in case of a doomsday scenario. It takes a lot of trust to buy into a Digital Distribution service. Will they respect their customers, because it’s not like you can take your library someplace else if they decide to change their Terms of Service for the worse? Will they remain competitive, or will I have to start buying from other services and fragment my library? Will I still be able to access the things I paid for in 10 years?

One of the things that push me over the edge was their amazing sales. Amazing games for just a few dollars. As someone who was unemployed at the time, or even just price conscious, it was too good to pass up. The basic idea is loss leading. Valve, or the publisher, takes a hit on the sale of a game hoping you’ll come back and buy more games from Steam or from that franchise. In the end, gaining a returning customer at the cost of a game that they may have never bought anyway.

David DeMartini Origin’s, EA’s competing DD service, boss was asked in an interview about these sales to which he responded, “We won't be doing that. Obviously they think it's the right thing to do after a certain amount of time. I just think it cheapens your intellectual property.” Take from that what you will considering partiality of the speaker.

Valve’s business development chief, Jason Holtman, responded to the criticism, “If all that were true, nobody would ever pre-purchase a game ever on Steam, ever again. You just wouldn't. You would in the back of your mind be like, okay, in six months to a year, maybe it'll be 50 per cent off on a day or a weekend or during one of our seasonal promotions. Probably true. But our pre-orders are bigger than they used to be. Tonnes of people, right? And our day one sales are bigger than they used to be. Our first week, second week, third week, all those are bigger.”

What’s underestimated in Holtman’s response is the importance of the social side of gaming. If all your friends are playing a game now, you’re more likely to buy it now to be able to discuss it with them or play it with them. Not to mention, if you happen to pick up a multiplayer game several months after launch, your libel to be greeted by many an empty server.

I’ve recently started dabbling in another Digital Distribution service, Amazon MP3. They too have been a major user of the loss leading tactic. It’s not odd to see a $10 album drop to $3 or songs drop from 99 cents to 25 cents. And boy do they give away free credit like there’s no tomorrow.

They too faced scrutiny for their tactics. One unnamed retailer is quoted in a report as saying, “I love it when they have a successful loss leader pricing deal. I can't stop laughing every time I think about how much money they must be losing”.

The problem is that music doesn’t have the same social aspect as gaming. Outside of people who are really into the technical aspects of music, most really don’t discuss it beyond “like” or “dislike”. There’s no real analog to multiplayer in music. So, there’s no pressure to buy music quickly beyond a few special circumstances like social gatherings. At the same time, this means the price of music will generally stay constant over time. What is a 99 cent song now will remain so for the remained of its life, barring sales.

While Amazon certainly has the money to keep their MP3 Digital Distribution service afloat for quite some time, I question how effective their loss leading strategy will be in the long term.

Sunday, June 24, 2012

The Scorpion of Baldora Field


I’m not going to do a lot of the typing this post, this time I have a story. It’s a monolog from Night on the Galactic Railroad about the scorpion of Baldora Field:

Our father told us once about the scorpion of Baldora Field. The scorpion killed other bugs and ate them.

Then one day, a weasel found him. The scorpion fled, and fell into a deep well. He was trapped, and knew he'd die.Then, he thought to himself,"How often have l eaten other creatures? And now, the one time that l was the prey, l fled in utter terror. And look what came of that. I'll die in this well, alone."

"Life is filled with uncertainty. Why didn't l accept my fate? If l had freely given my life to the weasel, I would have given himanother day of life.But now my death will help no one. I am useless. Dear Lord, I beg of you, look into my heart and hear my prayer. In my next life, don't let me waste myself.Let me use my body for the truehappiness of everyone in the world."

And then the scorpion burst into flame: a brilliant crimson glow. And by the light of his burning body, he lit up the night forever.

How beautiful!

I always liked the story. “Put the others before yourself” is a very nice motto. Even if it has a subtle communist overtone. The world would probably be a better place if everyone thought that way. But like the story says, when death has you in its clutches, even the courageous falter.

There was a story a few months ago on 60 Minutes about the cost of end of life care to tax payers. It reminded me of this story. It’s easy for most to expect the old and sick to accept their fate and save the tax payers a few dollars, but it’s much harder to accept it when your time comes.

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.