Skip to content

Instantly share code, notes, and snippets.

@shenmao1989
shenmao1989 / gist:2592480
Created May 4, 2012 06:11
测试js并发执行
var sleep = function(t){
//console.log(+new Date());
var t1 = +new Date();
while(+new Date() - t1 < t){
}
//console.log(+new Date());
}
var f = function(x){
sleep(Math.random() * 1000);
.s-btn {
display: inline-block;
zoom: 1;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
-moz-box-shadow: 0 1px 1px #e4e4e4;
-webkit-box-shadow: 0 1px 1px #E4E4E4;
box-shadow: 0 1px 1px #E4E4E4;
border: 1px solid #C1C8D1;
@shenmao1989
shenmao1989 / gist:3346179
Created August 14, 2012 04:06
如何将汉字转换成Unicode格式
var classObj=
{
ToUnicode:function(str)
{
return escape(str).replace(/%/g,"\\").toLowerCase();
},
UnUnicode:function(str)
{
return unescape(str.replace(/\\/g, "%"));
@shenmao1989
shenmao1989 / gist:3367244
Created August 16, 2012 06:17
github fork new
假设你fork的项目原始地址是http://github.com/abc/rep.git, 你自己的是http://github.com/you/rep.git
$ git remote add upstream http://github.com/abc/rep.git # 你本地的origin应该跟了自己的remote,前且假设当前本地branch是master。
$ git fetch upstream
$ git merge upstream/master # merge可能会有冲突,手工解决掉并commit
$ git push origin/master # push到你自己的fork上
然后向原始项目提交一个pull request。
@shenmao1989
shenmao1989 / gist:3414932
Created August 21, 2012 12:04
ubuntu 升级svn至1.7版本
echo "deb http://opensource.wandisco.com/ubuntu lucid svn17" | sudo tee /etc/apt/sources.list.d/svn.list
sudo wget -q http://opensource.wandisco.com/wandisco-debian.gpg -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get dist-upgrade
@shenmao1989
shenmao1989 / gist:3606642
Created September 3, 2012 03:57
nodejs ubuntu 升级
Example install:
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm
It installs current stable Node on the current stable ubuntu.
If you want to compile Node C++ modules:
@shenmao1989
shenmao1989 / gist:3662682
Created September 7, 2012 02:50
用UglifyJS解析/压缩/格式化你的Javascript
UglifyJS是基于 NodeJS 的Javascript语法解析/压缩/格式化工具,它支持任何CommonJS模块系统的Javascript平台(实现自己的CommonJS平台也非难事)。
UglifyJS通过解析重新生成JS代码的语法树,你可以通过AST以了解更多代码情况,或者自己来做一个不同的实现。UglifyJS解析器是在 parse-js.js 中实现的,它是非常优秀的 parse-js Common Lisp Library 的一部分。
(如果你正在查找UglifyJS的Common Lisp版本,点击 这里 )
UglifyJS的另一个重要部分是在 process.js 实现的,它用于检查并实现解析生成的AST:
通过AST进行Javascript代码的重新生成 :如果你想格式化已经被压缩过的代码,可以选择缩进参数。你也可以打印出无空白(whitespace)的AST,以达到压缩的目的。
缩短变量名 :UglifyJS通过分析代码并生成新的变量名称,依赖于作用域,这些名称通常被简化为单一字符,并能足够智能的处理全局变量,或者eval()调用及with{}块。换句话说,如果在某个作用域内使用了eval()或with{},那么该作用域的所有变量及其父作用域的变量都不会被重新命名,并且所有指向这类变量的引用也不会被改变。
@shenmao1989
shenmao1989 / gist:3909817
Created October 18, 2012 04:10
用 CSS 实现 Firefox 和 IE 都支持的 Alpha 透明效果
filter:alpha(opacity=50); /* IE */
-moz-opacity:0.5; /* Moz + FF */
opacity: 0.5; /* 支持CSS3的浏览器(FF 1.5也支持)*/
@shenmao1989
shenmao1989 / gist:4049697
Created November 10, 2012 03:15
图片垂直居中的使用技巧
.box {
/*非IE的主流浏览器识别的垂直居中的方法*/
display: table-cell;
vertical-align:middle;
/*设置水平居中*/
text-align:center;
/* 针对IE的Hack */
*display: block;
@shenmao1989
shenmao1989 / gist:4133708
Created November 23, 2012 02:10
js 对象序列化
/**
* js 对象序列化
* @param obj
* @return {String}
*/
function serialize(obj){
switch(obj.constructor){
case Object:
var str = "{";
for(var o in obj){