`
mr.a
  • 浏览: 93448 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
string that does not contain pattern
/^(?!.*PATTERN).*/.test('xx..fasf..PATTERN...')  // false

// (?!.*PATTERN) -- forward negative -- next letters do not match .*PATTERN

replaceLast regular expression
"@ss@ff@vv@ff@".replace(/@(?!.*@.*$)/, ''); // ?! --  negative lookahead http://www.regular-expressions.info/lookaround.html

// output: @ss@ff@vv@ff
String does not have certain patterns regular expression
example1:
"\$ref": "#/definitions/(?!success|total|ip_prefix|message|error_args|ip|code|resp)+

example2:
"(?!total|message|schema|success|code|items|errArgs|result).+": {.*\n.+"\$ref": ".+\n.+}


example3:
ss = 'xxdfas..fa..@...@fff.m@xxiff@fa'

ss.match(/@(?!.*@.*$)/)
["@", index: 28, input: "xxdfas..fa..@...@fff.m@xxiff@fa", groups: undefined]

ss.replace(/@(?!.*@.*$)/, '{}')
"xxdfas..fa..@...@fff.m@xxiff{}fa"

explaination: /@(?!.*@.*$)/  前瞻否定 匹配项@ 后面的字符串不匹配括号中的表达式(?!.*@.*$)

https://blog.csdn.net/joe_007/article/details/44947325 前瞻 后置
n2n edge shell
#!/bin/sh /etc/rc.common
#
# Copyright (C) 2014 Justin Liu <rssnsj@gmail.com>
# https://github.com/rssnsj/network-feeds
#


START=97
STOP=97
NAME=edge

start () {
    echo "Starting $NAME..."
    service_start /usr/bin/edge -a 10.1.0.111 -c p2pnet -k 333 -l yycuii.com:5566 -m 11:a1:af:a7:87:1b -f || return 2

}
~
ssh proxy config linux
ssh -o ProxyCommand='nc -x 10.0.0.123:1080 %h %p' user@serveraddr
unfinished Promise Test js
Promise = function () {
}

Promise.prototype.then = function (resolve, reject) {

	this.res = resolve;

	var p = this.res();
	p.parent = this;
	return p;
}

Promise.prototype.resolve = function (t) {
	this.arg = t;
	this.res && this.res();
}

Promise.prototype.reject = function () {}

fn1 = function () {
	var p = new Promise();

	Ext.Ajax.request({
		url : 'index.html',
		success : function (res) {

			p.resolve(res.responseText);
		},
		failure : function () {
			p.reject(res);
		}
	});	

	return p;
}

fn2 = function (text) {
	var p = new Promise(text);

	Ext.Ajax.request({
		url : 'index.html',
		success : function (res) {
			console.log(3)
			p.resolve(res.responseText + p.parent.arg);
		},
		failure : function () {
			p.reject(res);
		}
	});	

	return p;
}

fn1().then(fn2).then(function (t) {console.log(t)})
waterfall js, css, html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Jquery瀑布流布局(每行代码都有详细注释)-作者:刘晓帆</title>
<style type="text/css">
body, ul, li, h3 { margin: 0; padding: 0; list-style: none; font: bold 12px "微软雅黑"; }
/*瀑布流布局样式*/
#lxf-box { position: relative; }
#lxf-box li { position: absolute; background: #fff; border: solid 1px #ccc; text-align: center; padding: 10px; left: 0px; top: 0; }
h3 { padding-top: 8px; }
img { width: 200px; height: auto; display: block; border: 0 }
/*css3动画*/
li { -webkit-transition: all .3s ease-out .1s; -moz-transition: all .3s ease-out; -o-transition: all .3s ease-out .1s; transition: all .3s ease-out .1s }
</style>
<script src="http://liuxiaofan.com/demo/js/jquery-1.6.4.min.js" type="text/javascript"></script>
</head>
<body>
<ul id="lxf-box" style="margin:0 auto;position:absolute;top:400px;">
  <li><a href="javascript:;"><img src="http://img3.cache.netease.com/photo/0001/2015-12-05/BA2O42RD00AO0001.jpg"></a>
    <h3>图片标题</h3>
  </li>
  <li><a href="javascript:;"><img src="http://img2.cache.netease.com/photo/0001/2015-12-05/BA2O42RC00AO0001.jpg"></a>
    <h3>图片标题</h3>
  </li>
  <li><a href="javascript:;"><img src="http://img3.cache.netease.com/photo/0001/2015-12-05/BA2O42RE00AO0001.jpg"></a>
    <h3>图片标题</h3>
  </li>
  <li><a href="javascript:;"><img src="http://img3.cache.netease.com/photo/0001/2015-12-05/BA2O42RF00AO0001.jpg"></a>
    <h3>图片标题</h3>
  </li>
  <li><a href="javascript:;"><img src="http://img3.cache.netease.com/photo/0001/2015-12-05/BA2O42RG00AO0001.jpg"></a>
    <h3>图片标题</h3>
  </li>
  <li><a href="javascript:;"><img src="http://img3.cache.netease.com/photo/0001/2015-12-05/BA2O42RI00AO0001.jpg"></a>
    <h3>图片标题</h3>
  </li>
  <li><a href="javascript:;"><img src="http://img3.cache.netease.com/photo/0001/2015-12-05/BA2O42RI00AO0001.jpg"></a>
    <h3>图片标题</h3>
  </li>
  <li><a href="javascript:;"><img src="http://img3.cache.netease.com/photo/0001/2015-12-05/BA2O42RK00AO0001.jpg"></a>
    <h3>图片标题</h3>
  </li>
  <li><a href="javascript:;"><img src="http://img5.cache.netease.com/cnews/2015/12/3/201512032347544d8ff.jpg "></a>
    <h3>图片标题</h3>
  </li>
  
</ul>
<script>
/*
原理:1.把所有的li的高度值放到数组里面
     2.第一行的top都为0
	 3.计算高度值最小的值是哪个li
	 4.把接下来的li放到那个li的下面
作者:刘晓帆
博客地址:[url]http://liuxiaofan.com[/url]
编写时间:2012年6月9日
*/
var margin = 10;//这里设置间距
var li=$("li");//这里是区块名称
var	li_W = li[0].offsetWidth+margin;//取区块的实际宽度(包含间距,这里使用源生的offsetWidth函数,不适用jQuery的width()函数是因为它不能取得实际宽度,例如元素内有pandding就不行了)
function liuxiaofan(){//定义成函数便于调用
	var h=[];//记录区块高度的数组
	var n = document.documentElement.offsetWidth/li_W|0;//窗口的宽度除以区块宽度就是一行能放几个区块
	
	var offsetLeft =(document.documentElement.offsetWidth - n*li_W + margin)/2;
	for(var i = 0;i < li.length;i++) {//有多少个li就循环多少次
		li_H = li[i].offsetHeight;//获取每个li的高度
		if(i < n) {//n是一行最多的li,所以小于n就是第一行了
			h[i]=li_H;//把每个li放到数组里面
			li.eq(i).css("top",0);//第一行的Li的top值为0
			li.eq(i).css("left",i * li_W + offsetLeft);//第i个li的左坐标就是i*li的宽度
			}
		else{
			min_H =Math.min.apply(null,h) ;//取得数组中的最小值,区块中高度值最小的那个
			minKey = getarraykey(h, min_H);//最小的值对应的指针
			h[minKey] += li_H+margin ;//加上新高度后更新高度值
			li.eq(i).css("top",min_H+margin);//先得到高度最小的Li,然后把接下来的li放到它的下面
			li.eq(i).css("left",minKey * li_W + offsetLeft);	//第i个li的左坐标就是i*li的宽度
		}
		$("h3").eq(i).text("编号:"+i+",高度:"+li_H);//把区块的序号和它的高度值写入对应的区块H3标题里面
	}
}
/* 使用for in运算返回数组中某一值的对应项数(比如算出最小的高度值是数组里面的第几个) */
function getarraykey(s, v) {for(k in s) {if(s[k] == v) {return k;}}}
/*这里一定要用onload,因为图片不加载完就不知道高度值*/
window.onload = function() {liuxiaofan();};
/*浏览器窗口改变时也运行函数*/
window.onresize = function() {liuxiaofan();};
</script>
</body>
</html>
replace a string with multi patterns in one batch regular expression, js
Ext.Ajax.request({  
        url : 'data.json',  
        success : function (res) {  
  
            var t = res.responseText;  
  
            console.log(t.length);  
  
            var d = (new Date).getTime();  
  
            var o = {};  
            o['.'] = 'A';  
            o[';'] = 'B';  
            o['-'] = 'C';  
            o[','] = 'D';  
  
            var reg = (function () {  
                var a = [];  
                for (var p in o) {  
                    a.push(p);  
                }  
  
                return RegExp(a.join('|'));  
            })();  
  
            t = t.replace(reg, function (match, s) {  
                    return o[match];  
                });  
  
            var d1 = (new Date).getTime();  
  
            console.log(d1 - d);  
        }  
    });
regx的前后查找 regular expression
/****
http://blog.csdn.net/wzzfeitian/article/details/8867888

warning:
  向前查找模式的长度是可变的,它们可以包含.和+之类的元字符,所以它们非常灵活。
而向后查找模式只能是固定长度,这是一条几乎所有的正则表达式实现都遵守的限制。

测试发现js似乎不支持向后查找

向前: (?=*.*)
向后: (?>=*.*)

*/

var str = 'a,b,c,d.e;f.';

str.split(/\s*(?=\.|\;|\,)/);

// result:
// ["a", ",b", ",c", ",d", ".e", ";f", "."]


/[^\-](?=policy)/ // 匹配前驱字符不是'-'的'policy'
reset mysql 5.7root password mysql
http://dev.mysql.com/doc/mysql-windows-excerpt/5.0/en/resetting-permissions-windows.html

On Windows, use the following procedure to reset the password for all MySQL root accounts:

Log on to your system as Administrator.

Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list and stop it.

If your server is not running as a service, you may need to use the Task Manager to force it to stop.

Create a text file containing the following statements. Replace the password with the password that you want to use.

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
Write the UPDATE and FLUSH statements each on a single line. The UPDATE statement resets the password for all root accounts, and the FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.

Save the file. For this example, the file will be named C:\mysql-init.txt.

Open a console window to get to the command prompt: From the Start menu, select Run, then enter cmd as the command to be run.

Start the MySQL server with the special --init-file option (notice that the backslash in the option value is doubled):

C:\> C:\mysql\bin\mysqld-nt --init-file=C:\\mysql-init.txt
If you installed MySQL to a location other than C:\mysql, adjust the command accordingly.

The server executes the contents of the file named by the --init-file option at startup, changing each root account password.

You can also add the --console option to the command if you want server output to appear in the console window rather than in a log file.

If you installed MySQL using the MySQL Installation Wizard, you may need to specify a --defaults-file option:

C:\> "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe"
         --defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini"
         --init-file=C:\\mysql-init.txt
The appropriate --defaults-file setting can be found using the Services Manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list, right-click it, and choose the Properties option. The Path to executable field contains the --defaults-file setting.

After the server has started successfully, delete C:\mysql-init.txt.

You should now be able to connect to the MySQL server as root using the new password. Stop the MySQL server, then restart it in normal mode again. If you run the server as a service, start it from the Windows Services window. If you start the server manually, use whatever command you normally use.
Match url param names regular expression
'a=1&b=2&c=&d=5&'.match(/[^&]+?(?==)/g)

/* reault: ['a', 'b', 'c', 'd']
    +?    重复1次或更多次,但尽可能少重复
    (?==) 前瞻断言 字符串位于等号之前
*/
判断js基本类型 js
        /**
         * Returns true if the passed value is a JavaScript 'primitive',
         * a string, number or boolean.
         * @param {Object} value The value to test
         * @return {Boolean}
         */
        isPrimitive: function(value) {
            var type = typeof value;

            return type === 'string' || type === 'number' || type === 'boolean';
        }
Date.prototype.format js
Date.prototype.format=function(fmt) {
    var o = {
	    "m+" : this.getMonth()+1<10? '0'+(this.getMonth()+1):this.getMonth()+1, //月份
	    "d+" : this.getDate()<10?'0'+this.getDate():this.getDate(), //日
	    "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时
	    "H+" : this.getHours()<10?'0'+this.getHours():this.getHours(), //小时
	    "i+" : this.getMinutes()<10?'0'+this.getMinutes():this.getMinutes(), //分
	    "s+" : this.getSeconds()<10?'0'+this.getSeconds():this.getSeconds(), //秒
	    "q+" : Math.floor((this.getMonth()+3)/3), //季度
	    "S" : this.getMilliseconds() //毫秒
    };
    var week = {
	    "0" : "\日",
	    "1" : "\一",
	    "2" : "\二",
	    "3" : "\三",
	    "4" : "\四",
	    "5" : "\五",
	    "6" : "\六"
    };
    if(/(Y+)/.test(fmt)){
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+""));//.substr(4 - RegExp.$1.length));
    }
    if(/(E+)/.test(fmt)){
        fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "\星\期" : "\周") : "")+week[this.getDay()+""]);
    }
    for(var k in o){
        if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }
    return fmt;
}
根据不同的浏览器返回ajax对象 js, ajax
/**
 *根据不同的浏览器返回ajax对象
 *
 */
{
  _getAjaxObject : function () {
    var xmlHttp;
    if(window.XMLHttpRequest) {
      xmlHttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
      if (!xmlHttp ) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
    return xmlHttp;
  }
 
}
使用闭包生成唯一的id js, 闭包
util.genId = (function() {
  var prefix = "yourprefix", id = 0;
  return function() {
    return prefix + "_" + id++;
  } 
})();
taskManager js, widget
/**
 * taskManager
 * 使用方法:
 * var task = {
 * 	run : function() {
 *  	// do something
 *  },
 *  interval : 10000  // 10 seconds
 * }
 * $.fn.TaskManager.start(task);
 * $.fn.TaskManager.stop(task);
 */
$.fn.TaskManager = {
	start : function(task) {
		try {
			var t = setInterval(task.run, task.interval);
			this.tasks[t] = task;
		} catch (e) {
		}
	},
	tasks : {},
	stopAll : function() {
		$.each(this.tasks, function(task) {
			clearInterval(task);
		});
	},
	stop : function(task) {
		if (typeof task == "number") {
			clearInterval(task);
		} else {
			for ( var i in this.tasks) {
				if (this.tasks[i] == task) {
					clearInterval(i);
					delete this.tasks[i];
				}
			}
		}

	}
};
match a package name split by "." regular expression
/^([^\.]+\.)+[^\.]+$/.test("com.xp.test.regx1"); // true


// "+" 匹配至少一次
MAC Regex regular expression
MAC Regex : /^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$/
replace brases using regex regular expression
"AAAAAA{a}BBBBB{b}CCCC".replace(/\{[^\}]*\}/g, "@");  // "AAAAAA@BBBBB@CCCC"

[^\}] 表示非}的字符
replace return & spaces in ajax responseText regular expression
xhr.responseText = xhr.responseText.replace("/[\r\n]\s*/g", "");
用于获得对象类型的工具方法 js JS对象类型的确定
function getType(x){
	if(x==null){
		return "null";
	}
	var t= typeof x;
	if(t!="object"){
		return t;
	}
	var c=Object.prototype.toString.apply(x);
	c=c.substring(8,c.length-1);
	if(c!="Object"){
		return c;
	}
	if(x.constructor==Object){
		return c
	}
	if("classname" in x.prototype.constructor
			&& typeof x.prototype.constructor.classname=="string"){
		return x.constructor.prototype.classname;
	}
	return "<unknown type>";
}
Match a string that has Chinese character regular expression
match one Chinese character /^[\u4e00-\u9fa5]$/

match at least one Chinese character /^.*[\u4e00-\u9fa5].*$/
Global site tag (gtag.js) - Google Analytics