Recent Notes

Displaying keyword search results 31 - 40
Created by jinx on April 25, 2011 12:43:40    Last update: April 25, 2011 12:43:40
Use the PHP function method_exists to check if the class or object has a certain method. It returns TRUE if the method exists (even when the value of the property is NULL), FALSE if the method does not exist. Example: <?php class A { var $p = 'A property'; ... Outputs: Class A has method f1: bool(true) Object $a has... Also note that C++-like method overloading does not exist in PHP. Thus there's no ambiguity about which version of the method exists, i.e., with no argument, with one argument... etc. The following code generates Fatal error: <?php class A { var $p = 'A property'; ...
Created by jinx on April 25, 2011 11:50:09    Last update: April 25, 2011 11:51:53
Use the PHP function property_exists to check if the class or object has a certain property. It returns TRUE if the property exists (even when the value of the property is NULL), FALSE if the property does not exist, or NULL in case of an error. Example: <?php class A { var $p = 'A property'; ... Outputs: Class A has property $p: bool(false) Class A ha...
Created by jinx on April 20, 2011 09:28:01    Last update: April 20, 2011 09:28:46
This code fragment shows how to find the previous Sunday using PHP date/time functions. <?php $current_time = time(); $last_sunday =... Sample output: Current time: 1303316297 Last Sunday same time:...
Created by jinx on April 20, 2011 08:40:38    Last update: April 20, 2011 08:48:09
The PHP function time returns the current time in seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). This is the same function as the Perl time() . <?php print time() . "\n"; ?> Calling mktime without any arguments does the same: <?php echo mktime(), "\n"; ?>
Created by jinx on April 19, 2011 20:43:02    Last update: April 19, 2011 20:43:02
A literal PHP string can be enclosed between single quotes or double quotes. For single quoted string, nothing is escaped except \\ and \' , which represents a literal backslash and literal single-quote. You can also have octal and hex escapes double quoted literal strings. <?php print 'A single quoted string' . "\n"... Outputs: A single quoted string A double quoted string ...
Created by jinx on April 19, 2011 20:30:20    Last update: April 19, 2011 20:30:20
The PHP constant __FILE__ is the current file name, __LINE__ is the current line number. These can be helpful writing error logs. <?php // __LINE__ is the current line numbe... Outputs: Current file is C:\scrap\test2.php, current line n...
Created by Dr. Xi on April 19, 2011 16:01:39    Last update: April 19, 2011 16:01:39
This note relates to Python 2.x. A Python class is old-style by default, unless it has another new style class or the "top level" class object as its parent. The sure way to tell that an object is an instance of a new style class is to use the function type , type(x) returns <type 'instance'> for an old-style class, but it returns <class 'ClassType.X'> for a new-style class. Class definition: class A: # old style class def __init__(sel... Test session: >>> A <class ClassType.A at 0x7f36ae442fb0> ...
Created by jk34 on April 19, 2011 15:42:24    Last update: April 19, 2011 15:42:24
Check the __name__ variable to see if the Python module was invoked from the command line. The line prints when the Python script is called from the command line, but doesn't print when it is imported by another Python module with import MyModule . if __name__ == '__main__': print 'Invoked f...
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 freyo on April 06, 2011 14:50:01    Last update: April 06, 2011 15:00:03
C:\tmp>keytool -printcert -file CERT.pem keytoo...
Previous  1 2 3 4 5 6 7 8 9 10 Next