• 2012-07-15

    Odds in Python Grammar, and Replacement

    Views: 8748 | No Comments

    Whitespace indentation to delimit block is bad

    Python’s syntax is said to be clear and elegant. It is good for small peace of codes, but not good for more than 100 lines of codes. I usually mis-understand the number of indents when first glance at a more than 10 lines block of codes after an if.

    And TAB vs SPACE is particularly annoying! Couldn’t it be an annotation to set TAB=4 SPACE or TAB=8 SPACE?

    The curly braces are quit clear and elegant, most people feel comfortable at curly braces.


    i++ is very usefull.

    Unnecessary “self” in class member function definition

    Python requires you to put an unnecessary “self” as the first argument of a function definition in a class, but to omit it when invoking that function. What’s the meaning of that? It’s total garbage.

    “this” is that!

    Confusing expression of calling function in parent class

    Couldn’t it be as simple as “parent.f()”?

    Useless lambda expression

    The lambda body can only be a single expression – useless! Ah-ha, now you are regret for discriminating curly braces, aren’t you? Look at the really ELEGANT syntax of JavaScript’s anonymous function.

    Unwelcomed None/True/False

    Just let those be: null, true, false. “i is None” is no more elegant than “i == null”.

    Implicit static variable(Non-primative default argument)

    Non-primative default arguments in function definitions are implicitly static, that cause many hidden bugs by mistake.

    Cpy – The comfortable way to write Python codes in C syntax

    Cpy is a C-like scripting language. Cpy codes are converted into python code first, then run by Python at the same time.

    Cpy: http://www.ideawu.com/cpy/

    Posted by ideawu at 2012-07-15 13:51:51
  • 2012-07-14

    Cpy – Wrting Python in C Syntax

    Views: 8981 | No Comments

    Cpy is a C-like scripting language. It is based on Python runtime, and inherits all Python(Python 2.*)’s type system. So you can write script in C syntax, and also have the powerfull Python Engine!

    Documents and Downloads: http://www.ideawu.com/cpy/

    A Hello World of Cpy –

    class A{
    	public a = 0;
    	public static s = 1;
    	function init(a){
    		this.a = a;
    		print 'A init', a;
    	function f(a, b=1){
    		return a + b;
    print A.s; // 1
    a = new A(1); // A init 1
    print a.f(1, 2); // 3
    Posted by ideawu at 2012-07-14 18:40:43
  • 2011-07-08

    Address Picker Using Google Maps API v3

    Views: 22349 | 9 Comments

    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.

    Map Address Picker

    Continue reading »

    Posted by ideawu at 2011-07-08 16:27:21 Tags: , ,
  • 2011-07-03

    The Exact Way to get Width and Height of Dynamic Loaded Image

    Views: 22355 | 5 Comments

    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’t work:

    • You codes run before the image is downloaded from web server,
    • even if you use jQuery to bind a “load” event handler on that image, your codes won’t work when the image is loaded from browser cache(jQuery bug).

    Let me show you the WRONG ways:

    (WRONG)get width/height after setting html content

    var html = '<img src="URL" />;
    var width = $('#my_div img').width(); // may return 0

    (WRONG)get width/height in “load” event handler

    var html = '<img src="URL" />';
    var img = $(html);
        // return 0 if image is loaded from browser cache
        var width = img.width();

    And now, comes the right way…

    The Exact way

    // step 1: display the image
    var img = '<img src="http://image.jpg" />';
    // step 2: get image's width
    var ni = new Image();
    ni.onload = function(){
        var width = ni.width;
    ni.src = 'http://image.jpg';
    Posted by ideawu at 2011-07-03 22:22:53 Tags: , ,
  • 2011-06-10

    APUE-Memory Layout of a C Program

    Views: 15754 | No Comments

    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 on. Also, the text segment is often read-only, to prevent a program from accidentally modifying its instructions.
    • Initialized data segment, usually called simply the data segment, containing variables that are specifically initialized in the program. For example, the C declaration
          int   maxcount = 99;

      appearing outside any function causes this variable to be stored in the initialized data segment with its initial value.

    • Uninitialized data segment, often called the “bss” segment, named after an ancient assembler operator that stood for “block started by symbol.” Data in this segment is initialized by the kernel to arithmetic 0 or null pointers before the program starts executing. The C declaration
          long  sum[1000];

      appearing outside any function causes this variable to be stored in the uninitialized data segment.

    • 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’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’t interfere with the variables from another instance of the function.
    • Heap, where dynamic memory allocation usually takes place. Historically, the heap has been located between the uninitialized data and the stack.

    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 0x08048000, and the bottom of the stack starts just below 0xC0000000. (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.

    Figure 7.6. Typical memory arrangement

    Several more segment types exist in an a.out, containing the symbol table, debugging information, linkage tables for dynamic shared libraries, and the like. These additional sections don’t get loaded as part of the program’s image executed by a process.

    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.

    The size(1) command reports the sizes (in bytes) of the text, data, and bss segments. For example:

        $ 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

    The fourth and fifth columns are the total of the three sizes, displayed in decimal and hexadecimal, respectively.


    All text copy from Advanced Programing in the Unix Environment.

    Posted by ideawu at 2011-06-10 20:10:55 Tags: , ,
|<<<111213141516171819>>>| 17/19 Pages, 91 Results.