Skip to content

Instantly share code, notes, and snippets.

@wcccode
wcccode / swap.js
Created March 16, 2015 08:56
手机滑动
function Swap(opt){
var b = this.extend(this.defaultOpt, this.extend({} , opt || {}) ),
obj = document.getElementById(b.targetId);
b.touchAble = ("ontouchstart" in window) || window.DocumentTouch && document instanceof DocumentTouch,
b.obj = obj;
function start(e){
e = e ? e : event,
e.targetTouches ? (b.startX = e.targetTouches[0].clientX, b.startY = e.targetTouches[0].clientY) :
(b.startX = e.clientX, b.startY = e.clientY);
@wcccode
wcccode / unicodeSequence.js
Created March 4, 2015 07:55
javascript unicode转义字符相互转化
function fromUnicode (str) {
var runicode = /\\u([a-f0-9]{4})/gi;
str += '';
return str.replace(runicode, function (m, hex) {
return String.fromCharCode(parseInt(hex, 16));
});
}
function toUnicode (str) {
str += '';
@wcccode
wcccode / node_reject_unauthorized.js
Last active August 29, 2015 14:16
NODE_TLS_REJECT_UNAUTHORIZED 忽略https自签名验证
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
@wcccode
wcccode / apache&tomcat.txt
Created February 28, 2015 01:06
Apache和Tomcat的整合
Apache和Tomcat的整合,原理及例子
这类文档很多很多,但是大多是由不明原理的人拘泥于具体版本写出来的,有很多错漏或多余的部分。
最后找到一篇写得很很不错的,http://macawspark.spaces.live.com/blog/
我修正了其中的错误然后加了一些自己的理解
原理
tomcat 为一个jsp的容器,apache为一个web server,两者之间通信通过worker进行(由Tomcat使用Server.xml文件中Connector的标签来定义其端口和协议),通过 mod_jk的模块(由web服务器像apache、iis等使用)和Web Server通信。
通信协议有很多,其中jk2已经被抛弃了,现在就用jk就好了。
整个过程其实就是让apache的httpd.conf文件调用mod_jk.conf,mod_jk.conf调用workers.properties,最后配置虚拟主机。
文件说明
mod_jk.conf
@wcccode
wcccode / encodeToGbk
Created February 13, 2015 07:20
encode to gbk
var _charHash = (function() {
var data = (function (zipData) {
var re = zipData.replace(/#(\d+)\$/g, function (a, b) {
return new Array(+b+3).join('#');
}).replace(/#/g,'####').replace(/(\w\w):([\w#]+)(?:,|$)/g, function (a, hd, dt) {
return dt.replace(/../g, function (a) {
if (a !== '##') {
return hd + a;
} else {
return a;
@wcccode
wcccode / shell
Last active August 29, 2015 14:15
$$
Shell本身的PID(ProcessID)
$!
Shell最后运行的后台Process的PID
$?
最后运行的命令的结束代码(返回值)
$-
使用Set命令设定的Flag一览
$*
所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。

UNINCORPORATED FACTS

  • _tickCallback processes the process.nextCallback queue
  • setTimeout cannot have a timeout smaller than 1
  • domains make changes

Understanding the Node event loop

There are two important things to remember about the Node event loop. The

@wcccode
wcccode / connect.md
Last active August 29, 2015 14:09
understand source code of node connect

#connect 源码学习 这里主要说下connect的路由拦截处理。connect可以添加多个中间件或路由对http的请求进行处理。 在处理http请求时,connect先获取相应的path,然后遍历相应的路由stack,每次从栈顶开始, 当一个路由和path匹配时,若path符合/path、/path/*、/path.*则使用该路由处理请求,否则都跳过当前路由 继续遍历下一个路由。若路由处理请求成功则终止当前路由遍历,若失败则跳过路由继续路由遍历。 路由的匹配规则:

  1. route.length={0,m}, path.length={0,n}
  2. 当m>n时route != path 跳过该路由,继续遍历
  3. 当m<=n route != path.substring(0, m) 跳过该路由,继续遍历
  4. 当m<=n route = path.substring(0, m)