Notes by Dr. Xi
Displaying keyword search results 1 - 10
Created by Dr. Xi on February 06, 2012 12:14:11
Last update: February 07, 2012 15:39:35
Oracle sqlplus command line tools does not support command line editing out-of-the-box. But on Linux there's a handy utility that enables command line editing with any command line tool: rlwrap - readline wrapper.
Install rlwrap:
$ sudo apt-get install rlwrap
Create a keywords file .sql.dict (optional, but convenient):
false null true
access add as asc begin by chec...
It would be nice to add the tables names also.
Create an alias for sqlplus (put it in .bashrc ):
alias sqlplus='rlwrap -f $HOME/.sql.dict sqlplus'
Created by Dr. Xi on October 01, 2007 03:26:46
Last update: August 25, 2011 08:57:40
Use the sub function in the re module to do global replacement:
import re
re.sub(pattern, replacement, inpu...
Created by Dr. Xi on July 14, 2011 11:47:48
Last update: July 14, 2011 11:47:48
The String.trim function trims spaces from both ends. There's no built-in function to trim only the right side or left side.
To right trim:
String trimmed = original.replaceAll("\\s+$", "");
To left trim:
String trimmed = original.replaceAll("^\\s+", "");
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 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 Dr. Xi on December 24, 2009 22:25:38
Last update: April 04, 2011 13:48:24
Use the urlparse module to parse a URL into parts.
The urlparse function parses a URL into six components, returning a 6-tuple. This corresponds to the general structure of a URL: scheme://netloc/path;parameters?query#fragment
>>> from urlparse import urlparse
>>> parts = u...
Created by Dr. Xi on March 08, 2011 15:53:33
Last update: March 08, 2011 15:53:33
Use the date_format function to format a date:
mysql> select now() now;
+---------------------...
Created by Dr. Xi on March 07, 2011 16:23:40
Last update: March 07, 2011 16:25:05
Oracle operator || doesn't work for MySQL. Looks like I have to use the concat function:
mysql> select 'abc' || '123';
+----------------...
Created by Dr. Xi on February 25, 2011 08:43:40
Last update: February 28, 2011 11:16:10
If you think the JavaScript code below is simple, think again. Try it in different browsers and see if you can explain what you see.
What is displayed in the browser window with this HTML page?
<!doctype html>
<html>
<body>
<p>befor...
What is displayed inside the iframe? Try different browsers.
<!doctype html>
<html>
<head>
<style t...
Created by Dr. Xi on February 09, 2011 15:35:41
Last update: February 09, 2011 15:36:08
Perl BEGIN and END blocks are executed at the beginning and at the end of a running Perl program. By the Perl doc : A BEGIN code block is executed a s soon as possible , that is, the moment it is completely defined, even before the rest of the containing file (or string) is parsed . You may have multiple BEGIN blocks within a file (or eval'ed string); they will execute in order of definition. Because a BEGIN code block executes immediately, it can pull in definitions of subroutines and such from other files in time to be visible to the rest of the compile and run time. Once a BEGIN has run, it is immediately undefined and any code it used is returned...