JavaScript 正则表达式简单字符串搜索/替换转义方法(使用RE速度增强 - 预编译)

RegExp.escape = function(text) {
  if (!arguments.callee.sRE) {
    var specials = [
      '/', '.', '*', '+', '?', '|',
      '(', ')', '[', ']', '{', '}', '\\\\'
    ];
    arguments.callee.sRE = new RegExp(
      '(\\\\' + specials.join('|\\\\') + ')', 'g'
    );
  }
  return text.replace(arguments.callee.sRE, '\\\\$1');
}

JavaScript array_insert

Array.prototype.insert = function( index, item ) {
	this.splice( index, 0, item );
}

var arr = [ 1, 2, 3, 4, 5 ];
alert( arr.insert( 3, 6 ) ); // 1,2,3,6,4,5

JavaScript string_camelize

String.prototype.camelize = function( ) {
	return this.replace( /-([a-z])/g,
		function( $0, $1 ) { return $1.toUpperCase( ) } );
}

alert( "get-element-by-id".camelize( ) ); 
//getElementById

JavaScript string_center,rjust,ljust

String.prototype.ljust = function( width, padding ) {
	padding = padding || " ";
	padding = padding.substr( 0, 1 );
	if( this.length < width )
		return this + padding.repeat( width - this.length );
	else
		return this;
}
String.prototype.rjust = function( width, padding ) {
	padding = padding || " ";
	padding = padding.substr( 0, 1 );
	if( this.length < width )
		return padding.repeat( width - this.length ) + this;
	else
		return this;
}
String.prototype.center = function( width, padding ) {
	padding = padding || " ";
	padding = padding.substr( 0, 1 );
	if( this.length < width ) {
		var len		= width - this.length;
		var remain	= ( len % 2 == 0 ) ? "" : padding;
		var pads	= padding.repeat( parseInt( len / 2 ) );
		return pads + this + pads + remain;
	}
	else
		return this;
}

alert( "Ruby".center( 10 ) );      // "   Ruby   "
alert( "Ruby".rjust( 10 ) );       // "      Ruby"
alert( "Ruby".ljust( 10 ) );       // "Ruby      "
alert( "Ruby".center( 10, "+" ) ); // "+++Ruby+++"

Java Thread.java

/**
     * Causes the currently executing thread to sleep (cease execution) 
     * for the specified number of milliseconds plus the specified number 
     * of nanoseconds. The thread does not lose ownership of any monitors.
     *
     * @param      millis   the length of time to sleep in milliseconds.
     * @param      nanos    0-999999 additional nanoseconds to sleep.
     * @exception  IllegalArgumentException  if the value of millis is 
     *             negative or the value of nanos is not in the range 
     *             0-999999.
     * @exception  InterruptedException if another thread has interrupted
     *             the current thread.  The <i>interrupted status</i> of the
     *             current thread is cleared when this exception is thrown.
     * @see        java.lang.Object#notify()
     */
    public static void sleep(long millis, int nanos) 
    throws InterruptedException {
	if (millis < 0) {
            throw new IllegalArgumentException("timeout value is negative");
	}

	if (nanos < 0 || nanos > 999999) {
            throw new IllegalArgumentException(
				"nanosecond timeout value out of range");
	}

        // Et là, c'est la grosse arnaque!!!
	if (nanos >= 500000 || (nanos != 0 && millis == 0)) {
	    millis++;
	}

	sleep(millis);
    }

C++ 如何对某些成员函数和/或变量进行分组(使用doxygen)

/** @name One example group
 * 
 */
//{@
	void function_example();
	int example;
//@}

HTML 与墨西哥各州下拉(选择)

<select>
<option value="Aguascalientes">Aguascalientes</option>
<option value="Baja California">Baja California</option>
<option value="Baja California Sur">Baja California Sur</option>
<option value="Campeche">Campeche</option>
<option value="Chiapas">Chiapas</option>
<option value="Chihuahua">Chihuahua</option>
<option value="Coahuila">Coahuila</option>
<option value="Colima">Colima</option>
<option value="Distrito Federal">Distrito Federal</option>
<option value="Durango">Durango</option>
<option value="Guanajuato">Guanajuato</option>
<option value="Guerrero">Guerrero</option>
<option value="Hidalgo">Hidalgo</option>
<option value="Jalisco">Jalisco</option>
<option value="Mexico">Mexico</option>
<option value="Michoacan">Michoacán</option>
<option value="Morelos">Morelos</option>
<option value="Nayarit">Nayarit</option>
<option value="Nuevo Leon">Nuevo León</option>
<option value="Oaxaca">Oaxaca</option>
<option value="Puebla">Puebla</option>
<option value="Queretaro">Querétaro</option>
<option value="Quintana Roo">Quintana Roo</option>
<option value="San Luis Potosi">San Luis Potosi</option>
<option value="Sinaloa">Sinaloa</option>
<option value="Sonora">Sonora</option>
<option value="Tabasco">Tabasco</option>
<option value="Tamaulipas">Tamaulipas</option>
<option value="Tlaxcala">Tlaxcala</option>
<option value="Veracruz">Veracruz</option>
<option value="Yucatan">Yucatan</option>
<option value="Zacatecas">Zacatecas</option>
</select>

PHP ITwebinfo.com - 调整jpeg图像的大小

<?

/*this can be used to resize image in jpeg format only
which provive a good quality thumbnails*/
// This is the temporary file created by PHP

$uploadedfile = $_FILES['simage']['tmp_name'];

// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);

// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);
$newwidth=300;
//$newheight=($height/$width)*100;
$newheight=200;
$tmp=imagecreatetruecolor($newwidth,$newheight);

// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = $_FILES['simage']['name'];
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp);
?>

C++ 联盟

union Example { 
   int A; 
   char B; 
   double C; 
} ex;

Other wsh_setClipboard

function setClip( txt )
{
	var ie = new ActiveXObject( "InternetExplorer.Application" );
	ie.Navigate( "about:blank" );
	
	while( ie.Busy ) WScript.Sleep( 50 );
	
	ie.Document.parentWindow.clipboardData.setData( "text", txt );
	ie.Quit( );
}