JavaScript Javascript - MP3播放器 - 声音

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>HTML PLAYER</title>

<script>



function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/*Namespaces*/
var Media = document.Media || {};
// funciones para cookies

Media.PlaySound = {
	MSIE: navigator.userAgent.indexOf("MSIE"),
	NETS: navigator.userAgent.indexOf("Netscape"),
	OPER: navigator.userAgent.indexOf("Opera"),
	cookieNameActive:  "cookie_sound_active",
	cookieNameThisSound:  "cookie_this_sound",
	imgOn: "images/ico_on.gif",
	imgOff: "images/ico_off.gif",
	SoundDefault: 1,
	Sounds: {
		0:{"file":"mp3/uno.mp3","name":"UNO"},
		1:{"file":"mp3/dos.mp3","name":"DOS"},
		2:{"file":"mp3/tres.mp3","name":"TRES"},
		3:{"file":"mp3/cuatro.mp3","name":"CUATRO"}
	},
	SoundStop: "mp3/silence.mp3",
	WriteCookie: function( name, value ){
		var expdate=new Date();
		expdate.setTime(expdate.getTime()+10*365*24*60*60*1000);
		document.cookie = name + "=" + escape (value) + "; expires=" + expdate.toGMTString();
	},
	EliminarElemento: function(elemento) {
		elemento.parentNode.removeChild(elemento);
	},
	ReadCookie: function( name ){
		var namearg = name + "=";
		var nlen = namearg.length;
		var clen = document.cookie.length;
		var i = 0;
		while (i < clen) {
			var j = i + nlen;
			if (document.cookie.substring(i, j) == namearg) {
				var endpos = document.cookie.indexOf (";", j);
				if (endpos == -1) endpos = document.cookie.length;
				return unescape(document.cookie.substring(j, endpos));
			}
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break;
		}
		return null;
	},
	OnOffSound: function( img ){
		newValue = Media.PlaySound.ReadCookie( Media.PlaySound.cookieNameActive ) == 1 || Media.PlaySound.ReadCookie( Media.PlaySound.cookieNameActive ) == null  ? 0 : 1;
		img.src = newValue == 1 ? Media.PlaySound.imgOn : Media.PlaySound.imgOff;
		objInfo = MM_findObj("MediaMyMediaDivInfo");
		if( newValue == 0 ){
			Media.PlaySound.Stop();
			objInfo.innerHTML = 'Mute';
			Media.PlaySound.WriteCookie( Media.PlaySound.cookieNameActive, newValue );
		}else{
			Media.PlaySound.WriteCookie( Media.PlaySound.cookieNameActive, newValue );
			Media.PlaySound.Play();
		}
		
	},
	Init: function(){
		if((Media.PlaySound.MSIE>-1) || (Media.PlaySoundOPER>-1)) {
			document.write('<bgsound loop="0" name="MediaMyMediaObj" id="MediaMyMediaObj" >');
		}
	},
	Play: function(){
	if( Media.PlaySound.ReadCookie( Media.PlaySound.cookieNameActive ) == 1 || Media.PlaySound.ReadCookie( Media.PlaySound.cookieNameActive ) == null ){
		sound = Media.PlaySound.ReadCookie( Media.PlaySound.cookieNameThisSound ) || Media.PlaySound.SoundDefault;
		obj = MM_findObj("MediaMyMedia");
		objInfo = MM_findObj("MediaMyMediaDivInfo");
		objInfo.innerHTML = 'Estás escuchando ' + Media.PlaySound.Sounds[sound].name;
		//alert(Media.PlaySound.Sounds[sound].file)
			if((Media.PlaySound.MSIE>-1) || (Media.PlaySoundOPER>-1)) {
				obj = MM_findObj("MediaMyMediaObj");
				obj.src = Media.PlaySound.Sounds[sound].file;
			} else {
				obj = MM_findObj("MediaMyMediaDiv");
				obj.innerHTML = '<embed  src="'+Media.PlaySound.Sounds[sound].file+'" hidden="true" volume="200" loop="0" type="audio/midi" >';
			}
		}
	},
	Next: function(){
		sounds = Media.PlaySound.Sounds;
		var firstSound = 0;
		var lastSound = 0; for (var sonido in sounds){ lastSound++; } if( lastSound > 0 ) lastSound--;
		thisSound = Media.PlaySound.ReadCookie( Media.PlaySound.cookieNameThisSound ) || Media.PlaySound.SoundDefault;
		nextSound = thisSound < lastSound ? parseInt(parseInt(thisSound,10)+1,10) : firstSound;

		Media.PlaySound.WriteCookie( Media.PlaySound.cookieNameThisSound, nextSound );
		Media.PlaySound.Play();
	},
	Previus: function(){
		sounds = Media.PlaySound.Sounds;
		var firstSound = 0;
		var lastSound = 0; for (var sonido in sounds){ lastSound++; } if( lastSound > 0 ) lastSound--;
		thisSound = Media.PlaySound.ReadCookie( Media.PlaySound.cookieNameThisSound ) || Media.PlaySound.SoundDefault;
		nextSound = thisSound > 0 ? parseInt(parseInt(thisSound,10)-1,10) : lastSound;

		Media.PlaySound.WriteCookie( Media.PlaySound.cookieNameThisSound, nextSound );
		Media.PlaySound.Play();
	},
	Stop: function(){
	if( Media.PlaySound.ReadCookie( Media.PlaySound.cookieNameActive ) == 1 || Media.PlaySound.ReadCookie( Media.PlaySound.cookieNameActive ) == null ){
		obj = MM_findObj("MediaMyMedia");
		objInfo = MM_findObj("MediaMyMediaDivInfo");
		objInfo.innerHTML = 'Stop';

			if((Media.PlaySound.MSIE>-1) || (Media.PlaySoundOPER>-1)) {
				obj = MM_findObj("MediaMyMediaObj");
				obj.src = Media.PlaySound.SoundStop;
			} else {
				obj = MM_findObj("MediaMyMediaDiv");
				obj.innerHTML = '<embed  src="'+Media.PlaySound.SoundStop+'" hidden="true" volume="200" loop="0" type="audio/midi" >';
			}
		}
	}	
}
Media.PlaySound.Init();
</script>
</head>
<body>



<a href="#"><img src="images/ico_on.gif" onclick="Media.PlaySound.OnOffSound(this)" border="0" align="absmiddle" /></a> 


<span name="MediaMyMediaDiv" id="MediaMyMediaDiv" style="margin:0; width:0; height:0;"></span>
<input type="button" value="Previus" onclick="Media.PlaySound.Previus()" />
<input type="button" value="Play" onclick="Media.PlaySound.Play()" />
<input type="button" value="Stop" onclick="Media.PlaySound.Stop()" />
<input type="button" value="Next" onclick="Media.PlaySound.Next()" />
<span name="MediaMyMediaDivInfo" id="MediaMyMediaDivInfo"></span>
</body>
</html>

JavaScript Google AJAX API

// http://www.google.com/jsapi
google.load("jquery", 1);
google.load("jqueryui", 1);
google.setOnLoadCallback(function () {
    // ...
});

HTML HTML5ÂSITEA头

<header role="banner">
 <hgroup id="heading">
  <h1 class="site-title">
						<a href="@site-url@" title="@go-to@ @site-title@">
							<span>@site-title@</span>
						</a>
					</h1>
					<h2 class="page-title">
						<a href="@page-url@" title="@go-to@ @page-title@">
							<span>@page-title@</span>
						</a>
					</h2>
				</hgroup>
				<nav id="navigation">
					<h1>
						<span>@navigation@</span>
					</h1>
					<ul>
						<li>
							<a href="@page-1-href@"><span>@page-1-label@</span></a>
						</li>
						<li class="selected">
							<a href="@page-2-href@"><span>@page-2-label@</span></a>
						</li>
						<li>
							<a href="@page-3-href@"><span>@page-3-label@</span></a>
						</li>
						<li>
							<a href="@page-4-href@"><span>@page-4-label@</span></a>
						</li>
						<li>
							<a href="@page-5-href@"><span>@page-5-label@</span></a>
						</li>
					</ul>
				</nav>
			</header>

Bash check_deps.sh

#  snippet:    check_deps.sh
#  version:    0.02 :-)
#  author:     ksaver (at identi.ca)
#  license:    Public Domain
#  arguments:  List of dependences to check.
#  sets:       check_deps function
#  returns:    0=OK, 1=ERR and echoes a helpfull message :-)
#  usage:      Use into a script:
#              source check_deps.sh
#              check_deps 'wget curl ftp tor mplayer or whatever'

function _dep_error()
{
    # for internal use only
    echo "[ERR]: Dependence '$1' Not found in your path!"
}

function check_deps()
{
    for DEPEND in $@
    do
        /usr/bin/which $DEPEND &> /dev/null || (__dep_error $DEPEND && return 1)
    done
}

Bash 一个非常简单的bash进度条。

#!/usr/bin/env bash
# simplepb.sh
# A very simple bash progress bar.
# Still needs a lot of work to become useful.
# ksaver (at identi.ca), Aug 2010.
# License: Public Domain

function progr_bar()
{
    MAX=$1
    PERCENT=0
    FOO=">"
    BAR=""

    while [ $PERCENT -lt $(($MAX+1)) ]
    do  
        echo -ne "\r\t[ "
        echo -ne "$BAR$FOO ] $((PERCENT*100/$MAX))% "
        BAR="${BAR}="
        let PERCENT=$PERCENT+1
        sleep 0.2
    done

    echo -e " Done.\n"
}

progr_bar 20

jQuery jQuery扩展模板

(function($) {
	$.extend($.ui.tabs.prototype, {
		_tabify: function(init) {
			//Do stuff here
			//We extended the _tabify function of jQuery's tabs
		}
	});
})(jQuery);

C# 从系统中阻止当前登录/特定用户(ASP.NET成员身份)

MembershipUser user = Membership.GetUser(); //to block currently logged in user

MembershipUser user = Membership.GetUser("username"); //To block a specific user:

user.IsApproved = false;
Membership.UpdateUser(user);

C# 取消阻止用户(ASP.NET成员身份)

MembershipUser user = Membership.GetUser("username");
user.IsApproved = true;
Membership.UpdateUser(user);

Bash 在没有上传svn文件的情况下通过ssh进行rsync

# download 
rsync -avz -e ssh --exclude=".svn" www-data@web1:/remote/dir .
# upload 
rsync -avz -e ssh --exclude=".svn" . www-data@web1:/remote/dir

PHP 圆形大数字到字母缩写例如:25,000到25K

function abbr_number($size) {
    $size = preg_replace('/[^0-9]/','',$size);
    $sizes = array("", "K", "M");
    if ($size == 0) { return('n/a'); } else {
    return (round($size/pow(1000, ($i = floor(log($size, 1000)))), 0) . $sizes[$i]); }
}

function format_size($size) {
    $sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
    if ($size == 0) { return('n/a'); } else {
    return (round($size/pow(1024, ($i = floor(log($size, 1024)))), $i > 1 ? 2 : 0) . $sizes[$i]); }
}