• 2011-05-27

    jQuery Delay Bind Event Handler(Lazy Bind)

    Views: 19250 | 1 Comment

    Bind an event handler to one or more elements, allow to abort the bindation on other event. Usefull for showing tooltip when mouse moves on elements after a few time.

    View: Demo

    // define
    (function($){
        $.fn.lazybind = function(event, fn, timeout, abort){
            var timer = null;
            $(this).bind(event, function(e){
                var ev = e;
                timer = setTimeout(function(){
                    fn(ev);
                }, timeout);
            });
            if(abort == undefined){
                return;
            }
            $(this).bind(abort, function(){
                if(timer != null){
                    clearTimeout(timer);
                }
            });
        };
    })(jQuery);
    
    
    // example
    $('#my_img').lazybind(
        'mouseover',
        function(){
            alert(1);
        },
        500,
        'mouseout');
    

    @Parameters

    • event: string, event to bind to
    • fn: function, callback
    • timeout: int, time to wait before fn being called, in millisecond
    • abort: string, on which event the binding will be cancelled.
    Posted by ideawu at 2011-05-27 16:40:48 Tags: ,
  • 2010-12-13

    An experience of Google interview

    Views: 8578 | 1 Comment

    Recently, I had a experience of Google interview(Beijing, China), I went through for three rounds of the interview. Firstly a phone interview, secondly an on-site interview in Google building, thirdly also an interview in Google building but with two people.

    We didn’t talk too much on the phone during first call from Google HR, a kind lady. Actually, it was because my spoken English, you know, I didn’t even speak a English word during the past threes year. But I suggest I should directly go to there office and have a face-to-face interview.

    Continue reading »

    Posted by ideawu at 2010-12-13 23:17:17
  • 2010-11-12

    Free Lucky Lottery Software

    Views: 8329 | No Comments

    Written in JavaScript+HTML+CSS, run on most web browser, such as Firefox, Internet Explorer, Chrome, Opera. Free of charge.

    Play Online Now >>

    Posted by ideawu at 2010-11-12 14:43:48
  • 2010-08-28

    Delegate in Python(Python Asynchronous Programming)

    Views: 14929 | No Comments

    The .NET Framework enables you to call any method asynchonously, by the two methods BeginInvoke and EndInvoke. The BeginInvoke method is used to register a function execution to Delegate(background threads), it quickly returns, so you can execute other codes after. In later time, you can use EndInvoke to get the return of the execution of that registered function, or you may had register a Callback function in the mean time you register that function, so this Callback will be automatically executed.

    The structure of source code can be demonstrate in this steps:

    1. handle = BeginInvoke(my_function)
    2. do other work
    3. result = handle.EndInvoke()
    4. deal with result

    Continue reading »

    Posted by ideawu at 2010-08-28 17:00:29
  • 2010-08-21

    How to select stdin in Python Windows?

    Views: 21064 | 1 Comment

    The Python document says:

    File objects on Windows are not acceptable, but sockets are. On Windows, the underlying select function is provided by the WinSock library, and does not handle file descriptors that don’t originate from WinSock.

    In a recent project, I must continuously read from one network socket, forward to another socket, until the user input ‘q’ from the console. One may think to use threading, but I don’t want to deal with multi-thread stuffs. Finally, I found a none-clear solution, and it worked.

    I create one thread – YES, thread, but no multi-thread concerns – this thread open a server socket listening on random port, then open a client socket connect to this server. The server socket accept the connection, then call sys.stdin.read() in a block way, all data read from stdin will write to that accepted connection. So client socket receive data reading from stdin. Now, the client socket is a *selectable* stdin, and it is thread-safe.

    Download source code: stdio.py

    Posted by ideawu at 2010-08-21 22:13:23 Tags: ,
|<<<111213141516171819>>>| 18/19 Pages, 91 Results.