Your Personal 24-hour news

We’re all familiar with the concept of the 24-hour news cycle that has become to characterize most of America’s news media outlets. Today I want to mention the idea of a personal 24-hour news cycle – something I’ve noticed for a while but recently gave some more thoughts about.

As with many people nowadays, I rely on Facebook News Feed and Twitter timeline to read and receive news, engage in discussions or simply stay updated with the whereabouts of people I’ve come to acquainted through the years and over 2 continents. A testament to this was how I personally chose to stay updated with the Boston bombings two weeks ago purely through these 2 media. I rely on the people I follow on Twitter (a list of semi-carefully curated sources) for noteworthy reports and retweets. I didn’t even look at trending hashtags’s feeds – those were too overcrowded and less reliable sources of information. I looked on Facebook for more reactions from the people closer to me, whom I knew personally.

In a (long ago predicted) way, my social media has slowly replaced newspaper and TV for me as a source of information. Not just for daily news and professional insights, but also for breaking news and latest reports.

All of this is just a context for the point I’m trying to make. Out of the 1100 plus friends I have on Facebook, half reside in Asia (more specifically, South East Asia) while the rest are dotted over the rest of the world, with a concentration in the US.

If my Facebook News Feed activities were to be plotted on a heat map, I’m sure the most red area would be around 7-11pm EST, the time when a lot of my Facebook connections (a majority of whom are in my age range) update their Facebook statuses, share interesting news or just be out and about on Facebook and Twitter socializing and commenting on other people. Things would then start to die down around midnight, and around 2am I wouldn’t get many updates.

This has sort of formed my nightly habits – as a creature easily distracted by anything but my homework, I spend my evening catching up on the daily news on Facebook and only start on my work as the news cycle slows down. I suspect this is (at least partially) true for many of my college friends too, judging from the sheer number of people online on Facebook chat. (It would be an interesting study if I keep track of this number by the hour over time.)

Interestingly, when I wake up in the morning and reach for my phone expecting perhaps a handful updates through the wee hours of the night, I instead see a slew of updates coming in from Asia. In a way, this is not all too surprising – people who work on international financial markets would be very familiar with this overlapping in time zones. But on a personal level, it is exciting for me to realize that as I wrap up my day and settle down for a night’s rest, many other people I know (more than half) are just starting out on their new day. When a video or an article goes viral and originates from the Western Hemisphere (like the Boston bombings), I will see updates from this side of the world first, then later another wave of updates (with seemingly equal sense of urgency) from Asia. Similarly, when New Zealand decided to pass the law legalizing gay marriage and broke out in a song, I first heard about it in the morning from my Asia-dwelling friends, only to be reminded of it later that evening by my friends here.

The same patterns could be observed on Twitter too, but to a lesser extent as I follow fewer people in Asia than those in the US.

Another interesting thing to note is that I see fewer updates from Vietnam than Singapore. There could be many factors at play here, and one of them could be the fact that access to Facebook is more restricted in Vietnam, so many people do not use it as their primary online social media platform as in Singapore or the US.

This observation isn’t ground-breaking or extremely interesting, but I suspect that it is something a lot of people who have online social connections spread across the globe (like college students studying abroad as an example) are and will experience. Our world has always been a very diverse and happening place – now all of that information is brought more to our forefront with better connectivity and better tools to stay connected. Spending a semester in far-flung places in Africa or treading over Europe no longer means dropping off the radar. It just means that we will hear from them at a different time in the day, and vice versa.

Using AppleScript and USB Overdrive to rewire my external keyboard

So I’ve recently made an investment in the Kinesis Freestyle 2 for Mac – an amazing keyboard that is supposed to be ergonomic and very friendly for your hands to type.

After playing it for a while, I really like it except for one thing – when I press the prev, play/pause and next buttons, it will always bring up iTunes even if Spotify is open. This is very annoying as I’ve said goodbye to iTunes long time ago and have migrated over to Spotify. It is also different from the default behavior of the Mac’s native keyboard. If I press these buttons on the default keyboard while Spotify is open, it will just play Spotify. Same goes for QuickTime Player.

This annoys me enough that I spent the past 2 hours looking into a solution. I’ve found one that is sort of a workaround that works well for me for now, so I thought I should leave it here.

First, I use USB Overdrive to manage the behavior of external mice and keyboards. It is just an incredible piece of software in terms of the amount of control it gives you.

It is almost perfect for what I need to do, except that for Media keys, it only allows mapping to iTunes commands.

To gives Spotify any sort of priority, I have to use the ‘Execute AppleScript’ feature. Even for someone who’s relatively good at programming, this was scary to me at first. The thought of programmatically alter my Mac was a scary thought, and a downhill move I thought. That is until I learned how friendly AppleScript is. Here’s a little code I wrote to get the play/pause button do what I want:

# prioritize Spotify first
						if application "Spotify" is running then
						    tell application "Spotify" to playpause
						
						# if Spotify isn't open, QuickTime Player is second on the list
						else if application "QuickTime Player" is running then
						    tell application "QuickTime Player"
						        tell document 1 to if exists then
						            if playing then
						                pause
						            else
						                play
						            end if
						        end if
						    end tell
						
						# only play iTunes when nothing else is open
						else if application "iTunes" is running then
						    tell application "iTunes" to playpause
						
						# if no media app is open, start Spotify and play some tunes!
						else
						    tell application "Spotify"
						        activate
						        delay 2 -- I added this in because having play right after activate doesn't quite work. It turns out the delay gives it a nice fade in effect
						        play
						    end tell
						end if
						

This is an opinionated solution to what to do. It is also limited to currently 3 apps right now, so it’s probably not as versatile as the built-in keys. However, for now, these are the 3 apps I use the most. If you use “VLC”, then just replace “QuickTime Player” with that, or put it before QuickTime.

Here are another example of what I did with my previous button. The next button is pretty much the same.

if application "Spotify" is running then
						    tell application "Spotify" to previous track
						
						else if application "QuickTime Player" is running then
						    tell application "QuickTime Player"
						        tell document 1 to if exists then
						            step backward
						        end if
						    end tell
						else if application "iTunes" is running then
						    tell application "iTunes" to previous track
						end if
						

I hope this is helpful to someone out there who’s looking to get more power of their keyboard and mouse mappings. As you can see, there is a limitless number of things you can do with this.

One more note, to start writing AppleScript, a good place to start is open the ‘AppleScript Editor’ on your Mac. Once you’re there, you can open the Application Dictionary through the shortcut cmd + shift + O or “File -> Open Dictionary”. Have fun!

When to use INDEX in MySQL

A great article explain when and how to use INDEX in MySQL. Want to leave it here so I could easily find it later. View article.

RESTful WordPress

WordPress is an incredibly powerful and user-friendly web platform. It is loved by both developers and users alike. WordPress’s polished wp-admin and Dashboard are probably one of the biggest reasons WordPress is chosen by many people as their go-to CMS. As a developer, I pick WordPress over other CMSes whenever I feel my client need a friendly CMS to manage their rich content in a smart and usable way, which turns out to be quite often.

In the State of the Word speech in 2012, Matt Mullenweg outlined a vision for WordPress with an even bigger emphasis on making wp-admin more user-friendly. I think this is a great direction to follow, given how User Experience has become the focal point in web development work in the past couple of years. In the same talk, Matt also shared his vision for WordPress being used more for web applications. Now this really got me off my seat.

Imagine a day when you are able to query every single bit of information that is on your WordPress site, from each Custom Post Type (CPT) and its custom meta fields to every user meta data. This will transform WordPress into a true web application powerhouse, with RESTful APIs on the back end and a stellar front end interface. The introduction of the REST API in JetPack 1.9 is a big step in that direction. However, there’s still much to be done.

A few months ago, I started working on a mobile application with a few friends. We wanted to make a nice tool for students to create meaningful interactions through a small on-campus social network. During the architectural design process, being a true WordPress developer, I urged the group to use WordPress as our backend. I was very optimistic that we could turn WordPress into a RESTful API while leveraging on the current familiar theme templates to rapidly build and deploy a web app version. We could then focus more of our time on designing and making the iOS app more user-friendly. Unfortunately, with a 3 month deadline in mind, we decided against using WordPress because the Jetpack REST API only supports regular post types and not CPTs (we also decided not to build an independent REST API because that would take even longer). This was a bummer because with a secure and mature user management system and a tested framework for interacting with the database in place, coupled with many plugins for optimization, WordPress would be the ideal candidate for small teams like ours to deploy mobile and web applications that rely on a solid backend in a relatively short period of time.

This experience led me to believe that there is a huge potential for making the WordPress Core RESTful. With work already done in Jetpack, I think that we’re already more than half way to achieving this goal. I don’t think the rest of the way is easy (or otherwise it would already be done), especially in trying to extend Core while maintaining it backward compatible. Nonetheless, being able to achieve this will put WordPress to the front and center of a developer’s toolkit in building awesome applications.

There are many benefits to this.

Despite these potentials, a quick search for REST API plugins from the WordPress plugin repository revealed only a couple of plugins which have not been maintained for more than 2 years (highly rated plugins nonetheless). I am not certain what the reason for that would be, but there have been definitely a lot of changes in the WordPress Core for the last 2 years. My dream right now is to be able to spend a few months focusing on building a more fully featured REST API for WordPress.

It would not be easy to do that all by myself, but if I were in a team of really talented and experienced developers who know WordPress in and out,the process would be a lot more fun and productive. Another important thing is knowing how to test the features and make sure it is scalable. These are the things the good people at Automattic do really well. But more than anything else, working on this would be a great learning experience.