Notes by Dr. Xi

Displaying notes 81 - 90
Created by Dr. Xi on December 04, 2009 04:44:40
From Perldoc : The special literals __FILE__, __LINE__, and __PACKAGE__ represent the current filename, line number, and package name at that point in your program. They may be used only as separate tokens; they will not be interpolated into strings. If there is no current package (due to an empty package; directive), __PACKAGE__ is the undefined value. The two control characters ^D and ^Z, and the tokens __END__ and __DATA__ may be used to indicate the logical end of the script before the actual end of file. Any following text is ignored. Text after __DATA__ may be read via the filehandle PACKNAME::DATA , where PACKNAME is the package that was current when the __DATA__ token was encountered. The filehandle is left open pointing to the ...
Created by Dr. Xi on December 04, 2009 04:33:05
Variable Meaning $_ The default or implicit variable. @_ Within a subroutine the array @_ contains the parameters passed to that subroutine. $a, $b Special package variables when using sort() $<digit> Contains the subpattern from the corresponding set of capturing parentheses from the last pattern match, not counting patterns matched in nested blocks that have been exited already. $. Current line number for the last filehandle accessed. $/ The input record separator, newline by default. $| If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Default is 0 (regardless of whether the channel is really buffered by the system or not; $| tells you only whether you've asked Perl explicitly to flush after ...
Created by Dr. Xi on November 23, 2009 23:37:55    Last update: November 24, 2009 04:04:20
IE can be started from JScript as an ActiveX control. Create a file named start_ie.js with the following contents and run (from command line or Run box): var browser = new ActiveXObject("InternetExplorer.Application"); // the following two lines are not necessary. They are here just to show that you can associate // properties to the browser object. browser.putProperty("question", "123uiotuer4"); var q = browser.getProperty("question"); browser.visible = true; // default is false browser.navigate('http://www.google.com/search?q=' + q);
Created by Dr. Xi on November 21, 2009 02:07:07    Last update: November 21, 2009 02:08:19
This is from Oracle 10g documentation . Data Lock Conversion Versus Lock Escalation [/size] A transaction holds exclusive row locks for all rows inserted, updated, or deleted within the transaction. Because row locks are acquired at the highest degree of restrictiveness, no lock conversion is required or performed. Oracle automatically converts a table lock of lower restrictiveness to one of higher restrictiveness as appropriate. For example, assume that a transaction uses a SELECT statement with the FOR UPDATE clause to lock rows of a table. As a result, it acquires the exclusive row locks and a row share table lock for the table. If the transaction later updates one or more of the locked rows, the row share table lock is automatically converted to a ...
Created by Dr. Xi on November 20, 2009 16:00:19
It is generally believed that unindexed foreign keys cause deadlocks in Oracle. But look at this interesting blog post by Tom Kyte: http://tkyte.blogspot.com/2006/11/interesting-post.html Nonetheless, identifying unindexed foreign keys may still be helpful (also by Tom): column columns format a20 word_wrapped column table_name format a30 word_wrapped select decode( b.table_name, NULL, '****', 'ok' ) Status, a.table_name, a.columns, b.columns from ( select substr(a.table_name,1,30) table_name, substr(a.constraint_name,1,30) constraint_name, max(decode(position, 1, substr(column_name,1,30),NULL)) || max(decode(position, 2,', '||substr(column_name,1,30),NULL)) || max(decode(position, 3,', '||substr(column_name,1,30),NULL)) || max(decode(position, 4,', '||substr(column_name,1,30),NULL)) || max(decode(position, 5,', '||substr(column_name,1,30),NULL)) || max(decode(position, 6,', '||substr(column_name,1,30),NULL)) || max(decode(position, 7,', '||substr(column_name,1,30),NULL)) || max(decode(position, 8,', '||substr(column_name,1,30),NULL)) || max(decode(position, 9,', '||substr(column_name,1,30),NULL)) || max(decode(position,10,', '||substr(column_name,1,30),NULL)) || max(decode(position,11,', '||substr(column_name,1,30),NULL)) || max(decode(position,12,', '||substr(column_name,1,30),NULL)) || max(decode(position,13,', '||substr(column_name,1,30),NULL)) || max(decode(position,14,', '||substr(column_name,1,30),NULL)) || max(decode(position,15,', '||substr(column_name,1,30),NULL)) || max(decode(position,16,', '||substr(column_name,1,30),NULL)) columns from user_cons_columns a, user_constraints b ...
Created by Dr. Xi on November 18, 2009 22:53:33    Last update: November 18, 2009 22:56:17
The "View Source" function in browsers displays the HTML source as it is received from the server. It does not show the HTML source after the DOM structure has been altered by JavaScript. Sometimes you want to see the HTML source as it is currently rendered in the browser. For Firefox: Without using any extension: select an area of the page, right click and select "View Selection Source" Using Firebug : click the HTML tab double click the body tag to edit copy all text in the edit panel and paste to your favorite editor. Using View Source Chart : right click and select "View Source Chart" For IE: Use View Rendered Source by Bill Friedrich: right click and select "View Rendered Source" For all ...
Created by Dr. Xi on November 15, 2009 21:56:19    Last update: November 15, 2009 21:57:59
Python doesn't seem to have a built-in function to find an object in a list that satisfies a specified criterion, for example, making a function f to return True . To find jack among people : jack = None for p in people: if p.first_name == 'Jack': jack = p break This is not a lot of code, but it's not terse enough as you would expect of Python. Some suggestions are offered here: http://dev.ionous.net/2009/01/python-find-item-in-list.html http://tomayko.com/writings/cleanest-python-find-in-list-function
Created by Dr. Xi on November 15, 2009 21:44:23
Python lists are enclosed in square brackets. When a list of objects are enclosed in parentheses it is a tuple (an immutable list). List comprehensions are enclosed in square brackets. But when you change the square brackets to parentheses, you get a generator not a tuple ! >>> l = [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> t = (1, 2, 3, 4, 5, 6, 7, 8, 9) >>> type(l) <type 'list'> >>> type(t) <type 'tuple'> >>> l2 = [i for i in l if i % 2 != 0] >>> l2 [1, 3, 5, 7, 9] >>> g1 = (i for i in l if i % 2 != 0) >>> type(g1) <type 'generator'> >>> g2 = (i for i in ...
Created by Dr. Xi on November 13, 2009 20:48:51    Last update: November 14, 2009 03:27:14
Create a "Hello World" script: if __name__ == "__main__": print "Hello World!" start the python interpreter and run the script with execfile : >>> execfile('hello.py') Hello World! >>> print execfile.__doc__ execfile(filename[, globals[, locals]]) Read and execute a Python script from a file. The globals and locals are dictionaries, defaulting to the current globals and locals. If only globals is given, locals defaults to it. >>>
Created by Dr. Xi on November 13, 2009 16:59:10    Last update: November 13, 2009 20:27:04
When you set DEBUG=True in settings.py , Django saves a copy of every SQL statement it has executed in django.db.connection.queries : >>> from django.db import connection >>> connection.queries [{'sql': 'SELECT polls_polls.id,polls_polls.question,polls_polls.pub_date FROM polls_polls', 'time': '0.002'}] You can clear the list of saved queries by calling django.db.reset_queries() : >>> from django import db >>> db.reset_queries() >>> Example: from django.db import models class Author(models.Model): name = models.CharField(max_length=50) email = models.EmailField() def __unicode__(self): return self.name class Blog(models.Model): author = models.ForeignKey(Author) name = models.CharField(max_length=100) def __unicode__(self): return self.name class Entry(models.Model): blog = models.ForeignKey(Blog) title = models.CharField(max_length=255) text = models.TextField() def __unicode__(self): return self.title >>> a = Author(name='author', email='a@domain.com') >>> a.save() >>> b = Blog(author=a, name='First Blog') >>> b.save() >>> e = Entry(blog=b, title='The First Article', text='simply a test') >>> ...
Previous  4 5 6 7 8 9 10 11 12 13 Next