ActionScript Bucle cambiar alfa是倍数元素
for(var i:Number = 0; i<=10; i++){this["btn"+(i)]._alpha = 50;}
Other 用于snippetsEmu的TSQL片段
if !exists('loaded_snippet') || &cp
finish
endif
Snippet $proc IF EXISTS (<CR>SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES<CR>
\WHERE ROUTINE_NAME = '<{"name"}>'<CR>
\AND ROUTINE_SCHEMA = 'dbo'<CR>AND ROUTINE_TYPE = 'PROCEDURE'<CR><BS>)<CR>
\BEGIN<CR>DROP PROCEDURE dbo.<{"name"}><CR>
\PRINT 'Dropped dbo.<{"name"}>'<CR>
\END<CR>GO<CR><CR>CREATE PROCEDURE dbo.<{"name"}> (<CR>
\/*<CR> Sample calls:<CR>
\<BS><Tab>EXEC <{"name"}><CR><BS>*/<CR>)<CR>AS BEGIN<CR>
\<Tab>SET NOCOUNT ON<CR><{}><CR>END<CR>GO<CR><CR>IF @@ERROR = 0<CR>
\PRINT 'Created dbo.<{"name"}>'<CR><BS>GO<CR>
Snippet $func IF EXISTS (<CR>SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES<CR>
\WHERE ROUTINE_NAME = '<{"name"}>'<CR>
\AND ROUTINE_SCHEMA = 'dbo'<CR>AND ROUTINE_TYPE = 'FUNCTION'<CR><BS>)<CR>
\BEGIN<CR>DROP FUNCTION dbo.<{"name"}><CR>
\PRINT 'Dropped dbo.<{"name"}>'<CR>
\END<CR>GO<CR><CR>CREATE FUNCTION dbo.<{"name"}> (<CR>
\/*<CR> Sample calls:<CR>
\<BS><Tab>SELECT dbo.<{"name"}>()<CR><BS>*/<CR>)<CR>
\RETURNS <{"return_type"}><CR>AS BEGIN<CR>
\<Tab><{}><CR>END<CR>GO<CR><CR>IF @@ERROR = 0<CR>
\PRINT 'Created dbo.<{"name"}>'<CR><BS>GO<CR>
Snippet $view IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.VIEWS
\WHERE TABLE_NAME = '<{"name"}>') BEGIN<CR>
\DROP VIEW dbo.<{"name"}><CR>
\PRINT 'Dropped dbo.<{"name"}>'<CR>
\END<CR>GO<CR><CR>CREATE VIEW dbo.<{"name"}><CR>AS<CR>
\/* Sample calls:<CR>
\<Tab>SELECT * FROM <{"name"}><CR><BS>*/<CR><{}><CR>GO<CR>
\<CR>IF @@ERROR = 0<CR>
\PRINT 'Created dbo.<{"name"}>'<CR><BS>GO<CR>
Snippet $table IF EXISTS (<CR>SELECT 1 FROM INFORMATION_SCHEMA.TABLES<CR>
\WHERE TABLE_NAME = '<{"name"}>'
\AND TABLE_SCHEMA = 'dbo'<CR><BS>)<CR>BEGIN<CR>
\DROP TABLE dbo.<{"name"}><CR>
\PRINT 'Dropped dbo.<{"name"}>'<CR>
\END<CR>GO<CR><CR>CREATE TABLE dbo.<{"name"}> (<CR>
\<{}><CR>)<CR>GO<CR><CR>IF @@ERROR = 0<CR>
\PRINT 'Created dbo.<{"name"}>'<CR><BS>GO<CR>
Snippet $sum SUM(<{"field"}>) AS <{"field"}>,<{}>
Snippet $vc varchar(<{"size"}>)<{}>
Snippet $c char(<{"size"}>)<{}>
Snippet $d decimal(<{"size"}>,<{"precision"}>)<{}>
Snippet $tv DECLARE @<{"name"}> table (<CR><{}><CR>)
Snippet $tt CREATE TABLE #<{"name"}> (<CR><{}><CR>)
Regular Expression 电子邮件验证正则表达式
\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b
ActionScript AS2:全屏
fullScreen_btn.onRelease = fullScreen_btn.onReleaseOutside = toggleFullScreen;
fullScreen_btn.onRollOver = onRollOverHandler;
fullScreen_btn.onRollOut = onRollOutHandler;
function onRollOverHandler()
{
}
function onRollOutHandler():Void
{
}
function toggleFullScreen():Void
{
if( Stage["displayState"] == "normal"){
goFullScreen();
} else {
exitFullScreen();
}
}
function goFullScreen():Void
{
Stage["displayState"] = "fullScreen";
}
function exitFullScreen():Void
{
Stage["displayState"] = "normal";
}
ActionScript 的SoundLoader
import mx.events.EventDispatcher;
import mx.utils.Delegate;
/**
* Loads a list of sounds "in the background" without playing them
* Allows client to request a specific sound in priority
*
* Usage
*
* var soundLoader:SoundLoader = new SoundLoader(this,
* "soundLoader",
* this.getNextHighestDepth());
* soundLoader.addEventListener("loadProgress",
* Delegate.create(this,
* soundLoaderLoading));
* soundLoader.addEventListener("doneLoading",
* Delegate.create(this,
* soundLoaderLoaded));
* function soundLoaderLoading(event:Object)
* {
* trace("Loading " + Math.round(event.percent * 100) + " out of " + Math.round(event.globalPercent * 100));
* }
* function soundLoaderLoaded(event:Object)
* {
* trace("soundLoader doneLoading");
* }
*
* // Add sounds to queue
* soundLoader.push("audio/audio10.mp3");
* soundLoader.push("audio/audio11.mp3");
* soundLoader.push("audio/audio20.mp3");
*
* // Start the load queue
* soundLoader.startLoad();
*
* // Request a sound in priority
* var soundHandler:Object = {};
* soundHandler.soundLoaded = function(event:Object):Void
* {
* soundLoader.removeEventListener("soundLoaded", this);
* trace("Priority sound loaded");
* }
* soundLoader.addEventListener("soundLoaded", soundHandler);
* // Retrieve sound by file name (no path or extension)
* soundLoader.getSound("audio20");
*
*/
class com.orazal.SoundLoader
{
public var dispatchEvent:Function;
public var addEventListener:Function;
public var removeEventListener:Function;
private var sprite:MovieClip;
private var soundList:Array /* of Object */;
private var current:Number;
private var interval:Number;
private var prioritySound:Sound;
private var priorityPosition:Number;
private var loadingPriority:Boolean;
/**
* Constructor, assign sounds to a movieclip to be able to control volume independently
* of _root
*
* @param target
* @param name
* @param depth
*/
public function SoundLoader(target:MovieClip, name:String, depth:Number)
{
EventDispatcher.initialize(this);
sprite = target.createEmptyMovieClip(name, depth);
soundList = [];
loadingPriority = false;
}
/**
* Adds a sound url to load queue creating a new sound for the url
* and assigning the sound a specific id
* @param url
*/
public function push(url:String):Void
{
// Retrieve file name only
var id:String = url.slice(url.indexOf("/")+1, url.indexOf("."));
var newSound:Sound = new Sound(sprite);
newSound.onLoad = Delegate.create(this, onLoad);
soundList.push( { url:url, sound:newSound, loaded:false , id:id} );
}
/**
* Start sound loading
*/
public function startLoad():Void
{
current = 0;
Sound(soundList[0].sound).loadSound(String(soundList[0].url));
interval = setInterval(Delegate.create(this, checkProgress), 100);
}
/**
* Sets volume for sprite
*/
public function setVolume(value:Number):Void
{
sprite.setVolume(value);
// extra sure
for(var p:String in soundList)
{
Sound(soundList[p].sound).setVolume(value);
}
}
/**
* Retrieves a sound by id
*/
public function getSound(id:String):Void
{
// Retrieve sound position
for (var i:Number = 0; i < soundList.length; i++)
{
if (String(soundList[i].id) == id)
{
priorityPosition = i;
break;
}
}
// Either dispatch get sound event or load specific sound
// as a priority
if (soundList[priorityPosition].loaded)
{
dispatchGetSound();
}
else
{
loadSoundPriority(priorityPosition);
}
}
/**
* Changes load priority flag to stop loading other sounds
* Uses a specific sound and load handler to load sound
* Resumes load queue after sound has been loaded
*
* @param position
*/
private function loadSoundPriority(position:Number):Void
{
loadingPriority = true;
prioritySound = new Sound(sprite);
prioritySound.onLoad = Delegate.create(this, onLoadPriority);
prioritySound.loadSound(String(soundList[priorityPosition].url));
}
/**
* Priority sound onLoad handler
*/
private function onLoadPriority(success:Boolean):Void
{
continueLoading();
// update loading status
soundList[priorityPosition].loaded = true;
// replace original sound with priority sound
soundList[priorityPosition].sound = prioritySound;
dispatchGetSound();
}
/**
* Dispatches an event when a specific sound that has been requested has
* finishes loading
*/
private function dispatchGetSound():Void
{
var event:Object = { target:this, type:"soundLoaded" };
event.sound = Sound(soundList[priorityPosition].sound);
event.id = String(soundList[priorityPosition].id);
dispatchEvent(event);
}
/**
* Continues load queue
*/
private function continueLoading():Void
{
loadingPriority = false;
// If current is not loaded it will automatically load next
// when loaded or call finishLoading if it's last on list
if(soundList[current].loaded)
{
if (current < soundList.length - 1)
{
loadNext();
}
}
}
/**
* Loads next sound in queue
* @param success
*/
private function loadNext():Void
{
// Make sure that there's a next sound to load
if (current + 1 <= soundList.length - 1)
{
current++;
Sound(soundList[current].sound).loadSound(String(soundList[current].url), false);
}
}
/**
* Sound onLoad handler used for load queue
*
* @param success
*/
private function onLoad(success:Boolean):Void
{
// update loading status
soundList[current].loaded = true;
if (current == soundList.length - 1)
{
finishLoading();
return;
}
if (loadingPriority)
{
// onLoadPriority will resume loading
return;
}
if (current < soundList.length - 1)
{
loadNext();
}
}
/**
* Stop checking sound load and dispatches event
*/
private function finishLoading():Void
{
clearInterval(interval);
var event:Object = { target:this, type:"doneLoading" };
dispatchEvent(event);
}
/**
* Checks current sound loading percent and total percent
*/
private function checkProgress():Void
{
var currentSound:Sound = Sound(soundList[current].sound);
var percent:Number = currentSound.getBytesLoaded() / currentSound.getBytesTotal();
// Determine percentage
var loadedPercent:Number = current/soundList.length;
var globalPercent = (percent/soundList.length)+loadedPercent;
// Dispatch event
var event:Object = { target:this, type:"loadProgress" };
event.current = current;
event.percent = percent;
event.globalPercent = globalPercent;
dispatchEvent(event);
if(globalPercent == 1)
{
clearInterval(interval);
}
}
}
JavaScript InputMask jQuery插件
/*---------------------------------------------------------------------------------
*
* InputMask jQuery Plugin
*
*---------------------------------------------------------------------------------
*
* Taking alot of inspiration and code from
* http://digitalbush.com/projects/masked-input-plugin this is a masked input
* solution that should handle most cases. It uses annotations to determine the
* actual mask. Mask characters include,
*
* % - Any digit or numeric sign
* # - Any digit
* @ - Any letter
* * - Any letter or digit
* ~ - Any sign (+/-)
* ? - Currencies ($,£,€,¥)
*
* @author James Hughes
*
* -------------------------------------------------------------------------------
* 29/10/2008 - Initial Version
* -------------------------------------------------------------------------------
*
*///------------------------------------------------------------------------------
(function($){
/*-----------------------------------------------------------------------------
*
* availableMasks
*
*-----------------------------------------------------------------------------
*
* Available Character Masks. This can be extended or modified via the
* $.mask.availableMasks config.
*
*///--------------------------------------------------------------------------
var availableMasks = {
'%' : '[-+0-9]', // Any digit or numeric sign
'#' : '[0-9]', // Any digit
'@' : '[A-Za-z]', // Any letter
'*' : '[A-Za-z0-9]', // Any letter or digit
'~' : '[+-]', // Any sign (+/-)
'?' : '[\$£€¥]' // Typical World Currencies
}
/*-----------------------------------------------------------------------------
*
* $.applyMasks
*
*-----------------------------------------------------------------------------
*
* Deteremines, based @Mask on annotations, all elements below either the
* specified root or the document element that should have masks applied
*
* @plugin
*
* @param opts - options
*
*///--------------------------------------------------------------------------
$.applyMasks = function(root, opts){
$.annotated("@Mask", root || document).mask(opts);
}
/*-----------------------------------------------------------------------------
*
* $.fn.mask
*
*-----------------------------------------------------------------------------
*
* Applies the annotated masks to the passed in elements. Applicable options
*
* invalidHandler custom event fired when field blurs invalid
* placeholder placeholder for mask characters. defaults to _
* alwaysShowMask determine if we always show the input mask
* permitIncomplete determine if we allow the field to be partially
* filled on blur.
* selectOnFocus : true
*
*///--------------------------------------------------------------------------
$.fn.mask = function(opts){
/*-------------------------------------------------------------------------
*
* Apply Mask
*
*-------------------------------------------------------------------------
*
* This section discovers the required mask on a per field basis and
* applies the behaviour to the field
*
*///----------------------------------------------------------------------
return this.each(function(){
/*---------------------------------------------------------------------
*
* No Mask Annotation Failover
*
*---------------------------------------------------------------------
*
* Most of this API is open to the public therefore open to the
* irresponsible, ignorant, clueless and just plain stupid. We need
* to cater for as much worst case edge cases as we can without
* making the good people suffer. Exit if no mask defined on the
* element.
*
*///------------------------------------------------------------------
if(!$(this).annotations("@Mask")[0]){ return undefined };
/*---------------------------------------------------------------------
*
* Apply Options
*
*---------------------------------------------------------------------
*
* Merge the default and custom options resulting in a specific
* options map for this function call.
*
*///------------------------------------------------------------------
var o = $.extend({}, defaultOptions, opts);
/*---------------------------------------------------------------------
*
* Assign Buffers
*
*---------------------------------------------------------------------
*
* Iterate over the jQuery collection of fields passed in and add
* the intial buffer data to each.
*
*///------------------------------------------------------------------
$(this).each(function(){
$(this).data("mask-buffer", new MaskBuffer(
$(this).annotations("@Mask")[0].data, o.placeholder
));
});
/*---------------------------------------------------------------------
*
* Handle Blur
*
*---------------------------------------------------------------------
*
* When a masked field blurs we need to handle overall validation and
* based on the confguration options hide and show the mask. If the
* field is invalid the event will fire the custom handler.
*
*///------------------------------------------------------------------
function handleBlur(){
var buffer = $(this).data("mask-buffer");
if(!o.permitIncomplete){
var v = $(this).val();
if(((!v || v === "") || !buffer.test())){
buffer.reset();
$(this).val( o.alwaysShowMask ? buffer.get() : "" );
o.invalidHandler(this, v);
}
}
}
/*---------------------------------------------------------------------
*
* Handle Key Press
*
*---------------------------------------------------------------------
*
* In the keypress event we are responsible for handling the standard
* keys and managing the buffer
*
*///------------------------------------------------------------------
function handleKeyPress(e){
var code = ($.browser.msie) ? e.which : e.charCode;
if(code != 0 && !(e.ctrlKey || e.altKey)){
var buffer = $(this).data("mask-buffer");
var carat = $.carat.get(this);
var ncp = buffer.nextMaskPosition(carat.start-1);
if(ncp < buffer.size()){
var characterTest = new RegExp(availableMasks[buffer.getMaskValue(ncp)]);
var value = String.fromCharCode(code);
if(characterTest.test(value)){
buffer.set(ncp, value);
$(this).val(buffer.get());
$.carat.set(this, new Carat(buffer.nextMaskPosition(ncp)));
}
}
/* handle ourselves */
return false;
}
}
/*---------------------------------------------------------------------
*
* Handle Key Down
*
*---------------------------------------------------------------------
*
* In the key down we are responsible for handling special characters
* such as delete, backspace and escape. As well as clearing any
* selections
*
*///------------------------------------------------------------------
function handleKeyDown(e){
/*-----------------------------------------------------------------
*
* Key Code Constants
*
*-----------------------------------------------------------------
*
* Constant representing the useful keycodes
*
*///--------------------------------------------------------------
var BACKSPACE = 8;
var DELETE = 46;
var ESCAPE = 27;
var carat = $.carat.get(this);
var code = e.keyCode;
var buffer = $(this).data("mask-buffer");
if(carat.isSelection() && (code == BACKSPACE || code == DELETE)){
buffer.reset(carat.start, carat.end);
}
switch(code){
case BACKSPACE:
while(carat.start-- >= 0){
if(availableMasks[buffer.getMaskValue(carat.start)]){
buffer.reset(carat.start);
if($.browser.opera){
/* Opera can't cancel backspace, prevent deletion */
$(this).val(buffer.get().substring(0, carat.start) + " " + buffer.get().substring(carat.start));
$.carat.set(this, new Carat(carat.start++));
}else{
$(this).val(buffer.get());
$.carat.set(this, new Carat(Math.max(buffer.getStartingMaskPosition(), carat.start)));
}
return false;
}
}
break;
case DELETE:
buffer.reset(carat.start);
$(this).val(buffer.get());
$.carat.set(this, new Carat(Math.max(buffer.getStartingMaskPosition(), carat.start)));
return false;
case ESCAPE:
buffer.reset();
$(this).val(buffer.get());
$.carat.set(this, new Carat(buffer.getStartingMaskPosition()));
return false;
}
}
/*---------------------------------------------------------------------
*
* Handle Focus
*
*---------------------------------------------------------------------
*
* On focus we want to set the value to the current buffer state and
* determine where we set the carat
*
*///------------------------------------------------------------------
function handleFocus(){
$(this).val($(this).data("mask-buffer").get());
if(o.selectOnFocus){
$.carat.set(this, new Carat(0, $(this).val().length));
}else{
$.carat.set(this, new Carat(Math.max(start, this.value.indexOf(o.placeholder))));
}
}
/*---------------------------------------------------------------------
*
* Handle Paste
*
*---------------------------------------------------------------------
*
* Custom event used to handle onpaste events. When we paste data
* into a masked field we loop over the buffer and only apply the
* valid parts of the paste.
*
* This method is not ideal but it does the job for now.
*
*///------------------------------------------------------------------
function handlePaste(){
var currentValue = $(this).val().split('');
var buffer = $(this).data("mask-buffer");
for(var i = 0; i < buffer.size(); i++){
if(availableMasks[buffer.getMaskValue(i)]){
var re = new RegExp(availableMasks[buffer.getMaskValue(i)]);
if(re.test(currentValue[i])){
buffer.set(i, currentValue[i])
}else{
buffer.reset(i);
}
}
}
$(this).val(buffer.get());
$.carat.set(this, new Carat((this.value.indexOf(o.placeholder) == -1)?buffer.size():this.value.indexOf(o.placeholder)));
handleBlur.call(this);
}
/*---------------------------------------------------------------------
*
* Bind Events
*
*---------------------------------------------------------------------
*
* Bind the mask events to the current field. Include the custom
* paste event.
*
*///------------------------------------------------------------------
$(this).bind('blur', handleBlur);
$(this).bind('keypress', handleKeyPress);
$(this).bind('focus', handleFocus);
$(this).bind('keydown', handleKeyDown);
if ($.browser.msie){
this.onpaste = function(){ setTimeout(handlePaste,0); };
}else if ($.browser.mozilla){
this.addEventListener('input', handlePaste, false);
}
/*---------------------------------------------------------------------
*
* Unmask Event
*
*---------------------------------------------------------------------
*
* Add the unmask event to be fired only once. This will remove all
* the mask associated data and event listeners from the field
*
*///------------------------------------------------------------------
$(this).one('unmask', function(){
/* Unbond Events */
$(this).unbind('blur', handleBlur);
$(this).unbind('keypress', handleKeyPress);
$(this).unbind('focus', handleFocus);
$(this).unbind('keydown', handleKeyDown);
/* Remove Buffer Data */
$(this).removeData("mask-buffer");
/* Remove Custom Paste Event */
if ($.browser.msie){
this.onpaste = null;
}else if ($.browser.mozilla){
this.removeEventListener('input',handlePaste,false);
}
});
/*---------------------------------------------------------------------
*
* Initialize Field
*
*---------------------------------------------------------------------
*
* Call the handlePaste event to intialize the field. This will
* handle any existing text that is there and set the inital value of
* the field.
*
*///------------------------------------------------------------------
handlePaste.call(this);
});
}
/*-----------------------------------------------------------------------------
*
* $.fn.unmask
*
*-----------------------------------------------------------------------------
*
* Remove any masks from the passed in fields.
*
*///--------------------------------------------------------------------------
$.fn.unmask = function(){
return this.trigger('unmask');
}
/*-----------------------------------------------------------------------------
*
* Default Options
*
*-----------------------------------------------------------------------------
*
* This map represents the global default options that should be used
* when applying constraints. They can be overridden via custom maps
* passed into the functions.
*
*///--------------------------------------------------------------------------
var defaultOptions = {
invalidHandler : function(el){},
placeholder : "_",
alwaysShowMask : true,
permitIncomplete : false,
selectOnFocus : true
};
/*-----------------------------------------------------------------------------
*
* Carat Object
*
*-----------------------------------------------------------------------------
*
* The Carat object encapsulates carat functionality such as setting and
* getting selections and postions.
*
* @constructor
*
*///--------------------------------------------------------------------------
var Carat = function(s,e){
this.start = s || 0;
this.end = e || s || 0;
}
Carat.prototype = {
/*-------------------------------------------------------------------------
*
* isSelection
*
*-------------------------------------------------------------------------
*
* Determines if the current carat position is a selection or not
*
*///----------------------------------------------------------------------
isSelection:function(){
return this.start < this.end;
},
start : this.start,
end : this.end
}
/*-----------------------------------------------------------------------------
*
* getCaratPosition
*
*-----------------------------------------------------------------------------
*
* Based on the passed in input field this function will return the current
* carat position as an object with a start and end property. This allows
* for both single carat positions and whole selection ranges
*
* @param el element to extract carat position from
*
*///--------------------------------------------------------------------------
Carat.getCaratPosition = function(el){
if (el.setSelectionRange){
return new Carat(el.selectionStart, el.selectionEnd);
}else if (document.selection && document.selection.createRange){
var range = document.selection.createRange();
var start = 0 - range.duplicate().moveStart('character', -100000);
return new Carat(start, start + range.text.length);
}
}
/*-----------------------------------------------------------------------------
*
* Set Carat Position
*
*-----------------------------------------------------------------------------
*
* Sets the postion of the carat on the passed in element. Can be a single
* postion of a selection.
*
* @param el element to set carat position omn
* @param from start position of carat
* @param to end position of carat (optional)
*
*///--------------------------------------------------------------------------
Carat.setCaratPosition = function(el, c){
if(el.setSelectionRange){
el.focus();
el.setSelectionRange(c.start,c.end);
}else if (el.createTextRange){
var range = el.createTextRange();
range.collapse(true);
range.moveEnd('character', c.end);
range.moveStart('character', c.start);
range.select();
}
}
/*-----------------------------------------------------------------------------
*
* Mask Buffer Class
*
*-----------------------------------------------------------------------------
*
* The Mask Buffer Class houses all the internal buffer mechanisms asnd
* provides a cleaner interface for working with buffers.
*
*///--------------------------------------------------------------------------
var MaskBuffer = function(m, p){
/*-------------------------------------------------------------------------
*
* isFixedCharacter
*
*-------------------------------------------------------------------------
*
* Determines if the postion within the passed in mask is a fixed
* character or if it is a mask character
*
* @param m - the mask
* @param postion - position to check
*
*///----------------------------------------------------------------------
this.isFixedCharacter = function(m, position){
return !availableMasks[m.charAt(position)];
}
/*-------------------------------------------------------------------------
*
* Generate RegExp
*
*-------------------------------------------------------------------------
*
* Build up a complete mask regualr expression to validate the enitre
* input upon blur and paste events.
*
*///----------------------------------------------------------------------
var parsedMask = $.map(m.split(""), function(it){
return availableMasks[it] || (/[A-Za-z0-9]/.test(it)?"":"\\") + it;
});
this.fullRegEx = new RegExp("^" + parsedMask.join("") + "$");
/*-------------------------------------------------------------------------
*
* Initialize Object
*
*-------------------------------------------------------------------------
*
* Build the initial buffer, find the first mask character position and
* store the values internall in this object
*
*///----------------------------------------------------------------------
this.start = m.length;
this.buffer = new Array(m.length);
for(var i = m.length-1; i >= 0; i--){
if(!this.isFixedCharacter(m,i)){
this.start = i;
this.buffer[i] = p;
}else{
this.buffer[i] = m.charAt(i);
}
}
this.initial = $.map(this.buffer, function(e){return e}),
this.mask = m;
}
/* Extend the object */
MaskBuffer.prototype = {
/*-------------------------------------------------------------------------
*
* getInitialMask
*
*-------------------------------------------------------------------------
*
* Returns a copy of the initial mask array that was used to create
* this buffer instance. A copy is returned to to prevent any pass by
* reference overwritting.
*
*///----------------------------------------------------------------------
getInitialMask: function(){
return $.map(this.initial, function(e){return e}); // clone
},
/*-------------------------------------------------------------------------
*
* getStartingMaskPosition
*
*-------------------------------------------------------------------------
*
* Returns the index of the first mask (i.e. non fixed) character in the
* mask
*
*///----------------------------------------------------------------------
getStartingMaskPosition: function(){
return this.start;
},
/*-------------------------------------------------------------------------
*
* nextMaskPostion
*
*-------------------------------------------------------------------------
*
* from the passed in index returns the postion of the next non fixed
* mask character.
*
*///----------------------------------------------------------------------
nextMaskPosition : function(i){
var target = i||0;
while(++target < this.mask.length){
if(!this.isFixedCharacter(this.mask,target)){
return target;
}
}
return this.mask.length;
},
/*-------------------------------------------------------------------------
*
* get
*
*-------------------------------------------------------------------------
*
* Returns, depending on the arguments passed, either the string value of
* the current buffer state of the character at the passed index of the
* buffer
*
*///----------------------------------------------------------------------
get: function(){
return (arguments.length === 0)?this.buffer.join(''):this.buffer[arguments[0]];
},
/*-------------------------------------------------------------------------
*
* getMaskValue
*
*-------------------------------------------------------------------------
*
* Returns the character of the mask at the current position
*
*///----------------------------------------------------------------------
getMaskValue: function(idx){
return this.mask.charAt(idx);
},
/*-------------------------------------------------------------------------
*
* size
*
*-------------------------------------------------------------------------
*
* Returns the length of the buffer/mask/initial mask etc
*
*///----------------------------------------------------------------------
size: function(){
return this.buffer.length;
},
/*-------------------------------------------------------------------------
*
* set
*
*-------------------------------------------------------------------------
*
* Sets either the enitre buffer or a specific character of the buffer.
*
* @param i Array|Number. The array to set the buffer to or the postion
* of the character to set the value of
* @param v Boolean|Character. If boolean then it makes determines if a
* clone of the array is to be used. If character it is the
* character to put in the current position of the buffer;
*
*///----------------------------------------------------------------------
set: function(i,v){
if(i.constructor === Array){
this.buffer = (v)?$.map(i, function(e){return e}):i;
}else{
this.buffer[i] = v;
}
},
/*-------------------------------------------------------------------------
*
* reset
*
*-------------------------------------------------------------------------
*
* Resets, returns back to the inital mask, all/some/one part of the
* current buffer depending on inputs
*
*///----------------------------------------------------------------------
reset: function(){
var start, end;
switch(arguments.length){
case 0 : start = 0; end = this.buffer.length; break;
case 1 : start = end = arguments[0]; break;
case 2 : start = arguments[0]; end = arguments[1]; break;
}
for(var i = start; i <= end; i++){
this.buffer[i] = this.initial[i];
}
},
/*-------------------------------------------------------------------------
*
* test
*
*-------------------------------------------------------------------------
*
* Test current buffer state against the complete RegExp of the field to
* determine if it is invliad/incomplete
*
*///----------------------------------------------------------------------
test: function(){
return this.fullRegEx.test(this.buffer.join(''));
}
}
/*-----------------------------------------------------------------------------
*
* Public API
*
*-----------------------------------------------------------------------------
*
* Extend the core jQuery object to allow access to the public functions
* for the plugin functionality
*
*///--------------------------------------------------------------------------
$.extend({
/* $.fn.mask
* $.fn.unmask
* $.applyMasks
*/
mask : {
//-- CONFIGURATION ACCESSORS ------------------------------------------
availableMasks : availableMasks,
options : defaultOptions,
/*---------------------------------------------------------------------
*
* Unistall plugin
*
*---------------------------------------------------------------------
*
* Unistall the entire plugin by deregistering all events and data
* caches in the document but also delete the objects from memory.
*
*///------------------------------------------------------------------
uninstall: function(){
/* UNMASK */
$.annotated("@Mask", document).unmask();
/* GARBAGE COLLECT */
delete(availableMasks);
delete($.applyMasks);
delete($.fn.mask);
delete($.fn.unmask);
delete(defaultOptions);
delete(Carat);
delete(MaskBuffer);
delete($.carat);
delete($.mask);
}
},
carat : {
get : Carat.getCaratPosition,
set : Carat.setCaratPosition
}
});
})(jQuery);
DOS Batch 删除Seapine Surround SCM绑定
attrib -r *.* /s
del /s *.MySCMServerInfo
del /s *.vspscc
XML 字符串的XSD Facets:length,minLength,maxLength
<?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="SONG" type="songType"/> <xsd:simpleType name="Str255"> <xsd:restriction base="xsd:string"> <xsd:minLength value="1"/> <xsd:maxLength value="255"/> </xsd:restriction> </xsd:simpleType> <xsd:complexType name="songType"> <xsd:sequence> <xsd:element name="TITLE" type="Str255"/> <xsd:element name="COMPOSER" type="Str255" maxOccurs="unbounded"/> <xsd:element name="PRODUCER" type="Str255" minOccurs="0" maxOccurs="unbounded"/> <xsd:element name="PUBLISHER" type="Str255" minOccurs="0"/> <xsd:element name="LENGTH" type="xsd:timeDuration"/> <xsd:element name="YEAR" type="xsd:gYear"/> <xsd:element name="ARTIST" type="Str255" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
PHP 递归遍历文件夹到多维数组
<?php
error_reporting(E_ALL);
header('Content-Type: text/plain; charset=utf-8');
$dir = dirname(__FILE__).'/';
$tree = dir_tree($dir);
print_r($tree);
function dir_tree($dir)
{
static $tree = array();
static $child = false;
// Detect the current branch to append files/directories to
if ($child !== false && isset($tree[$child]))
{
$branch =& $tree[$child];
}
else
{
$branch =& $tree;
}
// Force trailing slash on directory
$dir = rtrim($dir, '/').'/';
$dirlen = strlen($dir);
// Find files/directories
$items = glob($dir.'*');
foreach($items as $key => $item)
{
// Get basename
$base = pathinfo($item, PATHINFO_BASENAME); //substr($item, $dirlen);
// always skip dot files
if ($base[0] == '.') continue;
// If file
if(is_file($item) && is_readable($item))
{
$branch[] = $base;
$child = false;
continue;
}
// If directory
if(is_dir($item) && is_readable($item))
{
// Dirty hack to get around PHP's numerical index rules
if (ctype_digit($base))
$base = '~'.$base;
$branch[$base] = array();
$child = $base;
dir_tree($item);
continue;
}
}
// Only return from the root call
if ($child === false)
return $tree;
}
C# AccessHelper
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace Web.DataAccess
{
public class AccessHelper
{
#region private method & constructor
private AccessHelper() { }
private static void PrepareCommand(OleDbCommand command, OleDbConnection connection, OleDbTransaction transaction, string commandText, OleDbParameter[] commandParameters, out bool mustCloseConnection)
{
if (null == command) throw new ArgumentNullException("command");
if (null == commandText || string.Empty == commandText) throw new ArgumentNullException("commandText");
if (ConnectionState.Closed == connection.State)
{
connection.Open();
mustCloseConnection = true;
}
else
{
mustCloseConnection = false;
}
command.Connection = connection;
command.CommandText = commandText;
if (null != transaction)
{
if (null == transaction.Connection) throw new ArgumentException("transaction对象commitedå’Œrollbacked需è¦ä¸€ä¸ªå·²æ‰“开的事务", "transaction");
command.Transaction = transaction;
}
command.CommandType = CommandType.Text;
if (null != commandParameters)
{
AttachParameters(command, commandParameters);
}
}
private static void AttachParameters(OleDbCommand command, OleDbParameter[] commandParameters)
{
if (null == command) throw new ArgumentNullException("command");
if (null != commandParameters)
{
foreach (OleDbParameter p in commandParameters)
{
if (null != p)
{
if ((ParameterDirection.Input == p.Direction || ParameterDirection.InputOutput == p.Direction) && (null == p.Value))
{
p.Value = DBNull.Value;
}
command.Parameters.Add(p);
}
}
}
}
#endregion private method & constructor
#region ExecuteNonQuery
public static int ExecuteNonQuery(string connectionstring, string commandText)
{
return ExecuteNonQuery(connectionstring, commandText, (OleDbParameter[])null);
}
public static int ExecuteNonQuery(string connectionString, string commandText, params OleDbParameter[] commandParameters)
{
if (null == connectionString || string.Empty == connectionString) throw new ArgumentNullException("connectionString");
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
return ExecuteNonQuery(connection, commandText, commandParameters);
}
}
public static int ExecuteNonQuery(OleDbConnection connection, string commandText)
{
return ExecuteNonQuery(connection, commandText, (OleDbParameter[])null);
}
public static int ExecuteNonQuery(OleDbConnection connection, string commandText, params OleDbParameter[] commandParameters)
{
if (null == connection) throw new ArgumentNullException("connection");
OleDbCommand cmd = new OleDbCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, connection, (OleDbTransaction)null, commandText, commandParameters, out mustCloseConnection);
int retval = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
if (mustCloseConnection) connection.Close();
return retval;
}
public static int ExecuteNonQuery(OleDbTransaction transaction, string commandText)
{
return ExecuteNonQuery(transaction, commandText, (OleDbParameter[])null);
}
public static int ExecuteNonQuery(OleDbTransaction transaction, string commandText, params OleDbParameter[] commandParameters)
{
if (null == transaction) throw new ArgumentNullException("transaction");
if (null != transaction && null == transaction.Connection) throw new ArgumentException("transaction对象commitedå’Œrollbacked需è¦ä¸€ä¸ªå·²æ‰“开的事务", "transaction");
OleDbCommand cmd = new OleDbCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, transaction.Connection, transaction, commandText, commandParameters, out mustCloseConnection);
int retval = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return retval;
}
#endregion ExecuteNonQuery
#region ExecuteScalar
public static object ExecuteScalar(string connectionString, string commandText)
{
return ExecuteScalar(connectionString, commandText, (OleDbParameter[])null);
}
public static object ExecuteScalar(string connectionString, string commandText, params OleDbParameter[] commandParameters)
{
if (null == connectionString && string.Empty == connectionString) throw new ArgumentNullException("connectionString");
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
return ExecuteScalar(connection, commandText, commandParameters);
}
}
public static object ExecuteScalar(OleDbConnection connection, string commandText)
{
return ExecuteScalar(connection, commandText, (OleDbParameter[])null);
}
public static object ExecuteScalar(OleDbConnection connection, string commandText, params OleDbParameter[] commandParameters)
{
if (null == connection) throw new ArgumentNullException("connection");
OleDbCommand cmd = new OleDbCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, connection, (OleDbTransaction)null, commandText, commandParameters, out mustCloseConnection);
object retval = cmd.ExecuteScalar();
cmd.Parameters.Clear();
if (mustCloseConnection)
connection.Close();
return retval;
}
public static object ExecuteScalar(OleDbTransaction transaction, string commandText)
{
return ExecuteScalar(transaction, commandText, (OleDbParameter[])null);
}
public static object ExecuteScalar(OleDbTransaction transaction, string commandText, params OleDbParameter[] commandParameters)
{
if (null == transaction) throw new ArgumentNullException("transaction");
if (null != transaction && null == transaction.Connection) throw new ArgumentException("transaction对象commitedå’Œrollbacked需è¦ä¸€ä¸ªå·²æ‰“开的事务", "transaction");
OleDbCommand cmd = new OleDbCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, transaction.Connection, transaction, commandText, commandParameters, out mustCloseConnection);
object retval = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return retval;
}
#endregion ExecuteScalar
#region ExecuteReader
private enum OleDbConnectionOwnership
{
/// <summary>
/// 连接对象是由SqlHelper管ç†çš„
/// </summary>
Internal,
/// <summary>
/// 连接对象是由调用者管ç†çš„
/// </summary>
External
}
private static OleDbDataReader ExecuteReader(OleDbConnection connection, OleDbTransaction transaction, string commandText, OleDbParameter[] commandParameters, OleDbConnectionOwnership connectionOwnership)
{
if (null == connection) throw new ArgumentNullException("connection");
bool mustCloseConnection = false;
OleDbCommand cmd = new OleDbCommand();
try
{
PrepareCommand(cmd, connection, transaction, commandText, commandParameters, out mustCloseConnection);
OleDbDataReader dataReader;
if (OleDbConnectionOwnership.External == connectionOwnership)
{
dataReader = cmd.ExecuteReader();
}
else
{
dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
bool canClear = true;
foreach (OleDbParameter commandParameter in cmd.Parameters)
{
if (ParameterDirection.Input != commandParameter.Direction) canClear = false;
}
if (canClear)
{
cmd.Parameters.Clear();
}
return dataReader;
}
catch
{
if (mustCloseConnection) connection.Close();
throw;
}
}
public static OleDbDataReader ExecuteReader(OleDbConnection connection, string commandText)
{
return ExecuteReader(connection, commandText, (OleDbParameter[])null);
}
public static OleDbDataReader ExecuteReader(OleDbConnection connection, string commandText, params OleDbParameter[] commandParameters)
{
return ExecuteReader(connection, (OleDbTransaction)null, commandText, commandParameters, OleDbConnectionOwnership.External);
}
public static OleDbDataReader ExecuteReader(OleDbTransaction transaction, string commandText)
{
return ExecuteReader(transaction, commandText, (OleDbParameter[])null);
}
public static OleDbDataReader ExecuteReader(OleDbTransaction transaction, string commandText, params OleDbParameter[] commandParameters)
{
if (null == transaction) throw new ArgumentNullException("transaction");
if (null != transaction && null == transaction.Connection) throw new ArgumentException("transaction对象commitedå’Œrollbacked需è¦ä¸€ä¸ªå·²æ‰“开的事务", "transaction");
return ExecuteReader(transaction.Connection, transaction, commandText, commandParameters, OleDbConnectionOwnership.External);
}
public static OleDbDataReader ExecuteReader(string connectionString, string commandText)
{
return ExecuteReader(connectionString, commandText, (OleDbParameter[])null);
}
public static OleDbDataReader ExecuteReader(string connectionString, string commandText, params OleDbParameter[] commandParameters)
{
if (null == connectionString || string.Empty == connectionString) throw new ArgumentNullException("connectionString");
OleDbConnection connection = null;
try
{
connection = new OleDbConnection(connectionString);
connection.Open();
return ExecuteReader(connection, (OleDbTransaction)null, commandText, commandParameters, OleDbConnectionOwnership.Internal);
}
catch
{
if (connection != null) connection.Close();
throw;
}
}
#endregion ExecuteReader
#region ExecuteDataset
public static DataSet ExecuteDataset(string connectionString, string commandText)
{
return ExecuteDataset(connectionString, commandText, (OleDbParameter[])null);
}
public static DataSet ExecuteDataset(string connectionString, string commandText, params OleDbParameter[] commandParameters)
{
if (null == connectionString || string.Empty == connectionString) throw new ArgumentNullException("connectionString");
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
return ExecuteDataset(connectionString, commandText, commandParameters);
}
}
public static DataSet ExecuteDataset(OleDbConnection connection, string commandText)
{
return ExecuteDataset(connection, commandText, (OleDbParameter[])null);
}
public static DataSet ExecuteDataset(OleDbConnection connection, string commandText, params OleDbParameter[] commandParameters)
{
if (null == connection) throw new ArgumentNullException("connection");
OleDbCommand cmd = new OleDbCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, connection, (OleDbTransaction)null, commandText, commandParameters, out mustCloseConnection);
using (OleDbDataAdapter da = new OleDbDataAdapter(cmd))
{
DataSet ds = new DataSet();
da.Fill(ds);
cmd.Parameters.Clear();
if (mustCloseConnection)
connection.Close();
return ds;
}
}
public static DataSet ExecuteDataset(OleDbTransaction transaction, string commandText)
{
return ExecuteDataset(transaction, commandText, (OleDbParameter[])null);
}
public static DataSet ExecuteDataset(OleDbTransaction transaction, string commandText, params OleDbParameter[] commandParameters)
{
if (null == transaction) throw new ArgumentNullException("transaction");
if (null != transaction && null == transaction.Connection) throw new ArgumentException("transaction对象commitedå’Œrollbacked需è¦ä¸€ä¸ªå·²æ‰“开的事务", "transaction");
OleDbCommand cmd = new OleDbCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, transaction.Connection, transaction, commandText, commandParameters, out mustCloseConnection);
using (OleDbDataAdapter da = new OleDbDataAdapter(cmd))
{
DataSet ds = new DataSet();
da.Fill(ds);
cmd.Parameters.Clear();
return ds;
}
}
#endregion ExecuteDataset
}
}