mark cerqueira well-rounded nerd

Measuring Android WebView Content Size

Situation: you’re loading content into an Android WebView that’s embedded in another view (i.e. not a fullscreen WebView) and you want to ensure the WebView resizes to the height of the content it contains.

Easy, right? Loaded question: it’s Android so you know the answer is absolutely not. StackOverflow answers provide many ways to potentially do this, but most don’t work. I only found one way – using some Javascript magic – to reliably get the content height.

Changing Progress Bar Spinner Color

Situation: you’ve got a little progress spinner in your Android app.

<ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:indeterminateOnly="true"/>

But it’s grey. You want it to be a different color. Something more exciting. To the Googles!

Like many Android things, there are multiple Stack Overflow posts with all sorts of answers and comments on each one saying “Thanks” and “That doesn’t work for me.” I cut through all that and here is how you do it programmatically and it works across all API levels:

// Source: http://stackoverflow.com/a/36828947
try {
  int color = ContextCompat.getColor(this, R.color.favorite_color);
  myProgressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
} catch (Exception e) {
  // Why try-catch? Because some Xiaomi device out there will probably choke...
}

Now your ProgressBar – that’s actually a spinner and not a bar – be colored!

Ruby DateTime to Objective-C NSDate

Converting a Ruby DateTime to an Objective-C NSDate will lead you on a wonderful journey where you realize the DateTime outputs itself is incompatible with any potential NSDateFormatter you try to use to parse it. The crux of this is because DateTime includes a colon in its timezone offset which you cannot express in a NSDateFormatter.

So what is one to do? One option is to skip the default formatter of DateTime and roll your own:

# See http://stackoverflow.com/a/9132422/265791
my_datetime.strftime('%Y-%m-%d %H:%M:%S')

Then build the corresponding formatter in Objective-C:

[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

With this, you too can avoid the fruitless journey of trying to get NSDateFormatter to comprehend DateTime’s default format. Happy interoperating with languages!

Concert Review: Final Symphony, San Francisco, 7/28/16

It’s quite a sight to behold seeing Davies Symphony Hall packed (2,743 seats!) for a music concert centered around video game music. But when you are talking about one of the most iconic game series – Final Fantasy – with some of the most beloved soundtracks, it all kind of makes sense. Attending Final Symphony: Music from Final Fantasy VI, VII, and X, I expected to hear a beautiful homage to some of the most popular games in the series. While the San Francisco Symphony put on an absolutely spectacular show, I left the concert feeling very underwhelmed.

"Music from" should be taken very loosely.

My main problem with Final Symphony is all the pieces were over-composed to the point that they lost their identity as being a part of Final Fantasy. The concert was described as having “Music from Final Fantasy” but a more accurate description would be “Symphonies with riffs from Final Fantasy here and there.”

I went in expecting something like Distant Worlds (i.e. Final Fantasy pieces adapted for orchestra) with a pizzazz to turn them into symphonies. But what I got was fragments of soundtracks, build-ups to “the really good part of a song” that would abandon ship right before climaxing, and dissonance used far too liberally. Ultimately, it just didn’t feel like Final Fantasy to me. It didn’t remind me of all the wonderful memories I had playing and falling in love with the games.

I expected and wanted the composers to open up the original MIDI files, spruce them up a bit for live performance, hit Print, and put that in front of a world-class orchestra. What I got was something that felt really “try hard” and ended up really cheapening the experience for me. Expectations… They can really backfire sometimes!

Hello, Euler!

Last Thursday I was browsing a coworker’s repositories on GitHub and noticed one inconspicuously called euler. And that’s how I discovered Project Euler! The website describes the project as “a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve.”

I wouldn’t describe myself as a math aficionado, but have had a blast working my way through the problems. So far, I have already picked up a lot about prime numbers and touched the ceilings of number-based data structures many times! With over 500 problems (and a new one every week), I’ll be able to keep myself occupied for a while.

Like my coworker I now too have an euler repository that you can browse.