Saturday, June 22, 2013

Thoughts on the 2013 NBA Season and Finals

The team I was rooting for, the Spurs, lost to the team almost everyone was rooting against, the Heat, in a 7 game series.  I imagine that history will glorify the Heat and will more or less forget this year's Spurs.

I set my DVR to record the games.  Since the games were on late, I expected to watch the start of games and then finish the rest the next day.  However, I ended up watching most of it live.  I guess I was really into this series.

During the breaks in action, I checked twitter to read live instant updates.  I think twitter could replace or at least supplement sports announcing.  I'd like to tell the television who I'd like to follow and then their tweets would appear on the screen.  I'd also like to chat (maybe through twitter) with friends while the game is going on.  This would all appear on the television screen so that I don't have to constantly check my laptop or phone.

As much as I like Jeff Van Gundy, there are other broadcasters that I don't like as much.  If I don't like a broadcaster, it would be great if I can switch to another.  For big games, there are usually at least two sets of announcers (the local and the national).  For huge games, there are international broadcasts as well.  I'm sure some people would prefer to watch the game with the broadcast in a non-English language.

I have devoted way too much time to following basketball this season.  Zach Lowe, you have raised the bar for basketball analysis, hopefully other writers keep up.  I am now always commenting on the angle in which the Spurs bigs set picks (something that only diehards could get excited about).  48MinutesOfHell, your writing is always thoughtful and exceptional.  Well done.  The basketball Jones, you guys always crack me up.  It's gotten to the point where I feel like I understand some of your private jokes.

Now that the season is over, I'm happy to get back the time used watching, reading and listening about basketball, but it was fun while it lasted.

(Actually, after I post this, I'm going to listen to the final TBJ podcast, which I haven't had a chance to listen to yet).

Monday, June 10, 2013

Ruby on Rails tutorial

I began this tutorial, http://ruby.railstutorial.org/ruby-on-rails-tutorial-book, about a year ago and got through a few chapters.  However, I lost momentum, and for reasons that I do not remember at all, I stopped working on Ruby development.  Since I got a new computer and I probably forgot everything that I learned, I'm going to have to start from scratch and go through the tutorial again from the beginning.

Installing ruby, rvm, gem, rails ...
There seems to be a lot of stuff needed to install and configure in order for you to begin coding.  There really isn't anything fun or interesting to learn as you install this software.  You just have to do it, and hope that you didn't make some silly mistake that comes back to bite you later.   After a few minutes of downloading, compiling and other magic, I finished the installation process.

first_app
So after installing and configuring, you can start up your first app rather quickly.  With these commands:
rvm use ruby-1.9.3-p429  
rails new first_app
bundle update
bundle install
rails server
Bam! The server was up and running for me, viewable from a broswer and I didn't have to write a single line of code. It was almost too easy.

Github and Heroku
As recommended in the tutorial I also made a git repository, pushed the code onto github and deployed the project to heroku.  There is a lot of 'pushing' and 'pulling', and it can be a little confusing.  Here is a rundown of what's going on.

On my local machine (my laptop), I have all the source code and configuration needed to run the application.  This is good for development.  If all of your users (and other developers) had access to your laptop, this might be good enough.

But what if I want to share my code or back it up in case my machine crashes?  That's where GitHub comes along.  At the lowest level, Github is a place to back up your code.  At a higher level, it's a repository which can help you keep track of changes, allow you to easily test and revert changes,  and share and merge your changes with yourself or others.  The final thing that Github does (that I will mention) is that it helps me push my files onto Heroku.

Now, what is Heroku?  Well, for the purposes of this first app I just made, it's a better version of your laptop.  After you push your latest versions of your files onto Heroku, it figures out that you have a ruby on rails app and starts the server, where users can now visit.  You can configure heroku to work a bit differently than your laptop.  For example: (if you followed the tutorial), on your laptop you used sqlite as the backend database, but told Heroku to use another database (postgres).

Conclusion
This is the second time I made the first_app ruby on rails app.  It's been so long, it was almost all new to me.  Although, I think I was able to move along a bit faster this time, and I definitely understood a bit more than I did last time around.

Sunday, June 9, 2013

Biking in NYC

Citibikes have come to Manhattan.  This is a bike sharing plan where:
  • you sign up for access for some period of time (a day, a week or a year)
  • take out a bike from a bike stand (self service - without a human operator)
  • ride
  • return the bike to another bike stand (again, without human intervention)
  • hopefully return your bike within 45 minutes so you don't pay overage fees
I have my own bike, and there aren't many bike stands anywhere near me (or any above 59th street for that matter), so I do not plan on using the system at all.  However, I hope the system works and leads to these benefits:
  • Safer streets for cyclists.  The raw number of bike accidents and related injuries will surely rise, because the raw number of riders (many of them less skilled) will rise.  Yet, the more cyclists there are, the safer it is for other cyclists.  Cars (and pedestrians) will be more aware of cyclists, which will hopefully reduce the rate of collisions with each.  
  • Less congestion on the subway and buses.  
Hopefully there are many other unknown benefits.  Some downsides of citibikes are:
  • reduces the number of parking spots for cars.
  • the bike stands are a bit of an eyesore to some.  I'm not sure if the bike stands look worse than parked cars or wind mills off the coast of cape cod, but it is a complaint.

NYC culture

When the weather is nice, my wife, dog and I will go to Central Park at least once a week.  Over the last few weeks, there were a few events that affected our visits.

Puerto Rican Day Parade
This ran along 5th Avenue.  When there were breaks in the parade, pedestrians were able to cross the avenue to enter or exit the park.  We were able to enter at 72nd street without much delay.  However, when we entered the park, we found that the walkways were very congested and the normal access areas (lawns, the mall, sheep's meadow) were all blocked off.  I'm not sure if there was another access point, but a police officer told us that there was no access to our normal walking and relaxing areas, so we just left the park.  I'm not sure if restriction of park areas was related to the parade, but it ruined our visit nonetheless.

Conclusion: Unless you want to see the Puerto Rican Day parade, avoid 5th avenue, the east side and central park on this day.

Israel Day
Similar to the Puerto Rican Day Parade, there was a parade that ran along fifth avenue.  We crossed and entered the park without much delay on 72nd street.  Most of the park functioned just like any other day, except that an area near the Mall (just above the fountain) was closed off.  The only people who seemed to be allowed in were those who participated in the parade.  We didn't really ask how we might gain access, so we just walked around the restricted areas.  On this day, there were also protestors.  Because of the restricted areas with selective access, the protestors, Israel's history with terrorism, and the recent Boston marathon bombings, I couldn't help but feel a bit of tension in the park.

Conclusion: Similar to the Puerto Rican Day parade, avoid this parade and its activities unless you are sure you will participate and be allowed in to all of the restricted areas.

Japan Day
Unlike the parades, no roadways are blocked off for this event.  Instead, you will find Japanese volunteers scattered around the park advising visitors on where the events are.  Near the volleyball courts and the Mall, there is a large number of stands where the Japan day events are being held.  I think there was an origami stand and another place where you can try on kimonos.  You will also find lots of free Japanese food and drinks.  Also, there is a stage where you will see Japanese performers.

Conclusion:  Although it is crowded, this is the best of the events.  You might learn something, nothing is blocked off, and there will be lots of free stuff.

Thursday, June 6, 2013

MySQL on Macbook

My wife wanted to set up an environment so that she could practice her sql skills.  After a bit of research, I decided to give MySQL a try.  Here are my notes on how it went.

Step 1. Download the software.
http://dev.mysql.com/downloads/mysql/
I chose the 64 bit DMG archive for Mac version to install.  Before the download started I had to jump through a few hoops.  First, I had to register to get a new oracle account.  This sign up was pretty painful.  I had to provide my name, full address, phone number, and a complicated password.  As usual, I entered a password that I will surely forget by the next time I am asked for it.  I then had to fill out a survey about my job, what I will use the software for and some other questions.  This was a bit off-putting, but in the end, I finally downloaded the file.

Step 2. Installation.
I clicked on the downloaded dmg file and then the pkg file which started the installation process.  I was told that the install would use 680.9 MB of space, which seems a bit high.  The software was installed in less than a minute.  I also installed the MySQLStartupItem.pkg, but I'm not sure what that is.  I finally installed the MySQL.prefPane, which gives a GUI (placed as an icon in system preferences) so that you can easily start the MySQL server.

Step 3. Hello world.
I wanted to do the basic operations with a database to make sure that I had installed everything ok.  In the programming world, when you start working with a new language, you would try to write some code, compile it, and then output the results.  Typically, you make the program say, "hello world".  I think I got my database to say "Hello World" with the following commands:

a. First, I created a database:
mysql> CREATE DATABASE testdb;
Query OK, 1 row affected (0.00 sec)
b. I confirmed that my database was created by showing them:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
c. I then told mysql to use the database I just created.
mysql> use testdb;
Database changed
d. I created a table.
mysql> create table phrase_table ( 
-> words char(25)
-> );
Query OK, 0 rows affected (0.02 sec)
e. I added one row. It has one column called words and the phrase "Hello World".
mysql> insert into phrase_table (words) values("Hello World");
Query OK, 1 row affected (0.00 sec)
f. I finally selected all rows from my table to get the program to say "Hello World".
mysql> select * from phrase_table;
+-------------+
| words |
+-------------+
| Hello World |
+-------------+
1 row in set (0.00 sec)
e. Done. I got the basic operations to work. This link was pretty helpful. http://www.mysqltutorial.org/basic-mysql-tutorial.aspx

Wednesday, June 5, 2013

Jury duty notes

The day before jury duty.
Tomorrow I have jury duty, and I am looking forward to it.

Last time I served, I made it as far as walking into a court room.  I never had to answer any questions from the judge or a lawyer.  So basically, I just sat around, read and waited.  Needless to say, I loved it.  It was like retirement.

This time, I plan to take a book, a computer, a tablet and my phone.  This should give me enough things to read as I wait around.

Day 1 of jury duty.
I arrived a bit before 9 am.  I went through security, got to the floor I have been assigned to, and waited until the doors were opened.

When we were allowed in, we found a seat, watched a video, filled out some forms and waited again.  At first, I was a bit disappointed that I didn't get a seat near a power outlet.  But I soon found a computer room where I could sit and plug in.  I would think that a spot at one of the desks would be in higher demand, but there were a few remaining spots.

Around 10:15 am, we were told that a judge wanted to see everyone at 2 pm in another building.  So we were free until then.  If we were told this the day before, I would have gone to work for half a day.

After lunch, I bought soup dumplings and ate in the park, I went to the other jury waiting room and waited.  Around 2:30 pm, we were all called to the court, where the judge told us that this trial could last over a month.  The judge asked for volunteers who could serve.  A few people volunteered, but the judge was looking for more.  She then asked a few people why they couldn't serve and she said some were ok and some were bad excuses.  After a few rounds, I eventually volunteered.

I definitely did not want to spend weeks coming to this court house.  I did not want the projects I was working on at work.  There was no good reason for me to excuse myself, but there were a lot of reasons for me to serve. Every citizen should be ready to serve their city/country if called upon.  I also thought to myself, if I postpone now, there is no guarantee that I will have more time in the future or get a shorter case later on.  My desire to not procrastinate and my civic duty led me to volunteer for a trial I had no desire to participate in.

After about 60 volunteers arose, the remaining jurors were sent out of the courtroom.  The judge made some remarks, and then names were called out and chosen to sit in the jury box or in a specific seat in the audience.  My name was not called out.  Each of the jurors who had their name called out answered a list of questions like, "where did they live", "what do they do", "do they know any policeman", etc ... After this line of questioning, all jurors were told to go home and report back to the court room the next day at 9:45 am.

Day 2 of jury duty.
I went to the court house and waited for the judge to call in all of the jurors.  This time, the lawyers did most of the talking and each set asked a bunch of questions.  Some were directed to the whole set of jurors, like "Does anyone have any issue with saying someone is not guilty if there isn't sufficient evidence" and some were asked direct questions like "Mr X, will you be able to judge impartially the merits of the case based only on the evidence presented in the court room?"

After a few hours, all jurors were sent out of the courtroom.  After about half an hour, the jurors who had their names called earlier (30 or so of them), were called back into the courtroom.  After a few minutes, several of them walked out.  Then, for all of the rest of us, we were told to go back to the jury waiting room -- we weren't going to sit on this trial.

Back in the jury waiting room, we were told to return in an hour, after lunch.  After lunch (this time I ate Mapo Tofu in the park) we waited for a bit and were then eventually released with papers saying that we served for two days.

Is circumstantial evidence enough?
One line of questioning by the defense to the prospective jurors made me think that I might not be able to serve.  The defense said that the evidence in this case was all circumstantial.  He asked if we could render a verdict using just circumstantial evidence.  The example he gave goes as follows:

If you pick up your mail (in your apartment building) today, and then return tomorrow and find mail there again, then it is reasonable to conclude that the mailman visited your apartment building. 

After a moment of thought, I thought of three ways mail could be in your mailbox without the mailman visiting.
  1. When I picked up the mail, I left a letter behind.
  2. A neighbor incorrectly got a letter addressed to me.  The neighbor put the letter into my mailbox or asked the doorman to put it into my mailbox.  
  3. The doorman had only sorted some of the mail when I picked up the mail, and he finished putting the mail into the boxes after I made my first pick up. 
If asked, I don't think I could convict someone of a crime if all evidence was circumstantial.  Maybe it was a bad example, or I was thinking about it incorrectly.

Conclusions
My jury experience was a little bit better than the previous time.  With a power outlet, wifi, computer and a phone, I can always find something to read or play around with.  In the future, I hope the jury duty experience improves even more such that we don't have to physically go to the court house unless we are actually needed.

Tuesday, June 4, 2013

Updating Google Drive Files from an Android App

I want to save data generated by my Android App as a file on Google Drive.

Setting up the environment for the first time
First, I needed the google play services library, which I setup using this guide.  I used the "Android SDK Manager" from Eclipse to download the SDK.  This took a while to complete, because installation of one item required an upgrade or installation of a few other dependent libraries and tools.  In all, it took me about an hour.

I then followed this guide to update my Android project to work with the Google Play Services and Drive API.  At this point, I should have been able to:
  • Connect your app to Google Drive.
  • Ask you which account you'd like to use.
  • Allow you to save a picture that you take to Google Drive.
Of course, things didn't work right out of the box.  Here are the issues I encountered.
  • My app was crashing with a message about "No Activity found to handle Intent { act=com.google.android.gms.common.account.CHOOSE_ACCOUNT (has extras) }".  As suggested by a stack overflow question, I tried running my app on a real phone (instead of with an emulator) and it worked without crashing.
  • When I tried to save a file to Google drive I got a 403 error with a meesage about "Access Not Configured".  I realized I set up a client id using the production version of my keystore.  I had to use the development version from eclipse with:
    keytool -exportcert -alias androiddebugkey -keystore .android/debug.keystore -list -v
    where the password was 'android'.
My business logic
For my app, I'd like to.
  1. Create a new csv (spreadsheet) file on Google Drive.
  2. Check if a previously saved file from my app exists on Google Drive, and read it.
  3. If a file exists, update the existing csv file with updated data.
1. Creating a new Google Drive Spreadsheet file.
After creating a comma separated file, I saved it to Google Drive with the function listed below.  Importantly, you have to call setConvert(true) in order to allow Google Drive to update the file.

private String m_filename = "someFile";
private void saveFileToDrive() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
// File's metadata.
File body = new File();
body.setTitle(m_filename);
body.setDescription("Description for "+m_filename);
body.setMimeType("text/csv");

// File's content
String filePath = getApplicationContext().getFilesDir() +
java.io.File.separator +
m_filename;
java.io.File fileContent = new java.io.File(filePath);
FileContent mediaContent = new FileContent("test/csv",
fileContent);

// Insert and convert to spreadsheet
Insert request = m_service.files().insert(body, mediaContent);
request.setConvert( true );
File file = request.execute();
if (file != null) {
Log.i("MyTag","saveFileToDrive file Id:"+file.getId());
}
} catch (UserRecoverableAuthIOException e) {
startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
} catch (GoogleJsonResponseException e) {
GoogleJsonError error = e.getDetails();

Log.e("MyTag","Error code: " + error.getCode());
Log.e("MyTag","Error message: " + error.getMessage());
} catch (IOException e) {
Log.e("MyTag","saveFileToDrive failed");
e.printStackTrace();
}
}});
t.start();
}

Monday, June 3, 2013

2012-2013 NBA season

We are about one week from the end of the NBA season.

Even though I am a huge NBA fan, I am glad that the season is almost over.  Being an NBA fan is time-consuming.  I read about the NBA (Zach Lowe has the best stuff these days), listen to podcasts (the best NBA podcast is the Basketball Jones), and of course watch games (which I typically watch recordings of). 

Given the time commitment, I have been toying around with the idea of giving up my fandom.  
While I may never totally give up the NBA, this may be the last season that I follow the game very closely.  Here are some things I will remember from this season.

1. Teamwork (chemistry) seems important.
When the Knicks were playing great, assists were high, scoring was easy, and the game was beautiful.  The Lakers looked lost all season, and it did not seem as if they liked each other.

2. Shaquille O'Neal has no business being on the TNT broadcast team.
His comments are never insightful.  His interactions with Ernie, Kenny and Charles are awkward.  He mumbles.  He replaced the great Chris Webber, whose analysis was incredible.  Please fire Shaq.  At least make him a sideline reporter.

3. The NBA serves many masters.  In game 6 of the Heat-Pacers Eastern Conference finals, Chris "Birdman" Andersen was suspended for shoving Tyler Hansbrough.  In the pre-game highlights for game 7, the shove was shown as one of the highlights of the series.  Why is a punishable offense part of the highlights?

4. Everyone in the NBA is a remarkable athlete.  I tend to find the ones with the greatest physical advantage to be boring.  This year, my favorite players to watch were Stephen Curry, Jason Kidd, and Manu Ginobli.  

Sunday, June 2, 2013

The Office Ends

For as far back as I can remember, there has always been a television show that has been targeted to my age group.

Over the years, I remember watching Full HouseSaved by the BellBeverly Hills 90210, and Friends.  Each of these shows seemed to be made for me.  Most recently, The Office coincided with me getting my first real office job.  A few weeks ago, the series finale aired, which I watched today.

Here are some notes on how I felt watching the show
  • I felt a strong sense of sad nostalgia.  Unlike school, where there is a new beginning after graduation, the end of office life seems depressing.  Most of my youth was spent studying for a career, and when that career is over, I don't know what I will do or how I will feel.  
  • I wonder what show will capture the mood of my next stages in life.  Maybe (if I have kids) it will be Modern Family.  I wonder if shows will continue to target my age group anymore.  For example, MTV seems to target the teen audience.  
  • I always thought Michael was the star of the show, and then maybe Jim or Dwight.  But now I think it was Pam.  She had the most to learn, the most to overcome and the greatest lessons to impart.