Gui Guan’s BLOG

There’s more than one way to do it

Archive for the ‘Computer Science’ Category

Finally, I managed to compile a gtk + cairo GUI program by using mingw GNU make and eclipse CDT under Windows XP.

eclipse CDT + mingw + gtk + cairo

  • 3 Comments
  • Filed under: C
  • internet750.jpg

    read more

  • 1 Comment
  • Filed under: Network
  • Emacs入门指南

    Emacs入门指南(1)

    Emacs入门指南(2)

    Emacs入门指南(3)

  • 0 Comments
  • Filed under: Programming
  • LDBL_MAX -1.#QNAN0e+000 with MinGW?

    I have tried to run this with both eclipse(CDT)+MinGW and Cygwin+GCC

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <float.h>
     
    int main()
      {
        puts("The range of ");
        printf("\tlong double is [%Le, %Le]∪[%Le, %Le]\n", -LDBL_MAX, -LDBL_MIN, LDBL_MIN, LDBL_MAX);
        return EXIT_SUCCESS;
      }

    but got different results:

    • In eclipse(CDT)+MinGW
      The range of
      long double is [-1.#QNAN0e+000, 3.237810e-319]∪[6.953674e-310, 0.000000e+000]
    • In Cygwin+GCC
      The range of
      long double is [-1.189731e+4932, -3.362103e-4932]∪[3.362103e-4932, 1.189731e+4932]

    This is weird, and I googled it, then just found this http://www.thescripts.com/forum/thread498535.html

    The LDBL_MAX of long double is machine-dependent, but why it like this in same machine? I guess it’s the problem with MinGW. Anyone hv any idea?

  • 2 Comments
  • Filed under: C
  • Today, when I was reviewing the session part of PHP, I suddenly came out a question: how to make PHP to append session ID(SID) to your page links automatically when cookies are forbidden in that browser? I managed to do this in JSP, but not sure whether the PHP can also handle this problem.

    I checked the configuration files (php.ini) for my apache server, and there is a session section, under which there is a setting session.use_trans_sid = 0. After I changed this to session.use_trans_sid = 1, and restarted apache, the links of the page which invoked session_start() have now appended the SID. There is also an url_rewriter.tags, with which you can define what elements of a page will be appended.

    Here are some demo codes:

    sessions.php

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    
    <?php ob_start(); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    	<title>Untitled</title>
    </head>
     
    <body>
    <?php
    	ini_set('session.use_trans_sid','1'); //you can also do this instead of modify php.ini
    	session_start();
    	$_SESSION['test']='right!';
    	//header('Location: sessions2.php'); //SID won't be appended in this situation
    	//exit();
    ?>
    <a href="sessions2.php">click here</a>
    </body>
    </html>
    <?php ob_end_flush(); ?>

    sessions2.php

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    <?php ob_start(); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    	<title>Untitled</title>
    </head>
     
    <body>
    <?php
    	session_start();
    	echo $_SESSION['test'];
    ?>
     
    </body>
    </html>
    <?php ob_end_flush(); ?>
  • 0 Comments
  • Filed under: PHP
  • Age 1.0beta1

    Here is my first Robocode robot - Age.

    Age_1.0beta1.png

    No need to have an introduction, just have a try if you want. BTW, it uses anti-gravity motion.

  • 3 Comments
  • Filed under: Java
  • Java simulation for Brownian motion

    RacingParticles

    Here is the Java program written by me to simulate the Brownian motion. In this prac, I tried to use double buffering to improve the performances, but actually it is triple buffering. That’s because the JPane has already implemented the double buffering, so plus mine own copy of buffer to store the background coordinate system and the path of particles, it is triple! Ho ho :P

  • 0 Comments
  • Filed under: Java, Life
  • repaint(), paint() and update()

    Many Java programmers are befuddled by the three methods repaint(), paint(Graphics), and update(Graphics). This is because they are designed to work in a wide variety of circumstances, and they interact in a non-obvious fashion. This happens in several contexts in Java, but GUIs are the most obvious. The designers of Java wanted Java programs to be able to run on any machine that had a Java VM. So, a particular program might be running on a desktop machine, or a laptop, or a hand-held machine, like a personal assistant or a phone. This presents quite a challenge for the designer of an abstract windows toolkit (AWT). It also makes the job of a novice programmer more difficult than it might otherwise be. So it goes.

    i) public void update(Graphics)
    By default update(Graphics) fills the drawable area of a Component with its background color, and then sends paint(Graphics) to the object. Thus, flicker that comes from redrawing the background over and over, can sometimes be fixed by overriding update() (see Code Example 9 on page 238, Simple Java).

    ii) public void paint(Graphics)
    Every Java Component implements paint(Graphics), which is responsible for painting that component in the Graphics context passed in the parameter. When you extend a Component (like when you write a Applet), if you want to display it differently than its superclass, you override public void paint(Graphics) . This was first illustrated in Chapter 3, Simple Java. (more…)

  • 0 Comments
  • Filed under: Java
  • Gui Guan’s Laboratory

    Gui Guan’s Laboratory
    There’s more than one way to do it

    Gui Guan's Laboratory Logo

    http://lab.guiguan.net

    发现Bluehost的服务器环境非常适合在学校和家里来测试PHP脚本,呵呵。同时为了更好的学习Internet Computing,弄了一个自己的实验室,有点Google’s Lab的感觉,但是差远老:P lol

    当你点击进入之后,便是我完成的IC的第二次作业啦(默认用户名:user 密码:password)。以下是这次作业的一些要点:

    • sticky form
    • input validation
    • POST
    • SESSION
    • mail

    (待续…)

  • 0 Comments
  • Filed under: Life, PHP, Website Log