powered by Google

Plurk: Instant conversations using Comet

Posted on 30. Jan · Comments [9]
Plurk Comet

The web is becoming more and more realtime and we at Plurk are following the trend. Yesterday we released instant notifications so users can have conversations with sub-second delays - - it's like group based instant messaging.

Implementing this has not been easy given the complexities and size of Plurk, some problems include:

  • huge amount of active users - hundred thousands of online users at once
  • huge amount of usage - to this day our users have posted over 1 billion unique messages
  • complexity of Plurk's features - such as mute, responses seen, private plurks etc.

A demo can be seen here - if that's too boring sign up, invite some friends and try it out live:

Our implementation uses node.js and a big kudos goes to them for their wonderful work.

We have rewritten to node.js from Java+JBoss Netty, because the old solution had scalability problems. We have also been able to build a very sophisticated messaging system given JavaScript expressiveness and the simplicity of node.js. Generally, we have found node.js and V8 very impressive - and it uses about 10 times less memory than Java+Netty did. The bottom line is if you implement anything comet related - - try to use node.js!

We may release our comet implementation in the future, but currently it's very tied up to Plurk's architecture.

I have already shared a lot of my knowledge on comet - including code and a talk about node.js for Taipei Open Source Group. Check out these posts for more info:

Labels: Labels: Code Plurk Tips

Comet (long polling) for all browsers using ScriptCommunicator

Posted on 28. Jan · Comments [6]
Plurk Comet

There's little information on the web how to implement comet (long polling) so it works across domains and works in all major browsers.

I am sharing my solution that's used to power comet on Plurk and I hope this can save time for anyone that has to implement something similar.

I have pushed ScriptCommunicator on github and this script can do following stuff:

  • uses script tags for communication, but can detect when a script isn't loaded (this is non-trivial to implement across browsers)
  • works across domains as long as you control the domains
  • works on IE 6, IE 7, IE 8, FF X, Safari, Chrome and Opera
  • small (80 lines of code) with no dependencies

ScriptCommunicator can also be used to do JSONP calls in a manner where you can handle errors properly. ScriptCommunicator is copyrighted by Plurk Inc. and released under the BSD license.

The problem

There are different problems associated with long polling:

  • scaling comet by using one domain is a lot more difficult than scaling it by using different domains
  • most browsers limit how many open connection you can have to one domain
  • AJAX communication between different domains is restricted due to same origin policy

To solve this we use script tags for communication and this has one big pitfall: you can't easily find out whatever a script is sourced properly - - so error handling using script tags becomes a lot more difficult. ScriptCommunicator adresses these issues and makes communication easy.

The hack

It's trivial to source scripts across domains (you simply append the SCRIPT tag to the head or the body). What's not trivial is finding out if the script was sourced properly and handling errors - and I haven't found a solution for this problem on the net. But there is a solution and it works like this:

  • for Internet Explorer we use script_tag.onreadystatechange to figure out if a success signal is set
  • for other browsers we use following knowledge: sourcing JavaScript is blocking, this means we append two script tags to the document where the first one is sourcing the JavasScript and the second one checks if a success signal is set

It's hacky, but it works :-)

How to use it

You source JavaScript from another domain and this domain does a callback to foocall function. You also supply two functions on_success and on_error.

var url = 'http://some_domain.com/give_me_js_back.php?i=42&callback=foocall'
ScriptCommunicator.sourceJavascript(url, on_success, on_error)

Either your external JavaScript or foocall sets following attribute to true (to signal that the loading of the script was succefull):

ScriptCommunicator.callback_called = true;

That's basically it! Visit ScriptCommunicator on github to get the code.

If you are interested in comet check out following amix.dk posts:

Nikola Tesla - The Forgotten Wizard

Posted on 23. Jan · Comments [1]
Nikola Tesla

Once in a while a genius is born that changes the world. Unfortunately this has occurred only a few times in the human history. Nikola Tesla was such a genius and he never got the recognition he deserves - mainly because of his rivalry with Thomas Edison.

Nikola Tesla's inventions include AC electricity, neon lights, radio transmission, the electric motor, wireless electricity transfer, remote control, hydraulics and many more things. He had around 300 patents and some of his most remarkable work, such as wireless electricity transfer, never got finished and even today we don't have a full understanding what he was up to.

Personally, I am inspired by such a remarkable man and I think his thinking is very interesting, at least from the quotes I have found on him. Here are some of them:

Think before you do

If Edison had a needle to find in a haystack, he would proceed at once with the diligence of the bee to examine straw after straw until he found the object of his search.

I was a sorry witness of such doings, knowing that a little theory and calculation would have saved him ninety per cent of his labor.

What we do echoes in eternity

Let the future tell the truth, and evaluate each one according to his work and accomplishments. The present is theirs; the future, for which I have really worked, is mine.

Don't dwell too much on theory

Today's scientists have substituted mathematics for experiments, and they wander off through equation after equation, and eventually build a structure which has no relation to reality.

I recommend checking out this video on Nikola Tesla and his weird and remarkable life (which like this post is named Nikola Tesla - The Forgotten Wizard):

The ultimate Vim configuration (vimrc)

Posted on 16. Jan · Comments [12]
ultimative vim configuration

When searching for vimrc on Google you'll find my vimrc from 2006 in the top 10 results. Unfortunately this vimrc is outdated and it included a lot of garbage.

I am now releasing a new vimrc that I think is the ultimate and that you can use or get inspired by!

My new vimrc can be found here:

If you wish, you can also install my Vim configuration easily (along with some very useful plugins). To install it simply do following:

$ mkdir ~/.vim_runtime
$ svn co svn://orangoo.com/vim ~/.vim_runtime
$ cat ~/.vim_runtime/install.sh
$ sh ~/.vim_runtime/install.sh <system>
  <sytem> can be `mac`, `linux` or `windows`

My Vim configuration includes following plugins:

Happy hacking ;-)

The colorscheme I use is called peaksea and looks like this:

Vim peaksea colorscheme

Applying game mechanics to functional software

Posted on 3. Jan · Comments [3]
One of the things I find interesting is behavioral psychology and recently I stumbled on a presentation by Amy Jo Kim on how to introduce game mechanics into any product. The first part is rather interesting and she shows how game mechanics work in YouTube and eBay.

Labels: Labels: Psychology Tips

Comet with node.js and V8

Posted on 29. Dec 2009 · Comments [0]
A presentation on how to build realtime web applications using node.js, V8 and WebSockets.

This is a presentation I have given to Taipei Open Source Software User Group. A big thanks goes to Ping for the invitation.

Microsoft China rips off Plurk

Posted on 14. Dec 2009 · Comments [7]
Imitation may be the sincerest form of flattery, but blatant theft of code, design, and UI elements is just not cool, especially when the infringing party is the biggest software company in the world. Yes, we’re talking about Microsoft. Interested? Read more:

I am the lead dev & co-founder of Plurk. Please help this spread and help us fight this.

Update 1:
Microsoft has acknowledged they have a problem. club.msn.cn has been shut down while they investigate. Official press release from MS.

Update 2:
Microsoft has acknowledged code theft and apologized to Plurk. Juku has been shut down indefinitely. Their press release.

A big thanks goes to everyone that has supported us in this.

Labels: Labels: Code Design Life Plurk

Picasso's bull and Google's fade in page

Posted on 7. Dec 2009 · Comments [3]
Focusing on the essentials is hard, because it's unclear what the essentials are.

Pablo Picasso reduced a bull to 12 pen strokes:

Pablo Picasso

Google still tries to stick to essentials with the new fade in homepage:

Google Search Simple

Keep it simple stupid.

Labels: Labels: Design

We are humans

Posted on 29. Nov 2009 · Comments [6]
Earth

I walked the streets of Taipei, reflecting on the differences between my culture and the Taiwanese culture - - and suddenly a revelation hit me.

The Taiwanese people speak another language than me, they eat different food than me, they ... different than me. But let's look at it from another perspective: The Taiwanese people smile like me, they are as intelligent as me, they love their family like me...

And this is the revelation... Focusing on the differences is wrong, we should focus and embrace our similarities. Deep down we aren't Taiwanese, Bosnian, American, Muslims or Jews... We are humans and we have more things in common than in difference! Let's accept our small differences and embrace our many similarities. More love, less hate.

Why we are happy?

Posted on 2. Nov 2009 · Comments [3]
This is a great, and somewhat scientific, TED presentation on happiness:

The presentation features also a great quote from The Theory of the Moral Sentiments (by Adam Smith, the father of modern capitalism) :

The great source of both the misery and disorders of human life, seems to arise from over-rating the difference between one permanent situation and another. Avarice over-rates the difference between poverty and riches: ambition, that between a private and a public station: vain-glory, that between obscurity and extensive reputation. The person under the influence of any of those extravagant passions, is not only miserable in his actual situation, but is often disposed to disturb the peace of society, in order to arrive at that which he so foolishly admires. The slightest observation, however, might satisfy him, that, in all the ordinary situations of human life, a well-disposed mind may be equally calm, equally cheerful, and equally contented. Some of those situations may, no doubt, deserve to be preferred to others: but none of them can deserve to be pursued with that passionate ardour which drives us to violate the rules either of prudence or of justice; or to corrupt the future tranquillity of our minds, either by shame from the remembrance of our own folly, or by remorse from the horror of our own injustice.

Labels: Labels: Life

The structure of code is also important

Posted on 1. Nov 2009 · Comments [4]
A thing we forget to think or talk about is the structure that code lives in and interacts with. Building a logical directory and name structure for modules, for templates, for static files is as important as well written code.

Recently, I have done a rewrite of the template structure for Todoist - - where improving the structure played a bigger part of the rewrite. I think this picture speaks for itself:

Todoist template directory structure

Thoughts on freedom

Posted on 31. Oct 2009 · Comments [10]
Lotus flower

For some years I have thought about freedom and how to achieve it. It hasn't been that easy to specify what kind of freedom I really meant or really wanted. I have tried to specify freedom and how to achieve it and I hope this description can be useful for others that are looking to become free. I have been inspired by Buddhism, but I would not call myself a buddhist.

No attachments

Becoming free implies that you loose attachments. Non-attachment does not mean that you should become indifferent or emotionally cold. It means that you should accept that you can lose your job, your best friend could die and your girlfriend could leave you. Don't fear loss, but accept it as a part of life and something that could and will eventually happen.

Look within. Be still.
Free from fear and attachment,
Know the sweet joy of living in the way.

Live in the present

Live, embrace and accept the present moment, instead of waiting anxiously for all future desires to be fulfilled. Like Gandhi said: Live as if you were to die tomorrow. Learn as if you were to live forever.

Don't carry the burden of the past,
nor indulge in the fantasizes of the future,
nor intoxicate with the desires of the present.

No goals and dreams

Goals and dreams are mostly fantasizes. You build a fantasy of how it's going to be when you get that job or find the perfect mate. When you reach your goal you find out that it was just a fantasy and the taste is not that sweet as you imagined.

The lesson is to live in the present moment and not dwell on the prospects of the future. Enjoy what you have now, instead of being a slave of what you want to achieve or become.

David Bowie wrote about this delusion in Changes:

Still don't know what I was waiting for
And my time was running wild
A million dead-end streets and
every time I thought I'd got it made,
it seemed the taste was not so sweet...

Don't act

Acting like you live in the present moment is not the same as living in the present moment. Acting like you you are non-attached is not the same as being non-attached!

Acting is a delusion and if you are acting you are cheating yourself. Don't act free, but be free!

It's a practice

Becoming free takes a lot practice. It's not something that you can read your way through or something that magically happens to you. It's a change within and a change that takes a lot of practice.

Labels: Labels: Life

Social programming should be a feature of a language

Posted on 28. Oct 2009 · Comments [7]
Social programming

In this blog post I will argue that future programming languages should focus on the social aspects of programming and be more democratic (especially when it comes to the standard library).

History and trends

In 1995 Perl launched CPAN, which is a Perl repository that holds thousands of Perl modules and their documentation. CPAN is a great success and one of Perl's greatest strengths. It even holds some "social" aspects such as rating modules.

Python and Ruby have tried to copy CPAN, but their attempts are not that social in nature and not that good overall, but they do enable developers to quickly push out their packages and for developers to quickly install packages.

In the recent times we have seen the rise of GitHub, BitBucket, Google Code and lots of other projects that make programming more social and that enable easier collaboration between developers.

The bottom line is that programming is getting more social, it's relatively easy to push out packages and Perl, Ruby and Python have great success with their packaging platforms.

Lacks of the current platforms

I'll take Python as an example of the current problems. Python lacks can be applied to other languages as well. In my example I want to find a template library for Python.

I search for "template" on Python Package Index:

The results as you can see are mostly useless. Mako, which is one of the great template systems, has a score of 1. Jinja, another great template system, a score of 3. Other unknown template libraries and tools a score of 5+. Useless!

But that's really the beginning. PyPi is pretty horrific for any kind of collaboration. If I fetch a package I don't have a clear path on how to send back my patches, patches that could be useful for other developers. I don't have a clear path on how to report bugs, bugs which other developers might be experiencing. I don't have an overview of what current patches there exists or what bugs are currently present or have been fixed.

The general presentation of the system is pretty bad as well. Why not keep a track of which developers maintain which packages? Or have a reputation system? So if Joe is really active and really helpful, then the system should figure out that Joe should have a high reputation - others can then judge projects based on the reputation of the project and its developers. A reputation system would also introduce a competitive aspect, which could fuel innovation and improve quality.

The social platform

The idea of the social platform is to create a platform where developers can collaborate and a platform that promotes quality software. CPAN, Ruby Gems and Python Package Index are early versions of this vision and they need to become more social to become more useful. The social platform should be applied to the core libraries as well and not just be used for the external libraries. A language's standard library should be a democracy where the best and most used libraries win - and not like now, where libraries win by being selected by a few dictators!

Essentials of this platform are:

  • Easy distribution: It should be easy to push out modules to the platform.
  • Easy forking: It should be easy to fork modules, to apply patches and to send patches back. Using something like git or mercurial is a must.
  • Reviews and a reputation system: The platform should have reviews, but also reputation, something like Stack Overflow's excellent reputation system. I.e. a system where helpful developers are rewarded for their hard work.
  • Search and discovery: It should be easy to find modules you are looking for and to compare modules. If I am looking for a template library, then I might want to sort template libraries by how many others are using them.
  • Fully integrated into the language: This platform should be fully included in the language and ship with the language. The signup process to get on the platform should be very easy.
  • Trac like features included: This platform should include tickets, timeline of changes and a basic wiki.

Most of these pieces are partially implemented, especially in products like GitHub and BitBucket. What is needed is a much better integration with the languages. The bottom line is that languages should embrace "social programming" and implement a platform similar to GitHub/BitBucket that enables developers for easy collaboration.

The feel good start

Posted on 15. Oct 2009 · Comments [5]
I have lately started to use a hack that can enable me to enter the productivity zone much quicker.

By my experience one of the worst ways to start is by checking or answering emails - - or even worse, start the day by checking news to see what's up. In the past, I have spent tons of hours on kickstarting myself. This little hack addresses the issue of starting off in a good and productive way.

The productivity hack I use is quite simple:

  • Before finishing work or taking a break, leave an easy task that can be done next time

Next time you start working, start with this easy task. Hopefully you'll be amazed by the results :-)

Labels: Labels: Life Tips
© 2000-2009 amix. Powered by Skeletonz.