JavaScript JavaScript命名空间

String.prototype.namespace = function(separator) {
    var ns = this.split(separator || '.'), p = window;
    for (i = 0; i < ns.length; i++) {
        p = p[ns[i]] = p[ns[i]] || {};
    }
};

C# 玩扩展方法

using System;

namespace ExtensionMethodTest
{
	static class Program
	{

		public delegate void MyDelegate();

		static void Main(string[] args)
		{

			5.Times(delegate()
			{
				Console.WriteLine("Hello World");
			});

			Console.Read();
		}

		public static void Times(this int count, MyDelegate del)
		{
			for (int i = 0; i < count; i++)
			{
				del();
			}
		}

	}
}

LaTeX 总结下面的文字

\sum_{<text>}

Groovy Mediator设计模式Groovy实现

// The mediator class which connects all the colleges (buttons in this case)
// and updates them all in reaction to informations from any of them 
package design.patterns.mediator
public class Mediator {
    def show
    def buttons = []

    void registerButton(b) {
        buttons << b
    }
    void registerDisplay(d) {
        show = d
    }
    void mediate(disable, text) {
        buttons.each {
            if (it == disable) {
                it.enabled - false
            }
            else {
                it.enabled = true
            }
        }
        show.setText(text)
    }
}

// The demo UI which demonstrates the usage
package design.patterns.mediator.ui
import groovy.swing.SwingBuilder
import design.patterns.mediator.Mediator

public class MediatorDemo {

    public static void main(String[] args) {
        def Mediator mediator = new Mediator()
        def frame = new SwingBuilder().frame() {
            panel() {
                label(text: 'just starting') {mediator.registerDisplay(current)}
                button() {
                    mediator.registerButton(current)
                    action(name: 'view', closure: {mediator.mediate(current, 'viewing ..')})
                }
                button() {
                    mediator.registerButton(current)
                    action(name: 'book', closure: {mediator.mediate(current, 'booking ..')})
                }

                button() {
                    mediator.registerButton(current)
                    action(name: 'search', closure: {mediator.mediate(current, 'searching ..')})
                }

            }
        }
        frame.setSize(400, 200);
        frame.setVisible(true);
    }

}

PHP mySQL MIME表(PHP)

function addMime(){

/*
	source types: http://de.selfhtml.org/diverses/mimetypen.htm
	
	CREATE TABLE `mime` (                                                   
          `file_extension` varchar(10) collate latin1_general_ci default NULL,  
          `file_mime` varchar(255) collate latin1_general_ci default NULL,      
          `file_mime_type` varchar(255) collate latin1_general_ci default NULL  
        )
        
*/



$txt=<<< END
application/acad 	*.dwg 	AutoCAD-Dateien (nach NCSA)
application/applefile 	  	AppleFile-Dateien
application/astound 	*.asd *.asn 	Astound-Dateien
application/dsptype 	*.tsp 	TSP-Dateien
application/dxf 	*.dxf 	AutoCAD-Dateien (nach CERN)
application/futuresplash 	*.spl 	Flash Futuresplash-Dateien
application/gzip 	*.gz 	GNU Zip-Dateien
application/listenup 	*.ptlk 	Listenup-Dateien
application/mac-binhex40 	*.hqx 	Macintosh Binärdateien
application/mbedlet 	*.mbd 	Mbedlet-Dateien
application/mif 	*.mif 	FrameMaker Interchange Format Dateien
application/msexcel 	*.xls *.xla 	Microsoft Excel Dateien
application/mshelp 	*.hlp *.chm 	Microsoft Windows Hilfe Dateien
application/mspowerpoint 	*.ppt *.ppz *.pps *.pot 	Microsoft Powerpoint Dateien
application/msword 	*.doc *.dot 	Microsoft Word Dateien
application/octet-stream 	*.bin *.exe *.com *.dll *.class 	Ausführbare Dateien
application/oda 	*.oda 	Oda-Dateien
application/pdf 	*.pdf 	Adobe PDF-Dateien
application/postscript 	*.ai *.eps *.ps 	Adobe PostScript-Dateien
application/rtc 	*.rtc 	RTC-Dateien
application/rtf 	*.rtf 	Microsoft RTF-Dateien
application/studiom 	*.smp 	Studiom-Dateien
application/toolbook 	*.tbk 	Toolbook-Dateien
application/vocaltec-media-desc 	*.vmd 	Vocaltec Mediadesc-Dateien
application/vocaltec-media-file 	*.vmf 	Vocaltec Media-Dateien
application/xhtml+xml 	*.htm *.html *.shtml *.xhtml 	XHTML-Dateien
application/xml 	*.xml 	XML-Dateien
application/x-bcpio 	*.bcpio 	BCPIO-Dateien
application/x-compress 	*.z 	zlib-komprimierte Dateien
application/x-cpio 	*.cpio 	CPIO-Dateien
application/x-csh 	*.csh 	C-Shellscript-Dateien
application/x-director 	*.dcr *.dir *.dxr 	Macromedia Director-Dateien
application/x-dvi 	*.dvi 	DVI-Dateien
application/x-envoy 	*.evy 	Envoy-Dateien
application/x-gtar 	*.gtar 	GNU tar-Archivdateien
application/x-hdf 	*.hdf 	HDF-Dateien
application/x-httpd-php 	*.php *.phtml 	PHP-Dateien
application/x-javascript 	*.js 	serverseitige JavaScript-Dateien
application/x-latex 	*.latex 	LaTeX-Quelldateien
application/x-macbinary 	*.bin 	Macintosh Binärdateien
application/x-mif 	*.mif 	FrameMaker Interchange Format Dateien
application/x-netcdf 	*.nc *.cdf 	Unidata CDF-Dateien
application/x-nschat 	*.nsc 	NS Chat-Dateien
application/x-sh 	*.sh 	Bourne Shellscript-Dateien
application/x-shar 	*.shar 	Shell-Archivdateien
application/x-shockwave-flash 	*.swf *.cab 	Flash Shockwave-Dateien
application/x-sprite 	*.spr *.sprite 	Sprite-Dateien
application/x-stuffit 	*.sit 	Stuffit-Dateien
application/x-supercard 	*.sca 	Supercard-Dateien
application/x-sv4cpio 	*.sv4cpio 	CPIO-Dateien
application/x-sv4crc 	*.sv4crc 	CPIO-Dateien mit CRC
application/x-tar 	*.tar 	tar-Archivdateien
application/x-tcl 	*.tcl 	TCL Scriptdateien
application/x-tex 	*.tex 	TeX-Dateien
application/x-texinfo 	*.texinfo *.texi 	Texinfo-Dateien
application/x-troff 	*.t *.tr *.roff 	TROFF-Dateien (Unix)
application/x-troff-man 	*.man *.troff 	TROFF-Dateien mit MAN-Makros (Unix)
application/x-troff-me 	*.me *.troff 	TROFF-Dateien mit ME-Makros (Unix)
application/x-troff-ms 	*.me *.troff 	TROFF-Dateien mit MS-Makros (Unix)
application/x-ustar 	*.ustar 	tar-Archivdateien (Posix)
application/x-wais-source 	*.src 	WAIS Quelldateien
application/x-www-form-urlencoded 	  	HTML-Formulardaten an CGI
application/zip 	*.zip 	ZIP-Archivdateien
audio/basic 	*.au *.snd 	Sound-Dateien
audio/echospeech 	*.es 	Echospeed-Dateien
audio/tsplayer 	*.tsi 	TS-Player-Dateien
audio/voxware 	*.vox 	Vox-Dateien
audio/x-aiff 	*.aif *.aiff *.aifc 	AIFF-Sound-Dateien
audio/x-dspeeh 	*.dus *.cht 	Sprachdateien
audio/x-midi 	*.mid *.midi 	MIDI-Dateien
audio/x-mpeg 	*.mp2 	MPEG-Dateien
audio/x-pn-realaudio 	*.ram *.ra 	RealAudio-Dateien
audio/x-pn-realaudio-plugin 	*.rpm 	RealAudio-Plugin-Dateien
audio/x-qt-stream 	*.stream 	Quicktime-Streaming-Dateien
audio/x-wav 	*.wav 	WAV-Dateien
drawing/x-dwf 	*.dwf 	Drawing-Dateien
image/cis-cod 	*.cod 	CIS-Cod-Dateien
image/cmu-raster 	*.ras 	CMU-Raster-Dateien
image/fif 	*.fif 	FIF-Dateien
image/gif 	*.gif 	GIF-Dateien
image/ief 	*.ief 	IEF-Dateien
image/jpeg 	*.jpeg *.jpg *.jpe 	JPEG-Dateien
image/png 	*.png 	PNG-Dateien
image/tiff 	*.tiff *.tif 	TIFF-Dateien
image/vasa 	*.mcf 	Vasa-Dateien
image/vnd.wap.wbmp 	*.wbmp 	Bitmap-Dateien (WAP)
image/x-freehand 	*.fh4 *.fh5 *.fhc 	Freehand-Dateien
image/x-icon 	*.ico 	Icon-Dateien (z.B. Favoriten-Icons)
image/x-portable-anymap 	*.pnm 	PBM Anymap Dateien
image/x-portable-bitmap 	*.pbm 	PBM Bitmap Dateien
image/x-portable-graymap 	*.pgm 	PBM Graymap Dateien
image/x-portable-pixmap 	*.ppm 	PBM Pixmap Dateien
image/x-rgb 	*.rgb 	RGB-Dateien
image/x-windowdump 	*.xwd 	X-Windows Dump
image/x-xbitmap 	*.xbm 	XBM-Dateien
image/x-xpixmap 	*.xpm 	XPM-Dateien
message/external-body 	  	Nachricht mit externem Inhalt
message/http 	  	HTTP-Headernachricht
message/news 	  	Newsgroup-Nachricht
message/partial 	  	Nachricht mit Teilinhalt
message/rfc822 	  	Nachricht nach RFC 2822
model/vrml 	*.wrl 	Visualisierung virtueller Welten (VRML)
multipart/alternative 	  	mehrteilige Daten gemischt
multipart/byteranges 	  	mehrteilige Daten mit Byte-Angaben
multipart/digest 	  	mehrteilige Daten / Auswahl
multipart/encrypted 	  	mehrteilige Daten verschlüsselt
multipart/form-data 	  	mehrteilige Daten aus HTML-Formular (z.B. File-Upload)
multipart/mixed 	  	mehrteilige Daten gemischt
multipart/parallel 	  	mehrteilige Daten parallel
multipart/related 	  	mehrteilige Daten / verbunden
multipart/report 	  	mehrteilige Daten / Bericht
multipart/signed 	  	mehrteilige Daten / bezeichnet
multipart/voice-message 	  	mehrteilige Daten / Sprachnachricht
text/comma-separated-values 	*.csv 	kommaseparierte Datendateien
text/css 	*.css 	CSS Stylesheet-Dateien
text/html 	*.htm *.html *.shtml 	HTML-Dateien
text/javascript 	*.js 	JavaScript-Dateien
text/plain 	*.txt 	reine Textdateien
text/richtext 	*.rtx 	Richtext-Dateien
text/rtf 	*.rtf 	Microsoft RTF-Dateien
text/tab-separated-values 	*.tsv 	tabulator-separierte Datendateien
text/vnd.wap.wml 	*.wml 	WML-Dateien (WAP)
application/vnd.wap.wmlc 	*.wmlc 	WMLC-Dateien (WAP)
text/vnd.wap.wmlscript 	*.wmls 	WML-Scriptdateien (WAP)
application/vnd.wap.wmlscriptc 	*.wmlsc 	WML-Script-C-dateien (WAP)
text/xml 	*.xml 	XML-Dateien
text/xml-external-parsed-entity 	  	extern geparste XML-Dateien
text/x-setext 	*.etx 	SeText-Dateien
text/x-sgml 	*.sgm *.sgml 	SGML-Dateien
text/x-speech 	*.talk *.spc 	Speech-Dateien
video/mpeg 	*.mpeg *.mpg *.mpe 	MPEG-Dateien
video/quicktime 	*.qt *.mov 	Quicktime-Dateien
video/vnd.vivo 	*.viv *.vivo 	Vivo-Dateien
video/x-msvideo 	*.avi 	Microsoft AVI-Dateien
video/x-sgi-movie 	*.movie 	Movie-Dateien
workbook/formulaone 	*.vts *.vtts 	FormulaOne-Dateien
x-world/x-3dmf 	*.3dmf *.3dm *.qd3d *.qd3 	3DMF-Dateien
x-world/x-vrml 	*.wrl 	Visualisierung virtueller Welten (VRML) (veralteter MIME-Typ, aktuell ist model/vrml)
END;

	$types=explode("\n", $txt);
	foreach($types as $type){
		$parts=explode("	", $type);
		$parts[1]=trim($parts[1]);
		
		if(!$parts[1])	## no file extension specified
			continue;
		
		if(strpos($parts[1], " ")>0){	## more than one file extension
			$extensions=explode(" ", $parts[1]);
			
			foreach($extensions as $extension){
				$filetype=explode(".", $extension);
				$filetype[1]=str_replace("*", "", $filetype[1]);
				$add[]='("'.trim($parts[0]).'", "'.trim($filetype[1]).'", "'.trim($parts[2]).'")';
			}
			
		}
		else{	## only one file extension
			$filetype=explode(".", $parts[1]);
			$filetype[1]=str_replace("*", "", $filetype[1]);
			$add[]='("'.trim($parts[0]).'", "'.trim($filetype[1]).'", "'.trim($parts[2]).'")';
		}
	}
	$sql='insert into `mime` (`file_mime`, `file_extension`, `file_mime_type`) values '.implode(",<br/> ", $add);
	echo $sql.";";

}

PHP create_timestamp

function create_timestamp($date) { // Format : DD.MM.YYYY 
	if	(preg_match("/^([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})$/i",$date))
		{
			$expDate=explode(".",$date);
			if(strlen($expDate[0])=="1"){$expDate[0]="0".$expDate[0];}
			if(strlen($expDate[1])=="1"){$expDate[1]="0".$expDate[1];}
			return mktime(0,0,0,$expDate[1],$expDate[0],$expDate[2]);
		}
	else return false;
}

JavaScript 显示/隐藏元素

// show or hide a selected element
// if no state is given, the visibility is toggled
// otherwise visibility is set to hidden or visible as selected
function showHide(e, state) {
    el = document.getElementById(e);
    if (state == "hidden") {
    	el.style.visibility = "hidden";
    } else if (state == "visible") {
    	el.style.visibility = "visible";
    } else {
    	el.style.visibility = el.style.visibility  == "visible" ? "hidden" : "visible";
    } 
}

JavaScript IE Tunning con jquery

$(fixIE);

function fixIE(){
	$(':input[type]').each(function(){
		$(this).addClass($(this).attr('type'));
	});
	$('li:first, td:first',$('ul, ol, tr')).addClass('first');
};

JavaScript IsMouseLeaveOrEnter - 修复鼠标悬停/鼠标移动

// this function determines whether the event is the equivalent of the microsoft // mouseleave or mouseenter events. 
function isMouseLeaveOrEnter(e, handler) { 
  if (e.type != 'mouseout' && e.type != 'mouseover') return false; 
  var reltg = e.relatedTarget ? e.relatedTarget : 
  e.type == 'mouseout' ? e.toElement : e.fromElement; 
  while (reltg && reltg != handler) reltg = reltg.parentNode; 
  return (reltg != handler); 
}

Other 在maven2中将编译器版本设置为Java5

<profile>
    <id>java5</id>
    <properties>
        <build-home>D:/Build-Loc/build-cougar</build-home>
	<maven.compiler.compilerVersion>5</maven.compiler.compilerVersion>
        <maven.compiler.executable>pathto/bin/javac</maven.compiler.executable>
	<maven.compiler.source>5</maven.compiler.source>
	<maven.compiler.target>5</maven.compiler.target>
    </properties>
</profile>