Recent Notes

Displaying notes 81 - 90
Created by James on November 22, 2009 05:50:19
To add a DIV after the last element in body or before the first element: // append to the end of body var d1 = document.createElement('DIV'); d1.innerHTML = '<h1>Footer</h1>'; document.body.appendChild(d1); // insert before the first child var d2 = document.createElement('DIV'); d2.innerHTML = '<h1>Header</h1>'; document.body.insertBefore(d2, document.body.firstChild);
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 James on November 19, 2009 04:55:01
JavaScript <script type="text/javascript"> <!-- if (document.images) { var img = new Image(80,20); img.src="http://www.thedomain.com/images/cool-pic.png"; } //--> </script> CSS <img src="http://www.thedomain.com/images/cool-pic.png" style="display:none;">
Created by James on November 18, 2009 23:11:48
It turned out the removing the underline decoration from an element is not that trivial. The underline could have been introduced by any containing element up in the DOM tree! Try this page: <!doctype html> <html> <head> <style type="text/css"> div.underline,th.underline { text-decoration: underline; } div,th,span { font-style: italic; text-decoration: none; } table { border-collapse: collapse; } td,th { border: #ddd 1px solid; padding: 4px; } </style> </head> <body> <table> <tr> <th class="underline">Column 1</th> <th class="underline"> <span>Column 2</span>&nbsp;&nbsp;<img src="arrow.jpg"> </th> </tr> <tr> <td>Value 11</td> <td>Value 12</td> </tr> <tr> <td>Value 21</td> <td>Value 22</td> </tr> </table> <div class="underline"> <div> <span>Underlined DIV</span>&nbsp;&nbsp;<img src="arrow.jpg"> </div> </div> </body> </html>
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