Notes by Dr. Xi
Displaying notes 131 - 140
Created by Dr. Xi on October 02, 2008 21:35:59
Last update: January 11, 2011 19:51:26
This page demos a pop up window centered on the screen. In the demo tab, the pop up be centered relative to the tab panel.
<html>
<head>
<script language="JavaScript" ...
Created by Dr. Xi on September 11, 2008 22:55:01
Last update: January 11, 2011 19:48:19
<html>
<head>
<script language="JavaScript">...
Created by Dr. Xi on March 26, 2008 20:11:53
Last update: January 11, 2011 19:47:07
Suppose you have a select box like this in your HTML:
<select id="selectbox">
<option value="1">O...
and you want to use jQuery to select the last option, use this code:
$("#selectbox option:last").attr("selected", t...
Consult the jQuery documentation for more details.
Created by Dr. Xi on November 03, 2007 17:36:24
Last update: January 10, 2011 22:22:43
When rendering an HTML form, it is customary to use an icon to indicate that a field is required. You can render the icon in HTML directly, but it's a lot more convenient to use CSS. Here's the CSS:
label.required {
background: url(/img/requ...
And the HTML:
<label class="required">A required field</labe...
Created by Dr. Xi on August 21, 2007 21:25:58
Last update: January 10, 2011 22:19:09
You can grab some animated icons here: http://mentalized.net/activity-indicators/ . And here's some code to demonstrate how to use such an icon.
<html>
<head>
<script language="JavaScript"...
However, if you use Ajax and send a synchronous request, the icon won't show up at all, i.e., the following code doesn't work:
function eventHandler() {
startBusy();
...
This works:
function eventHandler() {
startBusy();
...
Created by Dr. Xi on April 26, 2007 23:00:25
Last update: January 10, 2011 22:15:32
If you ever wonder how those "cool" dialog boxes are made, copy and paste the following code to a file and test it with your browser. This is probably the simplest code for such effects. If you don't know what I mean, try it anyway.
<html>
<head>
<title>Test Overlay</ti...
Created by Dr. Xi on January 09, 2011 21:14:52
Last update: January 09, 2011 21:14:52
The string method split does not take regular expression, to split with a regex, you have to use regex split :
>>> a = 'a\r\nb\r\nc'
>>> a.split('\n')
['a\...
Created by Dr. Xi on January 08, 2011 15:06:17
Last update: January 08, 2011 15:06:17
For Python regular expression (regex) the groups method returns a tuple containing all sub-groups of the match, from group 1 to the last. The number of groups returned is determined by the regex, not the actual matching action. Optional groups are returned as None if not present in the match (unless a default value is provided to the groups method). So there's no need to count the number of groups matched (you know it when you write the regex).
In the following I try to match a phone number where the area code is optional, the number of groups matched is always 2:
>>> m = re.search('(\d\d\d)?(\d\d\d-?\d\d\d\d)', '...
Created by Dr. Xi on November 30, 2010 08:56:11
Last update: November 30, 2010 08:56:11
Focus on the checkbox.
press the Space bar!
Created by Dr. Xi on November 29, 2010 13:08:05
Last update: November 30, 2010 08:51:34
This sample code sets up a server socket on a specified address and port. I use it to test port binding conflicts.
import java.net.*;
public class SocketBind ...
Note: " netstat -ano " also gives you information on active TCP connections, including listening ports. But there are cases where netstat reports nothing and bind still fails.