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.