<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web Design &#38; Develop</title>
	<atom:link href="http://www.ideawu.com/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ideawu.com/blog</link>
	<description>Web development and develop, PSD to XHTML(HTML)/CSS</description>
	<lastBuildDate>Wed, 07 Sep 2011 18:23:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Address Picker Using Google Maps API v3</title>
		<link>http://www.ideawu.com/blog/2011/07/address-picker-using-google-maps-api-v3.html</link>
		<comments>http://www.ideawu.com/blog/2011/07/address-picker-using-google-maps-api-v3.html#comments</comments>
		<pubDate>Fri, 08 Jul 2011 08:27:21 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[Web Design & Develop]]></category>
		<category><![CDATA[Google Maps API]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.ideawu.com/blog/?p=18</guid>
		<description><![CDATA[A very light, simple and easy to use address picker using Google Maps API v3 and jQuery, you may use this widget to embd in you web forms if you want user to input address or/and latitude/longtitude.


Live Demo

Download

Code sample:
&#60;script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"&#62;&#60;/script&#62;
&#60;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"&#62;&#60;/script&#62;
&#60;script type="text/javascript" src="map.js"&#62;&#60;/script&#62;

&#60;input type="reset" id="pick_addr" value="Pick Address" /&#62;

&#60;script type="text/javascript"&#62;
&#60;!--
$(document).ready(function(){
	function callback(pos, [...]]]></description>
			<content:encoded><![CDATA[<p>A very light, simple and easy to use address picker using Google Maps API v3 and jQuery, you may use this widget to embd in you web forms if you want user to input address or/and latitude/longtitude.</p>
<p><img src="http://www.ideawu.com/prj/address-picker/screenshot-small.jpg" alt="Map Address Picker" /></p>
<p><span id="more-18"></span></p>
<h3><a href="http://www.ideawu.com/prj/address-picker/"><span style="padding: 5px; color: #33f; background: #eee; border: 1px solid #aaa;">Live Demo</span></a></h3>
<h3>
<a href="http://www.ideawu.com/prj/address-picker/map.js"><span style="padding: 5px; color: #33f; background: #eee; border: 1px solid #aaa;">Download</span></a><br />
</h3>
<p>Code sample:</p>
<pre>&lt;script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="map.js"&gt;&lt;/script&gt;

&lt;input type="reset" id="pick_addr" value="Pick Address" /&gt;

&lt;script type="text/javascript"&gt;
&lt;!--
$(document).ready(function(){
	function callback(pos, addr, addr_ext){
		alert(pos, addr, addr_ext);
	}

	var default_pos = new google.maps.LatLng(39.904214, 116.407413);
	var opt = {
		pos: default_pos,
		callback: callback
	};
	var addr_picker = new AddressPicker(opt);

	$('#pick_addr').click(function(){
		addr_picker.open();
	});
});
//--&gt;
&lt;/script&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.com/blog/2011/07/address-picker-using-google-maps-api-v3.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The Exact Way to get Width and Height of Dynamic Loaded Image</title>
		<link>http://www.ideawu.com/blog/2011/07/the-exact-way-to-get-width-and-height-of-dynamic-loaded-image.html</link>
		<comments>http://www.ideawu.com/blog/2011/07/the-exact-way-to-get-width-and-height-of-dynamic-loaded-image.html#comments</comments>
		<pubDate>Sun, 03 Jul 2011 14:22:53 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[Web Design & Develop]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[js-image]]></category>

		<guid isPermaLink="false">http://www.ideawu.com/blog/?p=16</guid>
		<description><![CDATA[There are certain wrong ways using JavaScript/jQuery to get the width/height of dynamic loaded image. Here are some reasons why your codes won&#8217;t work:

You codes run before the image is downloaded from web server,
event you use jQuery to bind a &#8220;load&#8221; event handler on that image, your codes won&#8217;t work when the image is loaded [...]]]></description>
			<content:encoded><![CDATA[<p>There are certain wrong ways using JavaScript/jQuery to get the width/height of dynamic loaded image. Here are some reasons why your codes won&#8217;t work:</p>
<ul>
<li>You codes run before the image is downloaded from web server,</li>
<li>event you use jQuery to bind a &#8220;load&#8221; event handler on that image, your codes won&#8217;t work when the image is loaded from browser cache(jQuery bug).</li>
</ul>
<p>Let me show you the WRONG ways:</p>
<h3>(WRONG)get width/height after setting html content</h3>
<pre>
var html = '&lt;img src="URL" /&gt;;
$('#my_div').html(html);
var width = $('#my_div img').width(); // may return 0
</pre>
<h3>(WRONG)get width/height in &#8220;load&#8221; event handler</h3>
<pre>
var html = '&lt;img src="URL" /&gt;';
var img = $(html);
html.load(function(){
    // return 0 if image is loaded from browser cache
    var width = img.width();
});
$('#my_div').html(img);
</pre>
<p>And now, comes the right way&#8230;</p>
<h3>The Exact way</h3>
<pre>
var html = '&lt;img src="URL" /&gt;';
$('#my_div').html(html);

var ni = new Image();
ni.onload = function(){
    var width = ni.width;
}
ni.src = img.attr(URL);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.com/blog/2011/07/the-exact-way-to-get-width-and-height-of-dynamic-loaded-image.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>APUE-Memory Layout of a C Program</title>
		<link>http://www.ideawu.com/blog/2011/06/apue-memory-layout-of-a-c-program.html</link>
		<comments>http://www.ideawu.com/blog/2011/06/apue-memory-layout-of-a-c-program.html#comments</comments>
		<pubDate>Fri, 10 Jun 2011 12:10:55 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[Linux C]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.ideawu.com/blog/?p=12</guid>
		<description><![CDATA[Historically, a C program has been composed of the following  pieces:

Text segment, the machine instructions that the CPU executes.  Usually, the text segment is sharable so that only a single copy needs to be in  memory for frequently executed programs, such as text editors, the C compiler,  the shells, and so [...]]]></description>
			<content:encoded><![CDATA[<p>Historically, a C program has been composed of the following  pieces:</p>
<ul>
<li>Text segment, the machine instructions that the CPU executes.  Usually, the text segment is sharable so that only a single copy needs to be in  memory for frequently executed programs, such as text editors, the C compiler,  the shells, and so on. Also, the text segment is often read-only, to prevent a  program from accidentally modifying its instructions.</li>
<li>Initialized data segment, usually  called simply the data segment, containing variables that are specifically  initialized in the program. For example, the C declaration
<pre>    int   maxcount = 99;
</pre>
<p>appearing outside any function causes this variable to be  stored in the initialized data segment with its initial value.</li>
<li>Uninitialized data segment, often called the &#8220;bss&#8221; segment,  named after an ancient assembler operator that stood for &#8220;block started by  symbol.&#8221; Data in this segment is initialized by the kernel to arithmetic 0 or  null pointers before the program starts executing. The C declaration
<pre>    long  sum[1000];
</pre>
<p>appearing outside any function causes this variable to be  stored in the uninitialized data segment.</li>
<li>Stack, where automatic variables are stored, along with  information that is saved each time a function is called. Each time a function  is called, the address of where to return to and certain information about the  caller&#8217;s environment, such as some of the machine registers, are saved on the  stack. The newly called function then allocates room on the stack for its  automatic and temporary variables. This is how recursive functions in C can  work. Each time a recursive function calls itself, a new stack frame is used, so  one set of variables doesn&#8217;t interfere with the variables from another instance  of the function.</li>
<li>Heap, where dynamic memory allocation usually takes place.  Historically, the heap has been located between the uninitialized data and the  stack.</li>
</ul>
<p>Figure 7.6 shows the  typical arrangement of these segments. This is a logical picture of how a  program looks; there is no requirement that a given implementation arrange its  memory in this fashion. Nevertheless, this gives us a typical arrangement to  describe. With Linux on an Intel x86 processor, the text segment starts at  location <tt>0x08048000</tt>, and the bottom of the stack starts just below  <tt>0xC0000000</tt>. (The stack grows from higher-numbered addresses to  lower-numbered addresses on this particular architecture.) The unused virtual  address space between the top of the heap and the top of the stack is  large.</p>
<h5>Figure 7.6. Typical memory arrangement</h5>
<p><a href="http://www.ideawu.com/blog/wp-content/uploads/2011/06/c-memory-layout.png"><img src="http://www.ideawu.com/blog/wp-content/uploads/2011/06/c-memory-layout.png" alt="" title="c-memory-layout" width="420" height="357" class="alignnone size-full wp-image-13" /></a></p>
<blockquote><p>Several more segment types exist in an <tt>a.out</tt>,  containing the symbol table, debugging information, linkage tables for dynamic  shared libraries, and the like. These additional sections don&#8217;t get loaded as  part of the program&#8217;s image executed by a process.</p></blockquote>
<p>Note from Figure 7.6 that the contents of the uninitialized data segment are not stored in the  program file on disk. This is because the kernel sets it to 0 before the program  starts running. The only portions of the program that need to be saved in the  program file are the text segment and the initialized data.</p>
<p>The <tt>size</tt>(1) command reports the sizes (in bytes) of  the text, data, and bss segments. For example:</p>
<pre>    $ size /usr/bin/cc /bin/sh
       text     data   bss     dec     hex   filename
      79606     1536   916   82058   1408a   /usr/bin/cc
     619234    21120 18260  658614   a0cb6   /bin/sh
</pre>
<p>The fourth and fifth columns are the total of the three sizes,  displayed in decimal and hexadecimal, respectively.</p>
<p>&#8212;&#8212;</p>
<p>All text copy from Advanced Programing in the Unix Environment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.com/blog/2011/06/apue-memory-layout-of-a-c-program.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Delay Bind Event Handler(Lazy Bind)</title>
		<link>http://www.ideawu.com/blog/2011/05/jquery-delay-bind-event-handler-lazy-bind.html</link>
		<comments>http://www.ideawu.com/blog/2011/05/jquery-delay-bind-event-handler-lazy-bind.html#comments</comments>
		<pubDate>Fri, 27 May 2011 08:40:48 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[Web Design & Develop]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.ideawu.com/blog/2011/05/jquery-delay-bind-event-handlerlazy-bind.html</guid>
		<description><![CDATA[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;
    [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<h3>View: <a href="http://www.ideawu.com/prj/jquery-lazy-bind/">Demo</a></h3>
<pre>
// 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');
</pre>
<p>@Parameters</p>
<ul>
<li><strong>event</strong>: string, event to bind to</li>
<li><strong>fn</strong>: function, callback</li>
<li><strong>timeout</strong>: int, time to wait before fn being called, in millisecond</li>
<li><strong>abort</strong>: string, on which event the binding will be cancelled.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.com/blog/2011/05/jquery-delay-bind-event-handler-lazy-bind.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An experience of Google interview</title>
		<link>http://www.ideawu.com/blog/2010/12/an-experience-of-google-interview.html</link>
		<comments>http://www.ideawu.com/blog/2010/12/an-experience-of-google-interview.html#comments</comments>
		<pubDate>Mon, 13 Dec 2010 15:17:17 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[None]]></category>

		<guid isPermaLink="false">http://www.ideawu.com/blog/10.html</guid>
		<description><![CDATA[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&#8217;t talk too much on the phone during first call from Google HR, a kind [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>We didn&#8217;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&#8217;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.</p>
<p><span id="more-10"></span>The guy was an engineer, we had a comfortable conversation. He asked me to traverse a binary tree for the first question to work out. I was not simply the Preorder Traversal, Inorder Traversal or Postorder Traversal, but to print out every node when you left it behind, it was: Parent-Left-Parent-Right-Parent order.</p>
<p>The second question was based on the first one. I was asked to transform the output of the first question back into a tree. This one was more easier, I worked it out within 3 minutes. All codes were written in Python.</p>
<p>So I got into next round, also a coding and algorithm interview. I was asked to find out the Not-intersection set from two lists. He wrote a prototype of C++ function, then I asked if I may change the return type from list to list pointer, and the parameters from list to list reference.  I firstly wrote one with two loops and STL list.find(), it was O(n2). We both know Google would not satisfied with it, then I said it should be using hashmap, not the solution. The he said the lists are ordered.</p>
<p>Next question was to find one random element from a list with an unknown length, with we only had a random function that returns double in (0, 1). He said that was one of the problems he faced in Google works and has not yet figured out a acceptable solution. I said it would be two traverses through the list, one to find out the length, and one to return the randomed index one. Until now, I still don&#8217;t know how could it be improved. But later after came home, I find something interesting relative to the question, and wrote a mail to the interviewer about that.</p>
<p>The last interviewer, I felt a bit weird about him, the conversation totally turned us into opposite sides. You know, people have feelings about each other at first glance. He asked me to design a web system like is.gd &#8211; the URL shorten service. Firstly, make it work, then supporting enormouse number of users, multi-IDC, distributed system synchronization, etc. I thought this as a wide question, so I didn&#8217;t answer into specifics, but he did not caught my idea at all! He asked something like how to distribute HTTP requests on multi servers? I said we may use network hardwares, or software like LVS, or HTTP proxy server(e.g. lighttpd, nginx). Oh man, what were you expecting for? Is this a question about certain technic, or is this a question about system/architecture design?</p>
<p>He realized the question was a blow into the air, so he followed with an algorithm question. Which I don&#8217;t want to talk about here, because I didn&#8217;t work it out at that time. It was not a complicated question, but he told in a unprofessional way. Howerver, time spending with this guy was not pleasant, it should be a friend-talk, which I expected.</p>
<p>You may have guessed out the consequence, I failed the interview for my weakness in algorithm. But I actually made a big improvement on my career since three years ago. I sent my resume to Google when I was a university student three years ago, and I didn&#8217;t even get a man-made reply. This time, I went a further way.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.com/blog/2010/12/an-experience-of-google-interview.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Free Lucky Lottery Software</title>
		<link>http://www.ideawu.com/blog/2010/11/free-lucky-lottery-software.html</link>
		<comments>http://www.ideawu.com/blog/2010/11/free-lucky-lottery-software.html#comments</comments>
		<pubDate>Fri, 12 Nov 2010 06:43:48 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[None]]></category>

		<guid isPermaLink="false">http://www.ideawu.com/blog/9.html</guid>
		<description><![CDATA[Written in JavaScript+HTML+CSS, run on most web browser, such as Firefox, Internet Explorer, Chrome, Opera. Free of charge.

Play Online Now &#62;&#62;
]]></description>
			<content:encoded><![CDATA[<p>Written in JavaScript+HTML+CSS, run on most web browser, such as <a href="http://www.mozilla.com/firefox/">Firefox</a>, <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx">Internet Explorer</a>, <a href="http://www.google.com/chrome">Chrome</a>, <a href="http://www.opera.com/">Opera</a>. Free of charge.</p>
<p><a href="http://www.ideawu.com/prj/lottery_en/"><img src="http://www.ideawu.com/blog/wp-content/uploads/2010/11/lottery-340x206.jpg" alt="" title="lucky lottery" width="340" height="206" class="alignnone size-medium wp-image-8" /></a></p>
<p><a href="http://www.ideawu.com/prj/lottery_en/">Play Online Now &gt;&gt;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.com/blog/2010/11/free-lucky-lottery-software.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delegate in Python(Python Asynchronous Programming)</title>
		<link>http://www.ideawu.com/blog/2010/08/delegate-in-pythonpython-asynchronous-programming.html</link>
		<comments>http://www.ideawu.com/blog/2010/08/delegate-in-pythonpython-asynchronous-programming.html#comments</comments>
		<pubDate>Sat, 28 Aug 2010 09:00:29 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.ideawu.com/blog/?p=5</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>The .NET Framework enables you to call any method asynchonously, by the two methods <b>BeginInvoke</b> and <b>EndInvoke</b>. The BeginInvoke method is used to register a <b>function execution</b> to <b>Delegate</b>(background threads), it quickly returns, so you can execute other codes after. In later time, you can use <b>EndInvoke</b> to get the return of the execution of that registered function, or you may had register a <b>Callback</b> function in the mean time you register that function, so this Callback will be automatically executed.</p>
<p>The structure of source code can be demonstrate in this steps:</p>
<ol>
<li>handle = <b>BeginInvoke</b>(my_function)</li>
<li>do other work</li>
<li>result = handle.<b>EndInvoke</b>()</li>
<li>deal with result</li>
</ol>
<p><span id="more-5"></span>Or in callback way:</p>
<ol>
<li>handle = <b>BeginInvoke</b>(my_function, callback)</li>
<li>do other work</li>
</ol>
<p>Python does not support Asynchronous, so I made a Delegate class, you can do Asynchronous Programming in the same way like <a href="http://msdn.microsoft.com/en-us/library/2e08f6yc%28v=VS.100%29.aspx">.NET Framework does</a>:</p>
<pre>
#encoding=UTF-8
import time, random
import sys
from delegate import *

def proc(a):
    time.sleep(random.random())
    return str(a)

def proc_callback(handle, args=None):
    try:
        ret = d.end(handle)
        log.debug('proc return: ' + repr(ret))
    except Exception,e:
        log.warn('end throw Exception: ' + str(e))
        return

d = Delegate()
d.init(2) # number of workers

n = 0
while True:
    n += 1
    log.debug("Press 'q' to quit, Enter to continue.")
    line = sys.stdin.readline().strip()
    if line == 'q':
        break
    data = str(n)
    handle = d.begin(proc, data, proc_callback, 'test')
    log.debug('register ' + data)

d.free()
</pre>
<p><b>Download source code: <a href='http://www.ideawu.com/blog/wp-content/uploads/2010/08/pap.zip'>pap.zip</a> <a href="http://www.ideawu.com/prj/pap/">API doc</a></b></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.com/blog/2010/08/delegate-in-pythonpython-asynchronous-programming.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to select stdin in Python Windows?</title>
		<link>http://www.ideawu.com/blog/2010/08/how-to-select-stdin-in-python-windows.html</link>
		<comments>http://www.ideawu.com/blog/2010/08/how-to-select-stdin-in-python-windows.html#comments</comments>
		<pubDate>Sat, 21 Aug 2010 14:13:23 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[socket]]></category>

		<guid isPermaLink="false">http://www.ideawu.com/blog/3.html</guid>
		<description><![CDATA[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&#8217;t originate from WinSock.

In a recent project, I must continuously read from one network socket, forward to another socket, until the user input [...]]]></description>
			<content:encoded><![CDATA[<p>The Python document <a href="http://docs.python.org/library/select.html#select.select">says</a>:</p>
<blockquote><p>
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&#8217;t originate from WinSock.
</p></blockquote>
<p>In a recent project, I must continuously read from one network socket, forward to another socket, until the user input &#8216;q&#8217; from the console. One may think to use threading, but I don&#8217;t want to deal with multi-thread stuffs. Finally, I found a none-clear solution, and it worked.</p>
<p>I create one thread &#8211; YES, thread, but no multi-thread concerns &#8211; 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.</p>
<p><strong>Download source code: <a href='http://www.ideawu.com/blog/wp-content/uploads/2010/08/stdio.py_.zip'>stdio.py</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.com/blog/2010/08/how-to-select-stdin-in-python-windows.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello World!</title>
		<link>http://www.ideawu.com/blog/2010/08/hello-world.html</link>
		<comments>http://www.ideawu.com/blog/2010/08/hello-world.html#comments</comments>
		<pubDate>Sat, 21 Aug 2010 04:00:38 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[None]]></category>

		<guid isPermaLink="false">http://localhost:8080/ideawu.com/blog/1.html</guid>
		<description><![CDATA[A Programmer&#8217;s blog. All things about C, C++, PHP, Python, HTML, CSS, JavaScript, Linux, Web development, Network Programming.
]]></description>
			<content:encoded><![CDATA[<p>A Programmer&#8217;s blog. All things about C, C++, PHP, Python, HTML, CSS, JavaScript, Linux, Web development, Network Programming.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.com/blog/2010/08/hello-world.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

