• 2012-07-24

    Why Cpy Beats Python

    Views: 11697 | 2 Comments

    A few ignorant Python programmers said that Python never neads a C-like for statement, they thought they can replace every C-like for looping to Python’s for.

    Cpy‘s way to loop:

    for(i=s; i<num; i+=step){
    }
    

    Python’s way to loop:

    for i in range(num)[s:e:step]:
    

    Recently I wrote a looping to loop 100000000, unfortunately (and as expected) Python eat up all memory(2 GB) of the whole machine and OS forces it to quit.

    But a Cpy looping works fine.

    Posted by ideawu at 2012-07-24 12:09:27
  • 2012-07-21

    The Real General Purposed Dynamic C-like Syntax Scripting Language

    Views: 7193 | No Comments

    Cpy is the real general purposed dynamic c-like syntax scripting language in the 21st century, totally built-up by a Chinese software engineer.

    Cpy provides you a way to write Python codes in C syntax!

    Like other C-like programming languages, it borrows the idea of C programming language, and many other C-like programming language, such as Java, JavaScript, PHP.

    It uses the Python programming language’s type model and runtime, but with a very clean and clear and elegant syntax. Since it is built on the Python runtime, all Python’s built-in modules and Python sources can be easily reused with an import.

    Programmer who has the expirence of Java/JavaScript/PHP development will have no difficulty to write his first Cpy codes, the learn cost is zero. It is a good idea for C programmers who never met a scripting language to start writing scripting codes with Cpy.

    Google project: https://code.google.com/p/cpy-scripting-language/

    Posted by ideawu at 2012-07-21 13:25:09
  • 2012-07-19

    Multi-thread programming with Cpy

    Views: 7330 | No Comments

    Multi-thread programming with Cpy is quit easy. Just import the thread module, then use thread.start_new_thread(func, args) to run a function as a thread.

    import time;
    import thread;
    
    function run(){
        while(true){
            printf("thread: %d says hello\n", thread.get_ident());
            time.sleep(1);
        }
    }
    
    
    foreach(range(0, 3) as i){
        args = tuple();
        thread.start_new_thread(run, args);
    }
    
    // press Enter to quit
    stdin.readline();
    

    Output:

    thread: 5032 says hello
    thread: 4708 says hello
    thread: 5676 says hello
    thread: 5032 says hello
    thread: 4708 says hello
    thread: 5032 says hello
    ...
    
    Posted by ideawu at 2012-07-19 11:12:38
  • 2012-07-17

    Cpy is now ready for download

    Views: 3750 | No Comments

    Download Link: http://www.ideawu.com/cpy/#download

    Posted by ideawu at 2012-07-17 22:56:58
  • 2012-07-17

    PHP codes to dump Redis

    Views: 11068 | No Comments

    Here is a script of PHP codes to dump Redis data, from one db to another. Usage: save codes to file named a.php, change $from and $to, run:

    php a.php

    <?php
    
    $from = '127.0.0.1:6200/6';
    $to = '127.0.0.1:6200/8';
    
    $from_redis = redis_init($from);
    $to_redis = redis_init($to);
    
    $keys = $from_redis->keys('*');
    $count = 0;
    $total = count($keys);
    foreach($keys as $key){
        if(++$count % 100 == 1){
            echo "$count/$total\n";
        }
        $type = $from_redis->type($key);
        switch($type){
            case Redis::REDIS_STRING:
                $val = $from_redis->get($key);
                $to_redis->set($key, $val);
                break;
            case Redis::REDIS_LIST:
                $list = $from_redis->lRange($key, 0, -1);
                foreach($list as $val){
                    $to_redis->rPush($key, $val);
                }
                break;
            case Redis::REDIS_HASH:
                $hash = $from_redis->hGetAll($key);
                $to_redis->hMSet($key, $hash);
                break;
            case Redis::REDIS_ZSET:
                $zset = $from_redis->zRange($key, 0, -1, true);
                foreach($zset as $val=>$score){
                    $to_redis->zAdd($key, $score, $val);
                }
                break;
        }
    }
    
    function redis_init($conf){
        $redis = new Redis();
        preg_match('/^([^:]+)(:[0-9]+)?\\/(.+)?/', $conf, $ms);
        $host = $ms[1];
        $port = trim($ms[2], ':');
        $db = $ms[3];
        $redis->connect($host, $port);
        $redis->select($db);
        return $redis;
    }
    
    Posted by ideawu at 15:29:08 Tags:
|<<<111213141516171819>>>| 16/19 Pages, 91 Results.