Monday, November 29, 2010

Youtube ETA - Chrome extension

If you have ever tried to watch a youtube video on a slow network connection, you will know the frustration I often face. Wondering when that red progress bar will reach its end. Thanks to a chrome extension like Stop Autoplay, I can let the youtube video open in background tab and let it buffer as I browse other webpages. But still I have to go back to the youtube video's tab to find out if the video is downloaded, can I start watching it?

So I always wished someone had written an extension which will do something about this problem. After going through 3-4 pages of search results on chrome extension website with the query 'Youtube', I figured no such extension exists. This weekend, the itch became unbearable. So I peeked into the Stop Autoplay's short code and with some searching found out there exists a Javascript API to control the youtube player's behavior. It provided the API calls that were sufficient for me to calculate the speed (in bytes-per-sec) at which youtube video is downloading. Combine that with total size and total duration of the video and I had the solution I was looking for.

So I decided to write an extension out of it. You can get it from here

It does following things:
  1. Pauses the video at the start, i.e. disables the autoplay
  2. It calculates an estimated time it would take to download the video completely. Shows it in a red box in the top left corner.
  3. It also prepends a short version of this estimated time to the title of page. So even if you are browsing in other tabs or windows, you can tell how much longer it is going to take, without visiting the youtube page.
  4. There is an instant of time, when the video is not yet downloaded completely, but if you start watching the video after that point, you can be assured that the entire video will be downloaded by the time you reach the end. That way it is guaranteed that you won't have any interruption while watching the video. The extension smartly calculates that instant and informs you by turning the red box into orange. It also adds '*' to the timestamp in title after this point.
Give it a shot. The extension won't yet work with HTML5 player, I will fix that soon though.

Monday, November 15, 2010

Why secure airports when it's planes that fly?

With all the debate going over TSA's naked scanners and intimate pat-downs, I think one simple question is being totally ignored.

Why secure the entire airport when it's only the planes that fly in the sky. The reason we need added security for air travel is their unique vulnerability as compared to other forms of transport. An accident or attack in mid-air can lead to nearly 100% fatality. Also planes can be used as weapons in even more significant disasters as demonstrated by 9/11. So the objective of securing air travel should be to keep the flying objects safe. Anything and anyone that boards the airliner should be thoroughly checked. But why secure the entire airport?

Airport is tens of square miles of area with hundreds of access points. To try to secure this entire area is to make the task at hand enormously difficult than it has to be. There is nothing more special about an airport than is about Grand central railway station. A terrorist group is not going to achieve anything more significant by blasting a bomb at airport gate than he would by blasting it on a railway platform. Consequently, security of airport can be as tight (or loose) as that of a railway station. All the extra vigilance however should be concentrated at the gates where passengers and crew board the airplane - the real vulnerable entity that needs protection.

It is a matter of common sense that smaller the area to protect, more effectively it can be done. Why not apply that to air travel security?

Moreover, securing entire airport varies from country to country. Flights fly to US from all over the world, in multiple hops. Securing the safety of a flight bound to US, then depends on securing the boundaries of all the airports where the flight was boarded. Imagine how behemoth that task is and how easy to breach. Establishing the checks at the doors of the actual plane simplifies that problem by magnitudes.

Friday, October 29, 2010

Mac book red light audio jack problem on Linux

When I upgraded my Macbook (2,1) to Ubunut 10.10 last week, I realized after a while that it wouldn't play any audio through the audio jack. The built-in speakers were working well, but as soon as I plugged in the headphone the built-in speakers would go off (as expected) and the headphone would be quiet too.

Then I got little concerned when I saw the red glow coming out of the audio jack. This macbook is now 4 years old, so I assumed the red light means some malfunction. But after I searched around, I found it was a known issue. The red light wasn't any indicator, but optical audio output. Many mac forums had discussions on this topic. Most of them fixed it by sticking a pin or toothpick into the jack, juggling around a little or shorting some internal probes. They reported that this eventually turns the light off and audio out was switched back to traditional wired output. I tried the same, but no luck. In retrospect, those all posts were with Mac OSX installed. So in their case, the optical audio output was probably turned on in hardware and had no way to turn off in software. Whatever the case, their solution didn't work on my Ubuntu installation.

I figured that, the optical audio output was not turned on in hardware, because when I rebooted the laptop in Mac OSX the red light used to go off and headphones worked. So now it remained to find some software tweak to fix the problem. Eventually I found this thread on ubuntu forums. Following two commands fixed the problem.

# Turns off the optical audio out
amixer set IEC958 off

# Turns on the headphone speakers
amixer set Speaker,1 on

# In case you want to tweak built-in speakers
amixer set Speaker,0 on

If your system is different than mine, it will help to run amixer without any options and see the list of audio channels and their states it prints out.

Hope this trick helps someone.

Ads:

Thursday, October 28, 2010

How to save HTML5 canvas image to Google App Engine

This is a very specific problem and not many would have it. But I had to implement it and came up with a solution that works for me. This is how I did it for 3DTin.

First why it's specific. In a typical case a web app wants to save user submitted images to Google app engine data store. This can be simply done by presenting user with a form and adding an 'input' tag with type 'file'. The submitted image can be extracted in GAE using request.get() and packaged into db.Blob to eventually store into BlobProperty. I am not going to explain this typical case, because it's covered nicely in the GAE's documentation. However, the process is not as straightforward when the image you want to store is not an image file on user's computer, but a dump of HTML5 canvas element in the web app.

An HTML5 canvas element lets you export its content as jpeg or png image with the toDataURL API. This function returns a data URL that contains base64 encoded jpeg/png image. So how do we convert this image data into GAE's db.Blob object?

The solution is to send the base64 encoded data as POST param to GAE app, do some regex matching to extract the exact portion of the data URL that is the encoded image and pass it through the base64 decoder (which is part of standard python library).

Here is client side:


Here is server side code:


Code is also accessible as gist here, in case you can't see the embedded version above.

This code works in 3DTin where a thumbnail of user's canvas is sent to GAE app for storage. It works without problem.

Ads:

Tuesday, October 05, 2010

Silicon Valley and Hi-tech

I grew up with a dream of doing something in the "Hi-tech" industry. Back then I imagined it will be some breakthrough scientific work like inventing a perpetual energy machine or engineering a space elevator... something that will fall under the category of rocket science.

They say Silicon valley "is home to many of the world's largest technology companies". No doubt, any young technologist like me had his eyes set on Silicon Valley. So when I compare the nature of today's so-called "hi-tech" hot companies, namely Facebook, Twitter... I can't help but wonder where is the Science and Technology in them?

This morning I read Sarah Lacy's Techcrunch article "Silicon Valley at a Cross Roads: Entertainment or Science?" and it all made sense.

She put into the words the very question that lingered in my mind.
Will it [Silicon Valley] follow the Web 2.0 path further down the road of media and entertainment or go back to its roots of hardcore science and technology?
According to her the valley made a choice between real hi-tech and Web 2.0 (that would lead to media innovation), back in early 2000s.

But in the early 2000s, the Valley was at a crossroads. Was the future cleantech or Web 2.0? Put another way, was the future starting a new stack or continuing to iterate on top of the mostly-built out one? The cleantech camp was championed by a lot of top Valley names– most famously John Doerr– who saw it as the most important way to change the world and an undeniably huge market that required real innovation. The Web 2.0 camp was championed largely by the PayPal Mafia’s angel investors like Reid Hoffman and Peter Thiel, and a handful of other angels and mentors like Marc Andreessen. Many of them prized the fact that Web companies were the opposite of cleantech: Thanks to decades of technology build out they were cheap and low-tech to start, utterly changing everything about these companies from the size of the exit you needed to have a good return to how quickly you could know if you had something or not.
Ultimately, Web 2.0 won the Valley’s heart and hype....
She then makes a logical guess about future that the valley will continue down "a path where San Francisco becomes the center of Web media, the way New York was the center of news media and LA was the center for entertainment media. These businesses are easier to understand, quicker to evaluate and more likely to produce a series of newsy blog posts"

I have to say, her post brought a moment of clarity to me this morning. You should read the entire article. Few people have the ability to observe a big industry over a long period of time and make sense about where it came from and where it is leading. Sarah Lacy is one of them.

My understanding and my hope is that even though Silicon Valley takes the route of a media industry, their will be "real" hi-tech innovation somewhere in the world. I feel confident about it when I read about Elon Musk's Tesla and SpaceX, Richard Branson's Virgin Galactic, or the Mega Machines episodes on Discovery channel that show behemoth engineering projects in China, Japan, S Korea. I also find promise in the grassroot culture of "Makers" that is taking shape in the form of Maker faire and the new industry of personal manufacturing that is evolving in the form of 3D printing. Hopefully we will build on top of the Web infrastructure that Silicon Valley provides and the true hi-tech innovation will take place in this virtual world and not in a specific physical valley.