Recent Notes
Displaying keyword search results 1 - 10
Created by magnum on October 20, 2011 20:44:23
Last update: October 20, 2011 20:53:26
Copied verbatim from The GNU C Library Manual . When you have finished using a socket, you can simply close its file descriptor with close ; see Opening and Closing Files . If there is still data waiting to be transmitted over the connection, normally close tries to complete this transmission. You can control this behavior using the SO_LINGER socket option to specify a timeout period; see Socket Options . You can also shut down only reception or transmission on a connection by calling shutdown , which is declared in sys/socket.h . Function: int shutdown (int socket, int how) The shutdown function shuts down the connection of socket socket. The argument how specifies what action to perform: 0 - Stop receiving data for this socket....
Created by magnum on October 06, 2011 14:35:20
Last update: October 06, 2011 14:35:20
The longjmp function jumps to the line where setjmp was last called. In return, setjmp returns the value passed in as the second parameter to longjmp .
#include <stdio.h>
#include <stdlib.h>
#incl...
Result:
$ ./longjmp
val is 0
val is 1
--> val is ...
Created by magnum on September 24, 2011 13:14:37
Last update: September 28, 2011 18:08:35
There are two sides to an IP socket: the local side and the remote side:
The getpeername function retrieves the peer address of the specified socket.
#include <sys/socket.h>
int getpeername(int soc...
Example:
struct sockaddr_in addr;
socklen_t socklen = si...
The getsockname function retrieves the locally-bound name of the specified socket.
#include <sys/socket.h>
int getsockname(int soc...
Example:
struct sockaddr_in addr;
socklen_t socklen = si...
Created by magnum on September 11, 2011 19:46:09
Last update: September 11, 2011 19:46:09
A pair of C functions convert between an Internet address and a string (ASCII):
#include <arpa/inet.h>
/*
* Returns a poin...
However , these functions do not support IPv6. The new pair is:
#include <arpa/inet.h>
/* Convert a Internet ad...
Examples:
#include <sys/socket.h>
#include <netinet/in.h>...
Created by jinx on May 03, 2011 11:43:26
Last update: May 03, 2011 11:43:26
The PHP function strval returns the string value of a variable. It does the same thing as casting a variable to string, or automatic conversion where string is expected.
Conversion rules:
Type String Value
Boolean TRUE '1'
Boolean FALSE '' (empty string)
integer of float string representing the number
Array The string 'Array'
Object Result of __toString() if defined, error otherwise
Resource 'Resource id #n' , where n is a number assigned to the resource.
NULL '' (empty string)
Example:
<?php
set_error_handler(function($errno, $errst...
Results:
bool(true)
---------------------
strval: '1'...
Created by jinx on May 02, 2011 12:14:23
Last update: May 02, 2011 12:15:07
The PHP function ctype_digit returns true when all characters in a string is numeric. Use this function only on strings. You get unexpected results with other data types.
Example:
<?php
$a = array("124.34", "00088760", "1.3e5",...
Results:
string(6) "124.34"
-----------------
ctype_d...
Created by jinx on April 29, 2011 13:43:13
Last update: April 29, 2011 13:44:34
List of functions testing variable type:
Function Description
is_bool Finds out whether a variable is a boolean
is_double Alias of is_float()
is_float Finds whether the type of a variable is float
is_int Find whether the type of a variable is integer
is_integer Alias of is_int()
is_long Alias of is_int()
is_null Finds whether a variable is NULL
is_numeric Finds whether a variable is a number or a numeric string
is_object Finds whether a variable is an object
is_real Alias of is_float()
is_scalar Finds whether a variable is a scalar
is_string Find whether the type of a variable is string
Test code:
<?php
class A {
}
$a = ar...
Output:
var_dump: int(1)
-------------------------
i...
Created by jinx on April 26, 2011 11:58:33
Last update: April 26, 2011 12:00:40
The PHP function array_unique removes duplicate values from arrays. It takes an optional parameter $sort_flags , which can be one of:
SORT_REGULAR : compare items normally (don't change types)
SORT_NUMERIC : compare items numerically
SORT_STRING : compare items as strings
SORT_LOCALE_STRING : compare items as strings, based on the current locale.
Example:
<?php
$a = array(
'1' => 'Apple',
...
Output:
array_unique results:
array(3) {
[1]=>
...
Created by Dr. Xi on April 18, 2011 12:10:37
Last update: April 18, 2011 12:14:24
Python defines a long list of special methods to customize class behavior. This is a short list for the Basic Customizations . Method Description object.__new__(cls[, ...]) Called to create a new instance of class cls. __new__() is a static method (special-cased so you need not declare it as such) that takes the class of which an instance was requested as its first argument. __new__() is intended mainly to allow subclasses of immutable types (like int, str, or tuple) to customize instance creation. It is also commonly overridden in custom metaclasses in order to customize class creation. object.__init__(self[,...]) Called when the instance is created. The arguments are those passed to the class constructor expression. If a base class has an __init__() method, the derived class’s __init__()...
Created by jinx on April 16, 2011 13:08:50
Last update: April 16, 2011 13:09:13
There are two functions:
int strcasecmp (string $str1 , string $str2) : binary safe case-insensitive string comparison.
int strnatcasecmp (string $str1 , string $str2) : case insensitive string comparisons using a "natural order" algorithm (a comparison algorithm that orders alphanumeric strings in the way a human being would).
In both cases the function returns:
< 0 if str1 is less than str2
= 0 if str1 is equal to str2
> 0 if str1 is greater than str2