HNHacker News
TopNewBestAskShowJobs

sandaru1

737 karma · joined March 23, 2009

http://www.sandaru1.com/ http://twitter.com/sandaruwan

Co-Founder of Medical Joyworks http://www.medicaljoyworks.com/

sandaruwan [at] gunathilake [dot] com

submissionscomments
sandaru1··on A few fun python lines for your deploy script if you're on a mac
You can use espeak for voice.

> espeak "Hello World"

sandaru1··on Ask HN: I really don't understand node.js, could someone explain it to me?
Following is what I understood while writing a Tornado like server implementation in PHP. Please correct me if I'm wrong.

-----

If you consider a normal application/process, the computation done there is usually very fast. For example, take a blog post being displayed. Once everything(data) is there, wrapping the content in a template, creating the HTTP requests only takes few milliseconds. However, disk IO, database IO, network IO, etc take a quite lot of time compared to computing. The process is usually idle while waiting for those resources.

Now, consider Apache. It's creating a TCP socket and starts listening. Once a connection is made by a client, it spawns a new thread for handling this connection. But since it's waiting for resources like network IO, the thread stays idle for a while. Now, imagine if you are getting lot of requests - like 1000 requests per second. If finishing one web request(processing+waiting) takes about 500ms, apache will need 500 threads per second. Now, creating a thread contains a certain amount overhead. When the thread count goes higher, it becomes much more slower.

Now, consider Node.js as a webserver. First, Node.js server creates a listening socket. In unix platforms, there is a kernel mechanism called "poll"(I think epoll is used in Node.js). Instead of waiting for a connection to send data, you can just register the connection with poll API and continue with your program. That's what happens in Node.js - it just creates the first listening socket, registers it and drops into a loop. Now, inside the loop, it's calling the poll API again with a very low(may be even 0, not sure) waiting time. Now, if there is any data in a registered socket, this API will notify it. So, you take new data and starts processing it. As for the handling of first socket, it creates a new Socket connection and registers that with poll API too and continues the process normally. Now, when HTTP request data comes to the second socket, the main loop gets notified by the epoll API. So, the main loop just jumps into the HTTP request handling function. This function takes the data available, append it with any old data sent from that socket and checks whether if there is enough data for a complete request. If there is not, it simply saves the data in memory and returns to the main loop. If there is data, it simply computes the response and send it back.

A quite similar happens if the response generation need any disk content or database content. Those functions just say I want access to these resources, and tell me once the data is back - and then the main loop takes over.

So, the main difference is that Async model eliminates the overhead created by thousands of threads/processes and handles many connections in single thread. The trick here is that understanding computing only takes a really small amount of time (comparatively). As I understand it, you can't do heavy processing inside the request handlers(like sort 100,000 numbers using buble sort) - this will halt all other requests. Of course, doing the same on a threaded server will cause severe lag in other requests - but that's because of the heavy CPU usage. In Node.js case, it's simply not even trying to process other requests because it's counting on the request handler to finish up quickly, or return to main loop when it's waiting.

sandaru1··on Face detection with Python and OpenCV
If anyone is interested, I wrapped OpenCV face detection into a gstreamer plugin.

http://github.com/sandaru1/smartcut/tree/master/gst-opencv/

sandaru1··on Dell's list of why to buy one with Ubuntu
> The vast majority of viruses and spyware written by hackers are not designed to target and attack Linux.

No wonder people think "hacker" is a bad thing.

sandaru1··on Hacker Monthly #1 is here
You don't have to sign up to checkout. It's mentioned just below the "checkout" link.

However, I agree with you. They can make it easier. It's a good idea to use GEO-IP location to track the country and let users know right away.

sandaru1··on How To Be A Real Elite Programmer And Make Sure Everybody Knows It
TL;DR
sandaru1··on Primer (film)
speaking of (relatively) low budget films, "The Man from Earth" is awesome (it's low budget relative to Hollywood, not relative to Primer; $200,000)

http://en.wikipedia.org/wiki/The_Man_from_Earth

sandaru1··on What iPads Did To My Family
How come iPad is popular among facebook users when [farm]ville apps don't work?
sandaru1··on Programming books I have read and somewhat liked
- Nineteen Eighty Four by George Orwell

- How the Steel Was Tempered by Nikolai Ostrovsky

sandaru1··on Ask HN: How do you solve hard problems if you can't make incremental progress?
Use Levenshtein distance - http://en.wikipedia.org/wiki/Levenshtein_distance
sandaru1··on Translation Of Tweets To Other Languages Spotted On Twitter
I actually implemented something similar just for fun(http://twitpic.com/xcwtb). But didn't release it because i never thought anybody would actually use that. It's very unlikely that someone is going to follow a person who is tweeting in a language they don't understand.
sandaru1··on The 5 Stages of Programmer Incompetence
"The Guru" is also a "she"
sandaru1··on Tell HN : Wordpress.com exploit
2 or 3 days
sandaru1··on Tell HN : Wordpress.com exploit
Indeed, they don't have a method for reporting security exploits. Wordpress Blogging Platform has one, but this issue is only limited to wordpress.com. I believe it has something to do with intensedebate.com

First I sent a email to matt(http://ma.tt/contact/). Then, I used the Automattic contact form(http://automattic.com/contact/)

sandaru1··on Tell HN : Wordpress.com exploit
About 2/3 days
sandaru1··on Tell HN : Wordpress.com exploit
I tested it using two different IP addresses about two days ago. Exploit is still there. Even if there are IP restrictions, it might be dangerous.
sandaru1··on Tell HN : Wordpress.com exploit
Yes. Just a simple JSONP API call.
sandaru1··on HN popularities by domain
Data from : http://news.ycombinator.com/item?id=1174005

Codes : http://gist.github.com/325337 http://gist.github.com/325195

sandaru1··on Six Months of HackerNews Front Page Data
The current data format is harder to read using python csv module. This code will convert it to python compatible csv : http://gist.github.com/325195

It's bit slow(~15 seconds), but it's a one time job.

sandaru1··on Ask HN: What do you think about this experimental twitter app
clickable links

https://chrome.google.com/extensions/detail/bfjidghmenmplpao...

http://www.conwitter.com/

sandaru1··on Working without distraction : my minimalist Macintosh experience
Quote : "I almost never need more than one window to focus on."

That's not suitable for most of the programming work.

sandaru1··on Ask HN: What was the worst bug you've ever solved ?
Is this relevant to following by any chance?

http://karma.nucleuscms.org/item/101

sandaru1··on For Writing Software, a Buddy System
"code - compile - check" - I'm assuming that you are talking about coding/algorithm bugs.

What I'm saying is, lets say you want to find a way to update a web page with live data(http push?). Then you do a brainstorming session with others and get some ideas(comet, bosh, xmpp, etc). If you want to see which technology fits your product most, then it would be a good idea that each person is spending time on different ideas.

"brainstorming" is completely different from "coding together", specially coding a hack.

sandaru1··on For Writing Software, a Buddy System
Pair programming seems to be good, if you have everything defined. But in reality, you research, experiment, hack things around. You work on hunches and quickly implement them, then gradually improve them, compare the solutions and find the best. Pair programming would be pointless; rather annoying in this case.
← PreviousPage 3 of 3