Recent Notes
Displaying keyword search results 21 - 31
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 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_...
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 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 April 22, 2007 21:58:45
Last update: January 19, 2009 20:26:12
Your code will be syntax highlighted when you specify the language of your code with the BBcode code tag:
[code=lang] Your code here [/code]
where "lang" is the language of your code. For example, the following Perl code
#!/usr/bin/perl
print "Hello World!\n";
is rendered with:
[code=perl]
#!/usr/bin/perl
print "Hel...
The following are supported languages and their corresponding names for BBcode:
Apache conf: apacheconf, aconf, apache
Bash...
The full list is available from http://pygments.org/ , which is our backend engine for syntax highlight rendering.
Created by Dr. Xi on September 21, 2008 21:04:24
Last update: September 21, 2008 22:27:36
IE uses Notepad as the default editor when you select "View Source" from a web page. You can change it to your favorite editor by adding a couple of keys to the registry: Start regedit Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\ Add key View Source Editor Under View Source Editor , add key Editor Name Change the default string value to the full path of your favorite editor. The following is the registry entry for vim (full tip for vim is available from the vim wiki ):
Windows Registry Editor Version 5.00 [HKEY_... It is probably easier (less error prone) to edit this in a file and import it back into the registry. The contents of gvim.vbs are: '--- gVim.vbs ------------------------------------... It is OK to use gvim.exe...
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"...
Created by Dr. Xi on August 10, 2007 20:43:10
Last update: August 10, 2007 20:43:10
IE and firefox both support client side XSLT.
This can be done by inserting an xml-stylesheet into the XML file, which would trigger the browser to apply the XSL to the XML document and generate a transformed page:
<?xml version="1.0" encoding="utf-8" ?>
<?...
Or, it can be done more dynamically with client side JavaScript. However, IE and FF offer different APIs for XSLT. Below is my attempt to bridge the differences. It's been tested to work for IE 7.0, FF 2.0 and Opera 9.0.2.
function XSLT(url) {
var xslt = false;
...
The following HTML page shows how to use it:
<HTML>
<HEAD>
<SCRIPT language="JavaS...