Posts by Toby

My Work Mail Filter

My company recently switched to Google Apps. One of the implications of this is that I can use Gmail's mail filters. Since - like many company - I get a daily plethora of list emails, I thought I'd create a simple rule to filter them down to only the ones that require my attention.

Attempt #1:
Matches: -{Toby}
Do this: Skip Inbox

This rule says that if the email does not have my name in it anywhere, then skip the Inbox(like Google Search, "-" is the NOT operator). This worked fairly well, but I found that there were some false positives after a week or so of using it. So it needed some tuning up.

Attempt #2:
Matches: to:(-my@company.email) -{Toby Birthday}
Do this: Skip Inbox

I found that once in a while, there'd be a message addressed to me directly, but would not have my name in the message. I fixed this by putting -my@company.email in the To field of the filter(replace my@company.email with your own email). So, this filter will only apply to mail not addressed directly to me - the ones sent to mailing lists, basically. Also, I'd like to be notified of people's birthday, so I added the word Birthday to the doesn't-have list.

Attempt #3:
Whenever I request support, I always first get a message first that says: Thank you for your support request. This is pretty uninformative, so I don't need to be alerted to them. So I added the rule:
Matches: from:(our@support.email) Thank you for your support request.
Do this: Skip Inbox


That's what I've got so far. This post will be updated as I further fine tune my mail filters.
Posted by Toby 1 day ago about gmail, mailfilters and tech (0 comments)

60s Music from Lost

My latest obsession: 60's music from Lost. In particular, Desmond's song from the very beginning of the first episode of Season 2: Make Your Own Kind of Music by Cass Elliot; and Juliet's intro on the first episode of the 3rd season: Downtown by Petula Clark. I found these songs by Googling the lyrics. Never heard of these folks before. I bought Cass Elliot's Mama's Big Ones and Petula Clark's Downtown, and have been listening for a few weeks, and am enjoying them. My favorite song is Cass Elliot's Ain't Nobody Else Like You. Cass is a big woman who has a sweet and somewhat childish voice which I like, I also like the music style which has some "hip" brass accompaniment. Petula Clark's voice somewhat resembles Julie Andrews, Don't Sleep In The Subway and I Couldn't Live Without Your Love on the album are quite catchy.
Posted by Toby 4 days ago about music (0 comments)

Javascript sort() Gotcha

Javascript pop quiz!

What is the result of this code?
var arr = [12, 3, 24]
arr.sort()
arr
You: [3, 12, 24]
Me: Wrong, You get an F! The correct answer is: [12, 24, 3].
You: WTF?
Me: Array.prototype.sort() uses lexical ordering by default. That is to say, it converts everything to string before comparing them. Thus, '12' comes before '24' comes before '3'.
You: So how do you make it sort numbers?
Me: You pass it a comparator function as an argument:
arr.sort(function(a, b){
  return a - b
})
You: That makes sense, I guess. But still...that is pretty messed up.


Posted by Toby 5 days ago about javascript and programming (0 comments)

Memoize for Javascript

I wrote a memoize function for Javascript today to cache file timestamps. I thought I would share it with the world. Here is the code:
function memoize(f){
    var cache = {}
    return function(){
        var keys = []
        for (var i = 0; i < arguments.length; i++){
            keys.push(typeof(arguments[i]) + ':' + String(arguments[i]))
        }
        var key = keys.join('/')
        if (key in cache){
            return cache[key]   
        }else{
            var val = f.apply(null, arguments)
            cache[key] = val
            return val
        }
    }
}
Let's say you have a function:
function f(x, y){
  return x + y * 2
}
If you memoize it:
f = memoize(f)
The first time you call f with arguments (3, 4):
f(3, 4) => 11
It will compute it, but the second time:
f(3, 4) => 11
It will merely return the cached value computed from the last time.

Note about the implementation: the equality metric used by this memoize function is: 2 objects are equal iff they are of the same type:
typeof(one) == typeof(other)
and, they have the same string represention:
String(one) == String(other)
That is it. Enjoy!
Posted by Toby 5 days ago about javascript and programming (0 comments)

Say No to Syncing

If you are a podcast listener like me, you have probably accustomed yourself to connecting your iPod to your computer everyday to get your new podcast episodes. This is a big hassle, but in the age of the iPod, this made a lot of sense. You sync your podcasts, just like you would sync your music collection, because the only way to get your media onto the iPod was through the USB cable. Apple also did a great job of integrating the podcast experience into iTunes and the iPod, their podcast listening experience was second to none.

Enter the iPhone. And later the iPod Touch as well as other smartphones which came into the market to compete with the iPhone. These new devices are internet enabled, and so they possessed the power to download the new podcast episodes by themselves, and thus the daily chore of syncing podcasts can be eliminated. With the RSS Player app you can catch new podcast episodes for your favorite podcasts directly on the device - no need to connect to a computer or go through iTunes at all. On the Android platform, there is Listen and a handful of other apps which do the same thing, and so G1, Droid, and other Android phone users can enjoy this convenience as well. But my guess is that most people are still syncing podcasts. Why is that? You ask.

Apple rejected what came to be the RSS Player app at first. They saw it as stepping on their own turf. Not long after that, they allowed users to download specific podcast episodes directly from their device, but still no automatic updates. Why they didn't add that feature is very puzzling to me. To me, Apple is still hanging on their dock-n-USB paradigm, which - in my opinion - will go out of fashion very soon. Case and point: the iPad. Why would the iPad need a dock connector? It's freakin' ridiculous. You may say: they want you to use iTunes. To that I say: you can use iTunes on the iPad. You may say: it needs to sync with the music collection. Then I say: you should be able to sync over wi-fi! I also predict - and I am not the only one by far - that on-demand music streaming is going to obviate the need for the syncing of even your music collection in probably 2-3 years. Who knows, Apple might even be the one pioneering that movement, given that they've bought Lala

And so, to smartphone or iPod Touch users who are still syncing podcasts, I'd say this:

Stop pushing the button.
The Button
Posted by Toby 25 days ago about apple, podcasts and tech (0 comments)

My Thoughts on the iPad

iPad
I've followed engadget's live blog, seen the keynote video, listened to Tom and Molly talk about it, even read others' opinions on engadgetgdgt and twitter, etc etc. I guess you could say I am pretty excited. 

The tech savy(engadget, gdgt, BOL, etc) are in general underwhelmed or disappointed. Below are some of the complaints I have heard:
  • No Webcam or microphone - which pretty much rules out using Skype on it, which would have been a great killer app at this form factor. I think they will add these to the iPad in the future. Update: actually, there IS a built-in microphone, so at least you can make audio calls with Skype.
  • Still No Flash Support - you cannot seriously claim it has the best web browsing experience when it doesn't support Flash! Apple has not allowed Flash to run on the iPhone all this time. Now that they are doing the  same with the iPad - which with it's larger screen you would think would be much better suited to run Flash apps, and add to it the fact that Flash has never ran great on Macs, it's becoming obvious that this is political. Apple wants to fight a format war with Adobe. Why would you need flash when you can buy great apps from the app store and buy TV shows and movies from iTunes? On the other hand, I can also see the concern that almost all of the flash apps out there(possibly with the exception of Flash ads) just aren't designed for the touch screen, and having users run them on the iPhone or the iPad degrades the user experience and therefore could hurt the products' reputation. Apple's PR, however, is going with: "it could rapidly drain battery life", which I think is probably in reality 3rd or 4th down on their list of concerns.
  • No multiple tasks/apps/windows - this is a pretty big one: given the iPad's screen real estate, it seems artificially limiting to not allow multiple apps to be running in separate windows. I believe the iPad will eventually have this feature. How the UI will turn out will be interesting to see. 
  • The App Store Sucks - Apple prevents certain types of applications from entering its App Store. One example is programming language interpreters; another is any app that Apple views as overstepping their core apps' boundaries. Given that the iPad is even more of a computer than the iPhone, these limitations may become even more glaring.
  • I just don't see the need - "I already have a laptop and a smartphone, there just isn't any more room for yet another device!" I think that at the moment the iPad is more exciting for developers than consumers, but that will change.

All the negatives are well and good, but I overlook all of them, because, from my point of view, the iPad - and what it will lead to - is much bigger. All of the tablet computers I've seen in stores in the past - HP's, Fujitsu's, etc: they all suck. These computer manufacturers created tablet computers but installed on them an Operating System which is design from the ground up for use with a mouse and a keyboard. They figured: "A tablet computer has a stylus. We can use it as a pointing device in the same way that a mouse is a pointing device. We just hook up the stylus driver to control the pointer, and boom! We got ourselves a tablet Operating System! Brilliant!" This is understandable, because it is the nature of software engineers to want to build solutions that solve as many problems as possible - and Windows is a very very big solution indeed. However, this tendency also causes brilliant people to routinely produce crap. The tablet form factor is more versatile than the mouse, and can be much more natural to use from a UI standpoint, but dumbing it down and retrofitting it to an inferior UI paradigm caused it to be marginal. Yes, you could use a tablet to draw, sign documents, take notes, etc, but when it came to interacting with the UI elements, it was usually very kludgy. 

iPad is the first tablet I've seen that comes close to realizing the potential of the tablet form factor. Why? It's all about the software, stupid! The software that come with the iPad were designed and written  specifically for the large multi-touch screen device. This is to take nothing away from the amazing hardware. Multi-touch was ground breaking when it first surfaced. When the iPad comes to market, it will be the single best showcase of multi-touch technology. But, the software is what brings it all together, and you can tell Apple put a lot of time and effort into the software. Okay, enough of my rambling. What am I really trying to say? 

iPad marks a historical step towards our liberation from mouse pointers and a paradigm shift in computer technology.

I hereby reiterate my prediction that in 5 to 10 years, mice will be on the way to extinction.
Posted by Toby about 1 month ago about apple, fourcast, gadgets, ipad, tablet and tech (0 comments)

Simulating a Tablet Using the Touchpad

Chinese Handwriting
I came across OS X's Chinese Trackpad Handwriting input method the other day, and was really impressed. Once you activate the handwriting mode(hotkey: Ctrl-Shift-Space), the mouse pointer disappears, and you can use write your chinese character on your trackpad using your finger. The UI looks like this:

Handwriting UI

What's interesting to me is the buttons on the left and right of the character recognition area. It took me a while to figure out how to use them at first, but after some experimentation, I figured it out: basically, the pretty gray box corresponds to your trackpad, and so to press a button on the upper left corner, you would tap the area in the upper left corner of your trackpad, and so on and so forth. It is very intuitive really. I would even say brilliant. Essentially, the trackpad has been made to work just like the Vistablet or any of the tablet accessories you can get from the Apple store these days. 

Which got me thinking, how far can we take this? Can we use this to say...draw? A couple of google searches later, I discovered the Inklet from Ten One Design. The Inklet is an application, which is primarily used with a stylus you can buy from the same company called the Pogo Sketch. 

Pogo Sketch Stylus

The Pogo Sketch is a pressure sensitive stylus that works with the Apple trackpads as well as the iphone and ipod touch. With Inklet and the Pogo Sketch together, you basically have the features of Vistablet. Here's their demo using Photoshop:

Embedded Content


Brilliant, brilliant stuff. Another why-didn't-I-think-of-that moment for me. The lesson from all of this is that, at least for the new Macs, you can do a lot more with the trackpad than you thought(or at least I thought). For some types of applications, it may make sense to completely do away with the mouse pointer and use a tablet-style interface instead, and we can do this NOW! (Yes, now - three days before the imminent release of the Apple Tablet). Tablet doubters, just you wait, tablets will be the way of the future. In 5-10 years(oh this could be another Fourcast prediction), the mice could be heading towards extinction. Just you wait.
Posted by Toby about 1 month ago about fourcast, gadgets, tablet, tech and touchpad (0 comments)

Working From the Future

This is my second FourCast style prediction. It is the "long term" prediction.

In the year 2110, 80%> of the earth's workers will work remotely.  Even physical tasks like surgery, construction, or mechanical repair: you can do by logging into a robot remotely and controlling in via a VR-type interface. Moreover, many of the reasons for needing to get out of the house have been eliminated, among them:
  • groceries - groceries will be delivered to your fridge. You will order them online - usually on a display on your fridge, or just by talking to it and the groceries will be delivered within a couple of hours.
  • social activities - 80% > of social activities will be done via virtual worlds like Second-Life. So you can connect with all of your friends no matter where they are or where you are.

The implications of this are:
  • Because people are not tied to the location where they work, they can be traveling on a day-to-day basis and still not miss a day of work: tourism flourishes.
  • By the same logic, people can live where they want to live, not where they have to live, therefore, they move their residence from place to place in a much higher frequency. People who love traveling live in RVs permanently.
  • The real estate market will sky rocket, because there will be a large influx of potential buyers from all over the world.
  • Most jobs will be short-term contracts because for whom you work is no longer tied to where you live, and so there's less of a need for stability and also you have a much larger pool of openings to choose from.
  • There will be one global currency to facilitate workers and employers in different countries to do business with one another.
  • There will only be 2 or 3 languages in common use throughout the world, and the majority of the people know at least 2 of them.
  • 90% of dating will happen virtually. Meeting IRL will be considered a major step in a relationship.
Posted by Toby 2 months ago about fourcast and tech (0 comments)

The Future of TV

I've been enjoying Tom and Scott's FourCast Podcast and decided that I would make my own predictions in the FourCast style. This post is my first prediction and will be the short term prediction. Here goes:

In the year 2020, TV will work completely wirelessly. Devices like Apple TV, Roku, Boxee Box, etc. will be merged into the TV itself. HDMI, DVI, Component inputs are only optional features and will be seen as outdated or niche. Apple Inc. will have the best selling TV which will have not a single hole or button on it. TV programming will be IP based and a la carte. TV shows will be delivered via a framework/standard like RSS but which allows for streaming, ad placement as well as paid shows in the form of a la carte or subscription. TV networks have a much smaller role and their main purpose will be to getting advertisers for shows. Google/YouTube will become the biggest TV network and will use ad-sense to place ads for shows anyone can make. Other competing networks will crop up and some of the old TV networks will move to this model but will not over take YouTube. TV channels will become a concept distinct from TV networks, and will be collections of shows/videos created by the TV networks or individual users(kinda like playlists). 
Posted by Toby 2 months ago about fourcast and tech (0 comments)

Flex Compiler Slower on 64bit Mode Java on Snow Leopard

Ever since I upgraded to Snow Leopard, the my flex apps seemed to compile slower. Today, I finally had enough and took a look into this problem. First, there was the weirdness with Java on Mac in that even though the compiler is a command line application(non-GUI), it creates a application menu. I cracked open the mxmlc script, and added:
-Djava.awt.headless=true
to VMARGS. This solved that issue, but didn't make it compile much faster.
Then, after a bit of fiddling around, it turned out that putting java into 32bit mode:
-d32
fixed the problem! The difference was significant. I tested this in 2 different apps. For App 1, it took 45 seconds to compile on 64bit mode, only 9 seconds on 32bit mode. For App 2, it took 30 seconds on 64bit mode, only 7 seconds on 32bit mode. So, mxmlc performs 4-5 times slower on 64bit java than 32bit, java. Why would this be the case, I have no idea. If anyone has an idea, I'd love to be enlightened. If you come across this problem, the fix is to open up mxmlc, and edit the line that says:
VMARGS="-Xmx1024m -Dsun.io.useCanonCaches=false"
and change it to:
VMARGS="-Xmx1024m -Dsun.io.useCanonCaches=false -Djava.awt.headless=true -d32"
I hope that helps someone.
Posted by Toby 3 months ago about flex and programming (0 comments)

Taking an Average in CouchDB

More fun with CouchDB, this time taking an average of something:
// map
function(doc){
    emit(null, doc.info.size) // in place of doc.info.size, you'd put whatever
                               // value you want averaged here
}
// reduce
function(keys, values, rereduce) {
    if (!rereduce){
        var length = values.length
        return [sum(values) / length, length]
    }else{
        var length = sum(values.map(function(v){return v[1]}))
        var avg = sum(values.map(function(v){
            return v[0] * (v[1] / length)
            }))
        return [avg, length]
    }
}
The end result will be 2 values, the first is the average, the second is the total number of values that we took an average of. Phew! Who woulda thought taking an average would be so involved!
Posted by Toby 5 months ago about couchdb, javascript and programming (0 comments)

Retrieve The Top N Tags in CouchDB

I am reading up on how map/reduce works in CouchDB, think I am getting the hang of it now, thanks to this great tool. I tried the "Retrieve the top N tags" example on this page. It didn't work for me at all. So I wrote my own as an exercise. Here's my code:
// the map function
function(doc){
    for(var i in doc.tags)
    {
        emit(null, doc.tags[i]);
    }
}

// the reduce function
function(key, values, rereduce){
    var hash = {}
    if (!rereduce){
        for (var i in values){
            var tag = values[i]
            hash[tag] = (hash[tag] || 0) + 1
        }
    }else{
        for (var i in values){
            var topN = values[i]
            for (var i in topN){
                var pair = topN[i]
                var tag = pair[0]
                hash[tag] = (hash[tag] || 0) + pair[1]
            }
        }
    }
    var all = []
    for (var key in hash)
        all.push([key, hash[key]])
    return all.sort(function(one, other){
        return other[1] - one[1]
    }).slice(0, 3)
}
The approach I took was different one from the one from the example page, but I believe it to be the more correct one: rather than returning the results keyed by the tag in the map step, I would emit every occurrence of every tag instead. Then in the reduce step, I would calculate the aggregation values grouped by tag using a hash, transform it into an array, sort it, and choose the top 3. For the rereduce case, I would combine a set of top 3 choices and then again pick the top 3 among them.
Posted by Toby 5 months ago about couchdb, javascript and programming (0 comments)