Tag Archives: Language

Node start – create a server listening port.

var http = require(“http”);
function onRequest(request, response) {
nsole. log(” function start “);
response. WriteHead (200, {” content-type “:” text/plain “});
response. Wirte (” hello “);
the response. The end ();
}
http.createServer(onRequest).listen(8888);
console.log(“Server has startsed”)
Get Node’s HTTP module first.
var http = require(“http”);
Write the handler function. onRequest
Create the server and listen on port 8888
http.createServer(onRequest).listen(8888);

The language of C__ FILE__ 、__ LINE__ And line

Original link:
 
http://hi.baidu.com/419836321/blog/item/fcf5ceec484681cfb31cb1f7.html
 
 
 
 

__FILE__ is used in C to indicate the filename of the source file in which the statement is written, for example (test.c) :

    #include < stdio.h> int main() { printf(“%s\n”,__FILE__); }

GCC compiler generates a.out. After execution, the output is:

test.c

Compiling results under Windows VC6.0 are as follows:

C :\ Documents and Settings \ Administrator \ Desktop \ Test.c

——————————————————————————————————————————————————————————————————– ————————————————————————–

__LINE__ in C is used to indicate the position of the statement in the source file. Examples are as follows:

    #include < stdio.h>

    main() { printf(“%d\n”,__LINE__); printf(“%d\n”,__LINE__); printf(“%d\n”,__LINE__); };

The program is compiled in Linux with GCC, in Windows VC6.0 under the compilation can pass, the execution results are:

7

8

9

__LINE__ can also be reset with the #line statement, for example:

    #include < stdio.h>

    # line 200 // specify the next row __LINE__ for 200 main () { printf (” % d \ n “, __LINE__); printf(“%d\n”,__LINE__); printf(“%d\n”,__LINE__); };

After compilation and execution, the output is:

202

203

204

——————————————————————————————————————————————————————————————————– —————————————————————————

GCC also supports __func__, which indicates the function, but this keyword is not supported in VC 6.0 under Windows, for example:

    #include < stdio.h> void main() { printf(“this is print by function %s\n”,__func__); }

The output result after compilation is

this is print by function main

Note # “line”, “__LINE__”, “a __FILE__” and “__func__” are case sensitive.

 

Python: Understanding__ str__

The following is my understanding if there is anything wrong with me. Please do tell me. Thank you very much!
In The Python language, successie __str__ is usually formatted this way.
class A:

def __str__(self):

return “this is in str”

Literally, ___ is called by the print function, usually return something. This thing should be in the form of a string. If you don’t want to use the STR () function. If you print a class, print first calls each ___ by str__, such as STR. Py

#!/usr/bin/env python
                                                                                                                                                                                 
class strtest:
    def __init__(self):
        print "init: this is only test"
    def __str__(self):
        return "str: this is only test"

if __name__ == "__main__":
    st=strtest()
    print st

$./str.pyinit: this is only test

str: this is only test
As you can see from the above example, the function with ___ is called when you print an instance of STRtest st.
By default, the python objects almost always have the __str__ function used by print. S the dictionary with ___, see the red part:
> > > dir({})
[‘__class__’, ‘__cmp__’, ‘__contains__’, ‘__delattr__’, ‘__delitem__’, ‘__doc__’, ‘__eq__’, ‘__format__’, ‘__ge__’, ‘__getattribute__’, ‘__getitem__’, ‘__gt__’, ‘__hash__’, ‘__init__’, ‘__iter__’, ‘__le__’, ‘__len__’, ‘__lt__’, ‘__ne__’, ‘__new__’, ‘__reduce__’, ‘__reduce_ex__’, ‘__repr__’, ‘__setattr__’, ‘__setitem__’, ‘__sizeof__’, ‘__str__’, ‘__subclasshook__’, ‘clear’, ‘copy’, ‘fromkeys’, ‘get’, ‘has_key’, ‘items’, ‘iteritems’, ‘iterkeys’, ‘itervalues’, ‘keys’, ‘pop’, ‘popitem’, ‘setdefault’, ‘update’, ‘values’]
> > > t={}
> > > t[‘1’] = “hello”
> > > t[‘2’] = “world”

> > > t
# is equal to print t

{‘1’: ‘hello’, ‘2’: ‘world’}

> > > t.__str__()

“{‘1’: ‘hello’, ‘2’: ‘world’}”

You can see a dictionary, print t and t. str__() are the same. Simply output the contents of the dictionary as a string.
If it’s not a string returned in the function ___, see str1.py

#!/us/bin/env/python                                                                                                                                                                                        
#__metaclass__ = type
#if __name__ == "__main__":
class strtest:
    def __init__(self):
        self.val = 1
    def __str__(self):
        return self.val

if __name__ == "__main__":
    st=strtest()
    print st

$./str1.py

Traceback (most recent call last):
File “./ STR. Py “, line 12, in < module>
print st
TypeError: ___, returned non-string (type int)
Error message with: ___ returned a non-string. Here’s what we should do: see str2. Py

#!/usr/bin/env python                                                                                                                                                                                        
#__metaclass__ = type
#if __name__ == "__main__":
class strtest:
    def __init__(self):
        self.val = 1
    def __str__(self):
        return str(self.val)

if __name__ == "__main__":
    st=strtest()
    print st

$./str2.py

1
We used STR () to change the integer to a character.

Python problem: indenta tionError:expected an Error resolution of indented block

The original address: http://hi.baidu.com/delinx/item/1789d38eafd358d05e0ec1df
   
Python is a very sensitive language for indentation, causing confusion for beginners and even experienced Python programmers, who can fall into the trap. The most common situation is that mixing tabs and Spaces causes errors, or indenting incorrectly, which is impossible to distinguish with the naked eye.
This fault occurs on compile IndentationError: expected an indented block here need to indent, you as long as there is an error in the line, press the space or Tab (but you can’t mix) key indentation.
Often some people will question: I did not indent how or wrong, wrong, the place where the indent should be indent, not indent will be wrong, such as:
If XXXXXX:
(space) XXXXX
or
Def XXXXXX:
(space) XXXXX
There are
For XXXXXX:
(space) XXXXX
The next line of a sentence with a colon is often indented

Oci-22053: overflow error problem

When connecting Oracle in.NET and using dataAdapter fill, the exception of OCI-22053: overflow error occurs, because the data type precision of.NET is smaller than that of Oracle, such as
Select sysdate- ISSUetime as Timediff from sometable returns an excessive precision
Select TRUNc (sysdate-issuetime,2) as Timediff from sometable.
There are other ways to do this online:
http://excel.cnblogs.com/archive/2005/11/14/276202.html using the new ODP.NET da. SafeMapping. Add (field name 1, typeof (System. String)); Method converts all fields to String. But I went to the Oracle website and found that the 9207 version of ODAC is 80M… I’m too lazy to download.

 
The Oracle numeric data type can store up to 38 bytes of precision.
the Oracle value
may become too large when converting the Oracle value to the common language runtime data type. This causes an Oracle OCI-22053 overflow error.
The solution is to use the round function.
How to use the Oracle Round function (rounded)
Description: Returns a value that is rounded to the specified number of decimal digits.
SELECT ROUND( number, [ decimal_places ] ) FROM DUAL
Parameters:
Number: The number you want to process
Decimal_places: Round up and take a few decimal places (default is 0)
Sample :
Select round (123.456) from dual; The back 123
Select round(123.456, 0) from Dual; The back 123
Select round(123.456, 1) from Dual; The back 123.5
Select round(123.456, 2) from Dual; The back 123.46
Select round(123.456, 3) from Dual; The back 123.456
Select round(-123.456, 2) from dual; The back to 123.46
 
From:
http://blog.csdn.net/xeonol/article/details/726133

error C2057: expected constant expression (Can the size of an array in C language be defined when the program is running?)

Can the size of an array be defined at run time?
no. In the definition of an array, the size of the array must be known at compile time, not at run time. For example, if I is a variable, you cannot use I to define the size of an array:
char array[I]; Notvalidc */
supports this definition in some languages, but not in C. If C supported this definition, the stack would become more complex, the overhead of calling functions would be greater, and the program would run significantly slower.
if the size of the array is known at compile time, even if it is a very complex expression, you can define it as long as it can be calculated at compile time. If you want to use an array whose size is not known until the program is running, you can specify a pointer and call the malloc() or calloc() functions to allocate memory space for the array from the heap. Here is an example of an argv array that is copied to the main() function:

[cpp]
view plain
copy

    7.15 cases in row to determine the size of the array, use the pointer and the malloc ()/* A silly program that copies the argv array and all the pointed – to strings. Just for fun, it also deallocates all the copies. */# include & lt; Stdlib. H> # include & lt; String. H> Int main (int arg c, char * * argv) {char * * new_argv; Int I;/* Since argv [0] through argv [arg c] are all valid, the program needs to the allocate room for arg c + 1 Pointers. */new_argv = (char * *) calloc (arg c + l, sizeof (char *));/* or malloc ((arg c + 1) * sizeof (char *)) */printf (” allocated room for % d Pointers starting at % P \ n “, arg c + 1, new_argv);/* now copy all the strings more (argv [0] through argv [arg c – l]) */for (I = 0; i< argc; + + I) {/ * make room for ‘\ 0’ at end, too */new_argv [I] = (char *) malloc (strlen (argv [I]) + l); Strcpy (new_argv [I], argv [I]); Printf (” % d bytes allocated for new_argv [% d] at % P “, “copied \” % s \ \ “n”, strlen (argv [I]) + l, I, new_argv [I], new_argv [I]); } new_ argv [arg c] = NULL:/* To deallocate everything, get rid of the strings (in any order), then the array of Pointers. If you free the array of poiners first, you lose all the reference To t (I = 0); i< argc; + + I) {free (new_argv [I]); Printf (” freed new_argv [% d] at % P \ n “, I, new_argv [I]); Argv [I] = NULL; * * Habit, see note at the end of this example */} free(new_argv); Printf (” Freed new_argv itself at %P\n”, new_argv); Return 0; /* see 16.4 */}

Note: Why does example 7.5 assign NULL after freeing each element in the new_argv array?This is a habit formed on the basis of long practice. After a pointer is released, you can no longer use the data it originally pointed to, or the pointer is “suspended” and no longer points to any useful data. If a pointer is assigned NULL immediately after it is released, the program will not make an error even if it USES the pointer again. Of course, the program may indirectly refer to the null pointer, but such errors can be detected in time while debugging the program. In addition, a
program may still have some original copies of the pointer pointing to the portion of memory that has been freed, which is natural in C programs. In short, although this habit doesn’t solve all problems, it does help.

matlab Error Subscript indices must either be real positive integers or logicals.

Matlab errors: Subscript Indices must either be real positive integers or Logicals.Subscript index must be of positive integer type or logical type

Cause of error: in the process of accessing the matrix (including vector, two-dimensional matrix, multidimensional array, same below), the index of the subscript either starts at 0 or has a negative number. Note: The syntax of MATLAB stipulates that the index of the matrix starts from 1, which is different from the habit of programming languages such as C.

Solution: Debug the program yourself and fix subscripts that are zero or negative.

I made a mistake when I was writing the program. I should have done the transpose of the matrix, but I forgot…