Skip to content

Instantly share code, notes, and snippets.

View xuanfeng's full-sized avatar

ivan xuanfeng

View GitHub Profile
@xuanfeng
xuanfeng / .profile
Created August 29, 2017 03:50
git alias .git/config
alias g='git'
alias ga='git add'
alias gaa='git add --all'
alias gapa='git add --patch'
alias gb='git branch'
alias gba='git branch -a'
alias gbl='git blame -b -w'
alias gbnm='git branch --no-merged'
alias gbr='git branch --remote'
alias gbs='git bisect'
@xuanfeng
xuanfeng / randomWord.js
Last active December 8, 2019 09:37
产生任意长度随机字母数字组合
/*
** randomWord 产生任意长度随机字母数字组合
** randomFlag-是否任意长度 min-任意长度最小位[固定位数] max-任意长度最大位
** xuanfeng 2014-08-28
*/
function randomWord(randomFlag, min, max){
var str = "",
range = min,
arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
@xuanfeng
xuanfeng / operation.js
Last active November 29, 2019 09:55
浮点数运算
/**
* operation 浮点数运算
* https://github.com/nefe/number-precision
* @desc 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
*/
/**
* 精确加法
*/
@xuanfeng
xuanfeng / util.js
Created August 14, 2017 12:26
util
_.type = function (obj) {
return Object.prototype.toString.call(obj).replace(/\[object\s|\]/g, '')
}
_.isArray = function isArray (list) {
return _.type(list) === 'Array'
}
_.slice = function slice (arrayLike, index) {
@xuanfeng
xuanfeng / passwordLevel.js
Last active November 20, 2016 06:49
密码等级:至少包含字母、大小写数字、字符中的两种
function passwordLevel(password) {
var Modes = 0;
for (i = 0; i < password.length; i++) {
Modes |= CharMode(password.charCodeAt(i));
}
return bitTotal(Modes);
//CharMode函数
function CharMode(iN) {
if (iN >= 48 && iN <= 57)//数字
@xuanfeng
xuanfeng / ASCII Art
Created October 8, 2016 16:30
ASCII Art
// http://chris.com/ascii/index.php?art=video%20games/pokemon
quu..__
$$$b `---.__
"$$b `--. ___.---uuudP
`$$b `.__.------.__ __.---' $$$$" .
"$b -' `-.-' $$$" .'|
". d$" _.' |
`. / ..." .' |
`./ ..::-' _.' |
/ .:::-' .-' .'
@xuanfeng
xuanfeng / moduleWrap.js
Created July 13, 2016 13:17
define module
// js库模版
// 可直接被引用或者AMD、CMD方式加载
;(function(root, factory) {
if (typeof module !== 'undefined' && module.exports) {// CommonJS
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {// AMD / RequireJS
define(factory);
} else {
root.Promise = factory.call(root);
}
@xuanfeng
xuanfeng / dabblet.css
Created May 21, 2016 10:59
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
@xuanfeng
xuanfeng / getSystemInfo.js
Last active January 3, 2016 02:48
getSystemInfo: 获取系统信息函数
// get system info
var getOSInfo = function () {
var ver = navigator.userAgent;
var OS = navigator.platform;
if(OS == "Win32" || OS == "Windows") {
return 'Windows';
} else if(OS == "Mac68K" || OS == "MacPPC" || OS == "Macintosh" || OS == "MacIntel") {
return "Mac";
} else if(OS == "X11") {
return "Unix";
@xuanfeng
xuanfeng / jsModule
Created January 13, 2014 10:07
JS 模块化写法
// 匿名函数-实现模块化
(function(){
// 定义对象
var Draw = {};
// 共有方法
Draw.init = function(){};
// 私有方法
Draw._private = function(){};
// 外部接口