Recent Notes

Displaying keyword search results 1 - 10
Created by Dr. Xi on April 16, 2014 16:15:27    Last update: April 16, 2014 16:15:27
Create a list, assign it to another variable. They both refer to the same object: >>> a = [ 1, 2, 3, 4 ] >>> b = a >>> a [1... List comprehension, assign value to a . Now a and b are different: >>> a = [ e for e in a if e > 2 ] >>> a [3, ... Splicing changes list in place, a and b refer to the same object after assignment: >>> a = b >>> a[:] = [ e for e in a if e > 2 ] ...
Created by James on April 24, 2012 13:50:05    Last update: April 24, 2012 13:50:05
The this object can be changed when calling a JavaScript function with func.call(theObject) . This is an example: <!DOCTYPE html> <html> <head> <title>jQu... The JavaScript console logs: [Global log] this is: [object Window] [log.cal...
Created by James on March 16, 2010 16:55:51    Last update: March 16, 2010 19:29:28
I had this seemingly innocent code that did not work: <html> <body> <script language="JavaScript"... I fired up the Chrome JavaScript console and it told me that: Uncaught TypeError: object is not a function . When the name sameAsInputName appeared in the inline event handler, the browser thinks that it refers to the input field(s), not the JavaScript function! It works as expected if you attach the event handler later: <html> <body> <script language="JavaScript"...
Created by James on July 05, 2009 02:21:15    Last update: July 05, 2009 02:25:20
This is a JavaScript wrapper for Bare Naked App's progress bar. As usual, download their images and add this to the CSS: img.progressBar { background: white url(images... Then, add my JavaScript function, which takes a parent HTML element as input and returns the progress bar object with a setValue method: function createProgressBar(elem) { var img = d... Test code: <html> <head> <!-- setup code START --> ...
Created by Dr. Xi on January 29, 2009 21:33:44    Last update: January 30, 2009 17:43:33
You can use applet , object , or embed tags to embed an applet in your HTML page. However, The applet tag is interpreted by both IE and Mozilla family of browsers. The applet tag won't automatically download a JRE if the Java Plug-in isn't already installed. The object tag works only for IE The embed tag works only for Mozilla family of browsers, i.e., Firefox. Use applet tag: <applet code="MyApplet.class" width="200" ... Use object tag: <!-- latest JRE --> <OBJECT classid="clsid:... Use embed tag: <!-- highest JRE that supports MIME type ... Mixed object and embed tag: <object classid="clsid:8AD9C840-044E-11D1-B3E9... You need to use a different name for the Mozilla embed tag and use that name to refer to the applet...
Created by Dr. Xi on January 30, 2009 16:57:12    Last update: January 30, 2009 17:25:36
The scriptable attribute defaults to false . However, even when you set it to true , there is a time delay between when the applet is loaded and when it becomes scriptable . The following code may fail: <html><body> <object classid="clsid:8AD9C840-04... You need to wrap the JavaScript like this: <script language="JavaScript" type="text/javascrip...
Created by Dr. Xi on September 01, 2008 01:01:59    Last update: September 02, 2008 15:55:05
In JavaScript, null is not the same as "undefined". The value null is an object, while "undefined" is, well, undefined. However, for undefined variable a , if (a){...} throws exception, but if (window.a) {...} returns false , even though they are the same thing! // 1. for undefined variable a, typeof functio...
Created by Dr. Xi on January 09, 2008 03:47:31    Last update: August 31, 2008 16:33:28
Many times I need to test some JavaScript snippet before writing code. Maybe I forgot how some JavaScrpit function is supposed to work, maybe I saw some tricky JavaScript code and needed to figure out how it worked. I used MS scripting host for while, but found it cumbersome. Plus, DOM objects are not available in the scripting host. Below is a simple HTML page I created for this task. You can use the Logger.debug method to output debugging messages. <html> <head> <script language="JavaScript" ... For example, if you enter Logger.debug(unescape('http%3a%2f%2fwww.56.com%2fn... into the text area and click "Execute", you get the following output: http://www.56.com/n_v166_/c33_/17_/ bcd [obj...
Created by Dr. Xi on December 12, 2007 20:30:01    Last update: December 12, 2007 20:32:23
This is a script to tail a log file through the web browser. It uses AJAX, apache web server, mod_python, UNIX utilities tail (requires the --lines switch) and wc . The log file may reside on the web server or any other host accessible from the web server through SSH. Although it's written in python, it should be easy to port to other languages such as Perl. Apache httpd.conf : LoadModule python_module modules/mod_python.so ... Python script: import time, os from os.path import basename ...
Created by Dr. Xi on November 15, 2007 04:40:44    Last update: November 15, 2007 04:40:44
Here's some simple Ajax code. The Ajax response is delivered as XML with attributes and an array of data payloads contained in CDATA sections: <?xml version="1.0" encoding="utf-8"?> <ajax-re... And the JavaScript that does the Ajax magic: // ajax.js function ajaxGet(url, ajaxCallback) ... And the HTML test code: <html> <head> <script language="JavaScript"...