Friday, October 11, 2013

Phonegap Diaries: Tools

Introduction

Twentyfour Challenge evolved from a native Android application written in Java using the Android SDK within Eclipse to a PhoneGap application where DreamWeaver (DW) is the main development tool.

This article explains the tools used to create the new, portable version of Twentyfour Challenge.

Tools

PhoneGap (2.9.6)

PhoneGap has two main functions:
  •          Provide javascript access to device specific APIs
  •          Provide packaging for targeted platforms

STS (2.9.2-RELEASE)

Springsource Tool Suite (STS) is a distribution of Eclipse from Springsource.  After the Android Development Kit (ADK ) is installed it is used to tweak the Android configuration files and generate the final package.  It also allows you to configure Android Virtual Devices (Android phone emulators) for testing.

Theoretically Eclipse is not needed as PhoneGap's Command Line Interface (CLI) does all of the work needed to produce a package, but that’s just in theory.

XCODE (4.6.3)

XCODE is the primary OS X and iOS development tool.  Its role is similar to that of STS but for targeting iOS platforms.  The iOS platforms include iPhone and iPad (all hardware variants).

DreamWeaver (CS6)

Although not strictly required, DreamWeaver is the best WYSIWYG tool for html/css web site creation.  A PhoneGap application is basically a web site running off the file system on the target platform

Additional Tools

These additional tools were used for special purpose tasks during the development project:
  •          Eclipse Javascript Project plugin
  •          Google jsTestDriver plugin for Eclipse
  •          Eclipse Groovy plugin
  •          iPhone and Android emulators
  •          Google Chrome developer tools
  •          Ripple emulator (a Chrome extension)
  •          Gimp
  •          Subversion 

Eclipse comes bundled with the Javascript plugin which gives IDE support for Javascript programming.  And the support is surprising good in terms of syntax error checking and autocompletion.   The one thing that’s missing is the ability to “Run as javascript project…”  (a search shows that there is a plugin to do this.  It involves running Rhino on the JVM).

Google has a code project called jsTestDriver that allows the development of unit tests for javascript code.  jsTestDriver  can be run from the command line, but there is also an Eclipse plugin that you can download and configure.  I regard unit testing as essential for the complex Javascript library that I developed for Twentyfour Challenge.

I used the Eclipse Groovy plugin to develop a groovy script that translates the 24 problem files from xml to json.  I did not want to do this by hand, and I knew that Groovy was ideal for such a translation.

The primary development tools (Android SDK and XCODE) deliver the phone emulators.  When these are launched from the IDE you can see output (console.log output) during testing.

The best productivity tools that I used were the developer tools within Google Chrome.  The only trick is that you must launch Chrome such that you can link to files residing on the file system.  This requires launching Chrome as follows:

open -a 'Google Chrome' --args --allow-file-access-from-files

The Ripple emulator was a late addition to the list.  It emulates the PhoneGap device specific API calls that your application makes.

Gimp is an open source tool that competes against Adobe Photoshop.  Since I had paid (educational discount here) for Adobe DreamWeaver, I didn’t want to pay for Photoshop.  Besides I’m not a graphics artist and can get by with Gimp.

Subversion is your good old version control software.  Use git if that’s your favorite.

Tools Not Used

I had the opportunity to use some cloud-based tools, but I choose not to use them.  They include the Adobe PhoneGap Build service and a testing service like SauceLabs.

I figured I had to use the emulators anyway so why hassle with cloud-based services that can potentially lead to monthly service fees.

Summary

That is a long list of tools.  I can't say that I've mastered them all.  You no longer use Eclipse and XCODE as editors and the parts that you do use like configuring Android Virtual Devices or code signing in XCODE are full of extremely frustrating dialogs.

All of the tools are all free with the exception of DreamWeaver.

"Wait!" I hear you say, "what about JQuery Mobile?"  I consider JQM a library and will discuss that in the Technologies posting.

Other postings:





Phonegap Diaries: Intro to 24 Challenge

Introduction

In order to get started in mobile development I appropriated a popular math game called "24" (I call mine "Twentyfour Challenge". Google play. iTunes store) and turned it into a native Android application (this was very unoriginal as there are many versions of this game out there).

Doing this required climbing a steep learning curve as there is a vast, new API to learn.  But at least I could program in Java using the familiar Eclipse IDE.  I released my app to Google Play store last December (2012).

But wouldn't it be great to re-write Twentyfour Challenge as a portable HTML5 / javascript application?  I decided to do this in the summer (2013).  I also decided to write a summary of my experience doing this re-write.  I call these the "PhoneGap Diaries." 

Here are the topics covered:


Friday, June 14, 2013

Don't Stand So Close to Me


I have this recurrent dream. A hot, female undergraduate is asking me what she has to do to boost her grade at the end of the semester. We're alone -- older male teacher and young female student. There's even background music to this scene and it's "Don't stand so close to me" by The Police. But I am getting ahead of myself. Let's start at the beginning of the semester.

The C++ course was not what I wanted to teach. But the assistant dean asked me just that, and it's best for an adjunct teacher to never say "no" to a course offering. So I find that there are 24 students enrolled including one female. This heavy imbalance is not unusual as the computer industry is male-dominated. Since it was the Spring semester I could count on most of the students being in their early twenties. For some reason the older, and frequently ex-military, students take my class in the Fall. I can't explain why the older students appear in the Fall, while the younger students come out in the Spring, but an attitude difference is readily apparent. The younger students just treat their college courses like high school courses as in "what is the least amount of work I can do to get a good grade?" The older students want to learn something in order to get a job.

This Spring my male dominated roster showed a wide range of programming skills. Some were decent programmers already, while others were unprepared having bluffed their way through the prerequisite courses. Most were in the middle.

In the decent programming skills group was Vince who proclaimed out loud the first class that he had eight years of programming experience. This programming veteran looked like a caricature right out of Mad Magazine having a pimple-laced face and wildly angle teeth. He talked boastfully about all of his experience setting up servers and compiling open source programs with his custom changes. The trouble was that Vince just did not want to listen to my lectures and do my assignments.

Also in this decent programmer group was Dan. Now Dan is my all-time favorite student. But it's not because he worked the hardest or got the best grades. It's because Dan always listened to my lectures and he always nodded in agreement to whatever I said. I would look around the classroom and see that students were either looking at me with no expression or staring at their computer screens. Dan was the one student I could count on to be paying attention and nodding affirmatively at all times. What a way to send positive energy back to the teacher.

Let me use Ross as an example of one of the bluffers in the class. Ross always came in about 15 minutes late to class. Since I make all of my announcements at the beginning of class this means that he never heard a single announcement. He would do the least amount of work possible, yet was always seeking extra credit for anything and everything. I had to continually extend the deadlines for quizzes and assignments for him because he never turned anything in on time.

The solo female, Amanda, was definitely in her early twenties. She kept to herself and browsed the internet while I was lecturing. I can always tell when a student is on Facebook or doing e-mail. The student's face is just locked on the screen with fingers tapping on the keyboard. They are definitely not paying attention to me. Why should they? My years of programming expertise just can't make up for my monotone voice. And if you’re not into programming, this stuff is boring.

I know I can do something about this. I can use the teacher control software to put my screen on all of the students' computers. I don't do this for a couple of reasons. It would piss them off so that they hate me more. Or, they would just switch to their smartphones and continue to ignore me.

Well the middle of the semester comes around and I give my open-book midterm exam. I think it's really easy, but then again I know this stuff inside-out. I'm amazed at how poorly some of my best students do on the midterm. Did they coast because it's an open-book exam? Did they just fail to study? I'll never know.

As the course drags on I notice that Amanda hasn't showed up for weeks. She hasn't dropped the course but she's behaving like she has. I send an e-mail to her as I would for any student who's acting like he/she is done with the course. No reply.

Well it's a week before finals and I finally scan the student's grades. I can see that Amanda is at the bottom having done about half of the assignments and half of the on-line quizzes. To my surprise she sends me an e-mail the same day and says she wants to meet me during my office hours. I agree and set a time for us to meet.

She shows up wearing exercise clothes: skin-tight nylon stuff that shows off every curve in her very curvy body. She sits opposite to me and says "Is there anything, I mean anything, I can do for extra credit?"

Now I'm getting nervous for a couple of reasons. One is that another adjunct might walk into the shared office where we are alone. The other is that I'm not exactly sure what she's willing to do for "extra credit."

So I say, "Amanda, did you ever hear of Riemann's zeta function? It's a pretty simple polynomial function but it's amazingly complex when its domain is the complex number system."

Amanda looks at me with utter non-comprehension as if I were speaking Greek to her. Greek, that's funny because the zeta function is stated with many symbols from the Greek alphabet.

"Well the zeta function expands to an infinite polynomial and like any polynomial we're interested in where there are zero values."

Now Amanda has started to lick her lips and blink her eyes to try to distract me, but I'm getting excited because I think I'm explaining the zeta function so well.

"Mathematicians have found many of the non-trivial zeros of the zeta function and since the domain is complex numbers the zeros have a real and an imaginary part. For all of the non-trivial zeros found thus far it's true that the real part is equal to 1/2. Isn't that amazing?"

Now Amanda is looking at me with serious confusion in her eyes like, "What the hell is this guy talking about? He must be hopeless."

"Okay, of all the non-trivial zeros found thus far the real part is equal to 1/2 -- but is this true for all possible non-trivial zeros? The assertion to the positive is called the Riemann Hypothesis and it hasn't been proven or disproven for over 150 years. What do you think?'

Amanda answers, "I think I don't understand. Besides what does this have to do with getting extra credit for the course?"

"I understand your confusion. I didn’t make clear the distinction between trivial and non-trivial zeros. The trivial zeros turn out to be all of the negative even integers like -2, -4, -6, etc. That's a consequence of the fact that zeta value of the quantity one minus s (e.g. z(1-s)) equals a value that has the sine function as a multiplicative factor and the value of that sine function is zero precisely at those negative even integers."

Amanda says, "I still don't understand. What can I do?"

"Well I was thinking that if you contributed to solving the Riemann Hypothesis, even a small contribution such as a tangential theorem, then I couldn't help but give you an A for the course."

Amanda left without a word.

I call out after her, "Did I say something wrong?" And she didn't ever stand close to me.

Tuesday, April 30, 2013

My Second Sprint Triathlon

Glutton for punishment or dedicated athlete? I won't know until my sports obituary is written, if it ever is. Anyway I completed my second UMLY Sprint Triathlon last Sunday in 1 hour 35 minutes and 55 seconds -- a four minute improvement over 2012.

2012 2013
Swim 13:00 13:07
Transition 1 5:27 5:20
Bike 44:17 41:44
Transition 2 2:38 2:33
Run 34:38 33:12
Total 1:40:00 1:35:55


The best way to contrast this year with last year is what I did not do while training.

2012 2013
Taught at 2 locations Taught at 1 location
Trained for 4 months* Trained for 2 months
Worked at Vanguard
Argued with my boss**

*The intense training left me irritable at work.
**My boss was himself an irritation.

I bought a new bike (GT Tachyon 3.0) and while shopping I was amazed by all of the categories of bikes there are (road, fitness, hybrid, mountain, comfort, etc.) let alone the various brands. I bought a fitness bike which has straight handlebars because I hate the curved handlebars that force you to bend over. The new bike worked great as I did not dismount once and pedaled up two very steep hills.

I started the 5 km run same as last year. My legs and buttocks were tied in knots and I had no desire to run. But again I recited the runner's mantra "put left foot in front of right foot, put right foot in front of left foot, repeat" and finished the race.

So in 2013 I improved my time over the previous year by 4%. If I keep this up for the next 25 years I will finish in no time!

Kudos to the Y and all of the volunteers who made this an amazing event. The Y closed the 50 m outdoor pool to get it warmed up (literally) for the race. The signage over the 13 mile course was excellent. And the cheering was motivating.

Wednesday, November 7, 2012

Two Hours as a Poll Greeter

I have never volunteered to work for a political party in my life -- until last night.  Since the media kept insisting that the 2012 presidential election was razor close, and because Romney started advertising heavily in Pennsylvania, I decided to respond to an email request to canvass Democratic voters on election day.

So reluctantly I called the organizer and offered two hours of volunteer work.  She said she didn't need any more canvassers.  Rather she needed a poll greeter to hand out sample ballots.  "Okay, I can do this," I thought.

So I showed a little early to overlap with the previous greeter.  He was there with his wife and granddaughter.  He showed me how easy it was to simply ask the incoming voters, "do you want a sample ballot?"   And he instructed me to thank the voters as they exited.

I thought, "boy, even I can do this." And so I did.  Some people politely accepted; some said "no thanks," and some were hostile when they saw the Obama sticker that I wore on my jacket.

My jocular coworker started chatting up his female Republican counterpart.  She was a local Republican committee woman.  She mentioned her name and I was surprised that her last name was Martinez.  Surprised, because she did not look one bit Hispanic.  Later she mentioned that her husband was Cuban and that his parents actually fled Cuba.

Fairly soon I was on my own handing out the sample ballots and thanking the voters while they were leaving.   My counterpart seem to wait until I went first, then she would offer a Republican sample ballot.   Most people accepted both ballots out of politeness or perhaps a desire not to indicate their preference.  Some people gave one of us the evil eye when they realized who we supported.

This pleasant stalemate continued until another female Republican greeter showed up.  The first thing she said to her colleague was "do you know the Communist Party has endorsed Obama?"  She made a loud stink out of this hoping to draw others into the conversation but there weren't any takers.  She also had a hand bell that she would ring as people walked by advising them to "vote right, vote Republican."

Now my timid excursion into politics was raising my ire.  But I'm not a talker and besides what could I say to this wingnut?  I just kept handing out my sample ballots and for every one that was accepted, Lady Wingnut forcibly thrust her counterpart upon the hapless voter.

Now we both were able to identify people we knew as friends and neighbors.  Lady Wingnut spotted a woman with two children as they approached.  She said to her colleague, "that's one of my neighbors."  She greeted the woman and asked, "will you consider voting for Romney and the Republicans?"  The woman replied, "No, I want to keep my vagina."  Then she quickly ducked into the building.

Now even I was surprised by what I heard and so was Lady Wingnut.  She asked her colleague, "did she say what I thought she said?" Answer "yes."  "Well, I know why she said that -- she's a teacher!"

That was probably the highlight of the evening for me but I want to recount another incident.  A couple who looked vaguely familiar to me from church accepted my ballot.  The middle-aged woman showed me the ballot and asked whether it was necessary to fill in all of the ovals in order to cast her Democratic vote.  I explained that she could vote along party lines and just fill one oval.

A few minutes later the woman emerged.  She wanted to know why the names of the Republican candidates were listed before the names of the Democrats.  I looked at my sample ballot which listed the candidates in this order: Republican, Democrat, Green, Libertarian.  I told the woman "I have no idea why they are listed this way."  So I figuratively crossed the aisle to see the Republican sample ballot.  It listed only Republicans.  A neat lesson in open-mindedness.

Wednesday, October 10, 2012

A Tenuous Analogy

Let me offer you three words -- inaccessible, hardship, and beauty -- and ask you if there's anything that can tie these words together. Based on my experience there are two seemingly unrelated topics that come to mind: Antarctica and higher mathematics. I was introduced to the latter as an undergraduate math major over forty years ago and again as a graduate student just a few years ago. As for Antarctica I learned about the heroic age of exploration in the 1980's, and had the fortune to visit the continent in 2010.

Inaccessible - unreachable, remote, unattainable.

Many people consider higher mathematics as inaccessible. Certainly you need an aptitude for it, but it does exist. In 2008 over 1,360 Phds* were awarded in mathematics in the United States. The interior of Antarctica is nearly inaccessible. You have to be well-prepared and well-motivated to go there. However, around 1,000 people winter in Antarctica every year including 50 at the Amundsen-Scott South Pole Station.



Hardship - a condition that is difficult to endure; suffering; deprivation.
There's no doubt that the exploration of Antarctica involved hardship. Consider the tragic ending to Robert Falcon Scott's expedition to the South Pole in 1912. I can't cite a case of death while exploring mathematics, but certainly there have been nervous breakdowns and possibly suicides.

The one thing math researchers and explorers have in common is the intense need to know the unknown. Apsley Cherry-Garrard, a member of Scott's support team, had this to say about polar exploration:
Polar exploration is at once the cleanest and most isolated way of having a bad time which has been devised... There are many reasons which send men to the Poles, and the Intellectual Force uses them all. But the desire for knowledge for its own sake is the one which really counts and there is no field for the collection of knowledge which at the present time can be compared to the Antarctic. Exploration is the physical expression of the Intellectual Passion.

I think you can substitute "mathematic exploration" for "polar exploration" and maintain the meaning of the quotation.

Beauty - the quality present in a thing or person that gives intense pleasure or deep satisfaction to the mind, whether arising from sensory manifestations, a meaningful design or pattern, or something else.

I can attest to the beauty of the Antarctic Peninsula. The snowscapes are gorgeous; the icebergs are magnificent. Many mathematicians, scientists, and engineers laud the beauty of mathematical forms that contain deep symmetry and internal elegance.


Here are mathematician Bertrand Russell's words on this kind of beauty:


Mathematics, rightly viewed, possesses not only truth, but supreme beauty — a beauty cold and austere, like that of sculpture, without appeal to any part of our weaker nature, without the gorgeous trappings of painting or music, yet
sublimely pure, and capable of a stern perfection such as only the greatest art
can show.

Here substitute "icebergs" for "mathematics" and again the meaning is preserved.

It would be silly to suggest that a heroic polar explorer would make a good mathematician or vice-versa. I count myself as neither an explorer nor a mathematician, yet I am fascinated by both species. The best I can do is explore words, make an analogy, and hope the analogy works.

*Phd's awarded in the United States in mathematics and statistics in 2008.












Tuesday, May 1, 2012

My First Sprint Triathlon

I finished at precisely 100 minutes -- five minutes more than I had hoped.  Actually at one point I thought I could finish around 85 minutes but I'm getting ahead of myself.



I'm talking about the 2012 Upper Main Line Y triathlon consisting of a 450 m. swim, 10 mi. bike ride, and 5 km. run.  I had been thinking about doing this for over a year before I convinced myself I could do it.  I trained for four months prior to the event during which I:
  1. Spent $400 fixing up my 40 year-old Schwinn LeTour bike that I did not use.
  2. Crashed same bike two weeks before the race and escaped with minor scratches.
  3. Felt exhausted and cranky at work most of the time.
  4. Lost 5 lbs. while eating unconstrained amounts of food.
I started training at the beginning of 2012 by doing gym triathlons - swim indoors, bike on a spinner, and run on the treadmill.  I never did the full distances but felt confidant I could do 12/32/31 minute splits.  With 10 minutes for both transitions I would finish in 85 minutes and win my age group (based on the previous year's results).  Then I started training outdoors and realized that the 50 m. pool, the hills on both the bike and running course, plus the wind added a real difficulty factor to the endeavor.  Fortunately I realized this before the event and decided to relax and enjoy the event.

Here are my splits as per my Ironman watch.

Swim13:00
Trans #15:27
Bike44:17
Trans #22:38
Run34:38

It was a perfect day -- temperatures in the 50's to 60's, brilliant sunshine, low humidity.  Because the swim event was in the outdoor 50 m. heated pool, the 300+ participants were divided into groups and each group started only after the previous group completed their swim (every athlete wore a timing chip which was tracked by computer).  This resulted in a nice, peaceful competition of athlete vs. self instead of athlete vs. crowd.

The swim was fun, the bike ride was challenging as I had to walk my bike up the two steepest hills.  The run was dreadful.  After finishing the bike ride I did not want to run 5 meters let alone 5 kilometers.  But following the mantra of "put one foot ahead of the other, now REPEAT" I muddled through the run.

Then it was over.  Later in the afternoon I slept exactly as long as I had competed.  Amazing how things balance out.