Skip to content

Instantly share code, notes, and snippets.

View leohxj's full-sized avatar
💯
Focusing

Leo Hui leohxj

💯
Focusing
View GitHub Profile
@leohxj
leohxj / reverseStr.js
Created May 29, 2014 07:04
反转字符串, 效率的话iterative ,hack ,m5较高。测试地址为:http://jsperf.com/string-reverse-compare/5
// iterative
function string_reverse_1(str) {
var new_str = "";
for (var i = str.length - 1; i >= 0; i--) {
new_str += str.charAt(i);
}
return new_str;
}
@leohxj
leohxj / formatNumber.js
Created May 29, 2014 06:00
将阿拉伯数字每三位分隔,如15000->15,000
// 直白一点的方法, 循环拼接字符串
function formatNumber(number, split) {
var string = String(number);
var split = split || 3;
var newStr= new Array(string.length+ parseInt(string.length/split));
newStr[newStr.length-1]=string[string.length-1];
var currentIndex=string.length-1;
for(var i = newStr.length-1;i >= 0;i--)
{
if((newStr.length-i)%(split+1)==0)
@leohxj
leohxj / arguments2Array.js
Created May 28, 2014 02:56
arguments对象转换成一个数组最好的办法就是 Array.prototype.slice.call
function y(){
var args = Array.prototype.slice.call(arguments);
}
@leohxj
leohxj / typeof.js
Created May 28, 2014 02:42
typeof运算符和Object.prototype.toString
typeof {foo: 'bar'};
// "object"
typeof ['foo', 'bar'];
// "object"
typeof "foobar";
// "string"
typeof /foo|bar/;
@leohxj
leohxj / nginx-forwards.conf
Created May 19, 2014 07:57
nginx实现反向代理
upstream nodejs__upstream {
server 127.0.0.1:3000;
keepalive 64;
}
server {
listen 80;
server_name 192.168.1.60;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@leohxj
leohxj / .gitconfig
Created May 14, 2014 06:21
gitconfig
[user]
name = leohxj
email = [email protected]
[alias]
st = status
l = log --pretty=oneline -n 20 --graph --abbrev-commit
ll = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --
b = branch
ci = commit
ca = commit -a
@leohxj
leohxj / ie8Event.js
Created May 12, 2014 09:05
IE8 Event
if (event.stopPropagation) {
event.stopPropagation();
} else {
event.cancelBubble = true;
}
evnet.target = evnet.target || event.srcElement;
@leohxj
leohxj / flicker.css
Created May 7, 2014 10:56
防止抖动
{
transform: translate3d(0,0,0);
}
or
{
-webkit-backface-visibility: hidden;
opacity: 0.999999;
}
@leohxj
leohxj / new_gist_file_0
Created May 5, 2014 03:06
NPM相关命名
# 查看版本
npm info xxx version
@leohxj
leohxj / tree.bat
Created May 2, 2014 07:18
windows下显示树形结构命名
tree . >> "tree.txt"