Thursday, August 23, 2012

Blogging

I have made changes to this blog.

Namely, I have created pages.  I tried tags for a while, but they never felt right for me.  Tags are meant to organize and help someone search through posts, but they always felt sort of flimsy and cheap to me, but I'm not sure why.

A while back, I found myself writing quite a bit about Android development, so I decided to move that into its own page.  Today, I decided that travel should be its own section as well, so I moved it into its own page.  You can navigate to those sites using the buttons at the top of this page.  Tomorrow, if I find myself writing a lot about another topic, I'll repeat the process.

I think one of the effects of making topic specific pages is that the ads presented by Google will be much more specific to the subject.  Also, I think the navigational bar at the top of the screen look more organized and polished.

Background Processes

For many apps, background processes are needed to accomplish some tasks.

Here, I will setup a class that runs a background process.

To set up the file in Eclipse, navigate to the package you want to add this to, and right click on src->"package_name", where package_name is something like com.example.project_name.  From there, select New->Class.  In the popup:
I set the name of my class to "Service_handler".
I set the superclass to "Service".
I then added some methods, so that the basic framework looks like this:
public class Service_handler extends Service 
{
public IBinder onBind(Intent intent)
{
return null;
}

public void onCreate()
{
System.out.println("onCreate");
}

public void onDestroy()
{
System.out.println("onDestroy");
}

public void onStart(Intent intent, int startid)
{
// Grab a "log_msg" from the caller
String message = intent.getStringExtra("log_msg");
System.out.println("onStart "+message);
}
}
Also, add this to the xml manifest file, within the application tags.
<service android:enabled="true" android:name=".Service_handler" >

Now you start the service with code added to your main activity, like this:
public void onCreate(Bundle savedInstanceState) 
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_first);

Intent myIntent = new Intent(getApplicationContext(),
Service_handler.class);
myIntent.putExtra("log_msg", "hello_from_activity");
startService(myIntent);
}
If you used the code above you should see this text in the logCat output, "onStart hello_from_activity". 

Driving out of NYC

In New York City, public transportation, whether subway, bus, rail or taxi-cab, is superior to driving a car - in most situations.  In the remaining instances, like going to the suburbs for a friend's birthday and then picking up some groceries, having a car of your own is often better.

Here are the options for getting back and forth to long island when you don't own a car.

Public transportation (Taxicab, subway, LIRR)
- Subway is $2.25 per ride.
- Long island rail road  is about $8.25 per ride (more or less depending on distance).
- Taxicab to and from train stations or to and from subway - $12.

Rent a car from Hertz, Avis, Budget, Alamo, etc ...
- No sign up fee.
- Typically, you have to refill the gas.
- On weekends, the rates are around $200/day.

Zip car
- You need to sign up and there's a fee.
- There is an annual fee of $60 / year.
- Gas is free.
- Weekend rates of $85 / day.

Hertz On Demand
- You need to sign up in and get approved. I just applied, so I'm waiting on their response. (Update: it took 10 days for them to send me an email saying that I was approved and that they were sending me a vehicle entry device.  Then, another week went by before I got the device).
- There is no sign up fee and no annual / monthly fee.
- I think gas is included.
- Price quotes are hard to find.  I've heard that they're trying to undercut Zip Car prices.  I will update after I become a member. (Update: For the upcoming weekend, I found rates for about $18 for 1 hour and about $140 for about 8 hours.).    

Relay Rides
- This is a car sharing, where you directly contact another car owner.
- Free sign up and instant access.
- Typically, you will have to refill the gas you use.
- Rates decided on by the car owner.  I saw rates as long as $40 /day and as high as $200 / day.

Sunday, August 19, 2012

Atlantic City -- Noodle Bars

I have been to two noodle bars in Atlantic City, one in 'Show boat' and one in 'Borgata'.

In my experience, the Borgota looks cleaner, the food is less greasy and is the better one to go to.  In the Borgota, I always get the Pork Sa Chiu Noodle Soup, to which I add a few spoon fulls of hot sauce.  However, the wait for a table at the Borgata can be rather long and preferred guests can cut the line, which sucks, depending on your perspective.

Rucola - in Brooklyn, NY

Rucola restaurant, in Brooklyn, NYC, is intimate, trendy and cool.   Most importantly, the food is delicious and affordable.

It is a cozy restaurant where most of the patrons are in groups of four or less.  Nonetheless, I can attest that the restaurant can accommodate large parties, as I came with a party of 14.  We had a pre-set meal that began with fresh toasted bread and an appetizer dish containing meats (some type of pepperoni and prosciutto) cheese (some hard and some soft), nuts and jam spreads.  Next, we had two types of salads, one mostly lettuce and the other containing an assortment of mixed vegetables.  For the main course, we had a sampling of roasted chicken, grilled fish, pasta in pesto sauce, another pasta, and other cooked vegetables.  The meal was finished with two desserts, which I didn't really eat, but the others seemed to enjoy.   They also have a quirky drink list of beers and cocktails.  

Overall, this is a great place to eat.  It is a great place to go if you want to feel like a true Brooklyn-ite / Boerum Hill- ite.

Saturday, August 11, 2012

Bill Simmons - London Chronicles 6 - Dwight Howard - Mail bag

The sports guy reacted to the Dwight Howard to the Lakers, Bynum to the Sixers, Andre Iguodala to the Nuggets and pu-pu platter of players to the Magic trade with a pseudo-mailbag article.

Here's my analysis of his article.
It begins with a blitzkrieg of amazing Olympic events that Simmons has recently experienced in London.  He basically lists off events and Olympic personalities with a series of sentences that all start the same way: "I spent the ...", "I knocked Wimbledon ...", "I caught a ...", "I watched the ...", "I devoured more ...", "I lived vicariously ...", and "I saw five ...".  The good thing about this technique is that readers can understand the article perfectly, even if they zone-out while reading any of these example sentences. 

The article then says it will be a mail-bag article, and so we expect to see a series of questions from readers followed by replies from the sports guy.  However, the mail-bag is only two questions long and is basically used to introduce the recent Dwight Howard mega-trade.   As further proof that this is not a true mail bag article, Simmons does not end the article as he usually does - with a particularly outlandish question from a reader followed by the reply, "Yup, these are my readers".  

The article is mostly a series of judgments on who is a "Winner" and "Loser" in the trade.  Simmons makes his judgement explicit by starting each section with a heading like "Winner: The Lakers" or "Loser: Orlando".   Starting each section with the same format has the same effect as starting each sentence in the the first paragraph in the same style: namely, readers can jump around the article and  read or skip what they like. 

I always wondered how he digests a sporting event and publishes an article so quickly.  After a bit of analysis, I can see that Simmons uses defined sentence patterns and article sectioning to quickly introduce a range of topics or examples.  He often assumes that the user is aware of the event that he is writing about (a fair assumption) and thus wastes little effort in providing background and instead focuses on his reaction to the event.

Syntax highlighting in blogger


Here's how I post code snippets with syntax highlighting in blogger.

1. Go to edit template
Put these lines under the <head> tag:
<link href='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css' rel='stylesheet' type='text/css'/> <script src='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js' type='text/javascript'/>

2. Change the body tag.
From <body ... >
to   <body onload='prettyPrint()' ... >

3. When you make a new post, edit html and put these tags around your code:
<pre class="prettyprint">
// your code goes here.
</pre>

Here's some sample prettified code:
int main(int argc, char * argv[])
{
printf("Hello world. I'm using prettyprint.\n");
}
Note: If you change the template in blogger, the changes to the template will probably be lost, so you will have to repeat steps 1 and 2.

If you want to post xml code, you will need to 'encode' the xml first.
1. Enter the code with one of these tools.
http://centricle.com/tools/html-entities/
http://www.spacefem.com/tutorials/makecode.php
This does some simple things like turning "<" into "lt", which stands for less than.

2. Put the encoded code into the prettyprint tags mentioned above.

Wednesday, August 8, 2012

Hustle

Since as far back as I can remember,  my role on sports teams has been the hustle guy. Often this is a euphamism for the least skilled player who needs to work extra hard or else he would provide no other value for the team. And for me, the euphamism is spot on.

However, I don't see it as a negative stigma. I see it as me having some skill in one area, namely hustle.  Moreover, while I might have been naturally gifted with some amount of this talent, I practiced hustling so much that I definitely have become better at it. 

Seeing hustle as a skill that I must practice and hone, led me into an altercation today. In my rec-league basketball game, our team was up by about 15 points with less than a minute and a half remaining.  By all estimates, this game was over from a win-loss perspective.  But for me, since the game was still technically going on, I was hustling hard on defense, and accidentally fouled the opposition. While he was taking his free throws, the referee made a comment to me about taking it easy and not to foul at that moment.  But this pissed me off. I can't stop hustling. If I did, I would get used to that, and my one skill would deteriorate.  I didn't have time to explain to the referee that I needed to hustle all of the time, so I ended up being mad, and writing this blog post instead.

Tuesday, August 7, 2012

Android Tracking Time - Part 3

In a previous post, I extended the basic hello world app from the android development site.

In short, I could keep track of how long my application was in one activity or another by saving the times when either onResume(), onPause(), or startActivity() was called.  By keeping track of these event milestones, I could calculate how long my main activity was in the the foreground or not.

At this point, I think I have a fairly good understanding of the Android App life-cycle as an app is created, resumed, paused and closed.  At this point, I think it might be a good idea to learn how I can store data that will persist beyond this life-cycle.

Monday, August 6, 2012

Android + Eclipse + Egit

So, after making some very small progress in my app development, it's become clear to me that I need 'version control'. 
Version control is a way for developers to keep track of code changes, to merge changes with other team coders, and to make experimental changes without fear of messing up previous good work.  A primitive way that version control could be done is as follows:

1 - Write code.
2 - Copy all files into a folder called version0.
3 - Make code changes.
4 - Copy all files into another folder called version1/.
5 - Repeat steps 3 and 4, but update the folder name as you go.

This type of homemade system has flaws.  For example, you will end up wasting a lot of space as each folder has the complete set of files.  Thankfully, this old problem has been looked into and existing version control systems already exist.  CVS, SVN, GIT are a few that I have actually used.  Among these CVS is the oldest and GIT is the most modern.

For Android development in eclipse, there is support for all of them.  After some internet research, I decided to go with GIT.  The process involves using eclipse to install the egit plugin. From there, I followed the wiki guide to create a repository to hold my code changes.  At the moment, I expect to use only the most basic superficial set of features that egit will give to me: committing changes into the repository under the main master branch, comparing my current version to old versions, and reverting to old versions from time to time.
Now that this is all set up, I can develop under the sweet protection of version control.

Update:
I ended up doing a very simple branch and merge that I wanted to note here.
Here is the workflow.

1 - Create a new branch.
2 - Code, test, save, commit the change to the new branch.
3 - Switch back to master branch.
4 - Merge the new branch into the master.

There is something nice about working in a completely separate branch, knowing that you won't mess up your previous work, that is liberating and puts your mind at ease. I guess I'm a fan of branching.

Android Tracking Time - Part 2

Continuing from a previous post, I've now updated my app to track how long I've taken to return from one activity (started from my main activity).
Here's what I did:
Create variables to hold onto the times when messages are sent and returned.

public class MyFirstActivity extends Activity {
public static long time_msg_sent = 0;
public static long time_msg_returned = 0;
public static long time_diff = 0;
// rest of code like onCreate(), etc ...
}
Just before the second activity is started, set one variable with the current time.

public void sendMessage(View view) {
// do code to prepare Intent ...

time_msg_sent = System.currentTimeMillis();
startActivity(intent);
}
Add an onResume method, which is called when the first activity returns from the second activity. In this function, I added logic to calculate the elapsed time. The check for 0 and the reset back to 0 is needed because onResume is called during other points of the activity life cycle.

public void onResume() {
if ( time_msg_sent != 0 ) {
time_msg_returned = System.currentTimeMillis();
time_diff_s = (time_msg_returned - time_msg_sent) / 1000;
time_msg_sent = 0;
}
super.onResume();
}

Sunday, August 5, 2012

Batman: Dark Knight Rises

This movie was the third one with Christian Bale as Batman and Christopher Nolan as the director.  It was a high-paced, entertaining, action movie, whose plot-line was somewhat difficult to follow (mostly because the lead villian was impossible to understand).  As I reflect now, I know there are many details that I can hardly remember, even though I watched it today.

So, I am going to reflect on the general feeling I have as I left this movie: it was about legacies.  Bruce Wayne understood that his body was aging and thus he couldn't fight the good fight for much longer.  Would Batman be remembered as an evil vigilante or a selfless hero?  In the real world, Christopher Nolan presented his final piece of his Batman trilogy.  Would the movie live up to the past two?  My feeling is that the legacies of both are intact.  Both the character and the director delivered.

With that said, there are few things about the movie that I'm unsure about.

1. When Bruce Wayne is in the jail/hole/dungeon why can't he use the rope to climb out?  If he could, why can't all the prisoners use the rope?
My answer: Although it wasn't clear to me, there must be a prison warden and guards.  They need to give the prisoners food, and they must regulate usage of the rope as a safety tool only and not an escape tool.

2. Why doesn't the clan of evil-doers kill all of the cops that they've trapped in the tunnel system?
My answer: The cops must be hiding within the tunnel system, and it's too large for the bad-guys to find (even though the bad-guys were living in the tunnel system and seemed to know it well).

USA women's swimming versus USA women's gymnastics

My wife has been watching a lot of Olympics these days.  I don't share the same enthusiasm that she has for the games, but I watch with her nonetheless.  This year, the USA women's swim and gymnastics teams, in particular, have been captivating.

The great 'sportsguy' has already weighed in on which of these sports is the better sport to watch in person, but I couldn't help but wonder about another question.  Who would you take, the women's swim team or the women's gymnastics team, in a fight?

The gymnastics team is insanely quick and strong, but tiny.  The swim team is long and powerful, but I have no idea how coordinated they are outside of water.  A battle royale between these two teams is something I could be very enthusiastic about.