Skip to content

Instantly share code, notes, and snippets.

Avatar

ivan xuanfeng

View GitHub Profile
@xuanfeng
xuanfeng / operation.js
Last active Nov 29, 2019
浮点数运算
View operation.js
/**
* operation 浮点数运算
* https://github.com/nefe/number-precision
* @desc 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
*/
/**
* 精确加法
*/
@xuanfeng
xuanfeng / .profile
Created Aug 29, 2017
git alias .git/config
View .profile
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'
View util.js
_.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) {
View ASCII Art
// http://chris.com/ascii/index.php?art=video%20games/pokemon
quu..__
$$$b `---.__
"$$b `--. ___.---uuudP
`$$b `.__.------.__ __.---' $$$$" .
"$b -' `-.-' $$$" .'|
". d$" _.' |
`. / ..." .' |
`./ ..::-' _.' |
/ .:::-' .-' .'
View moduleWrap.js
// 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
The first commented line is your dabblet’s title
View dabblet.css
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
@xuanfeng
xuanfeng / iLocalStorage.js
Last active Aug 29, 2015
LocalStorage 本地存储兼容函数
View iLocalStorage.js
/*
* 名称:本地存储函数
* 功能:兼容各大浏览器存储
* 作者:轩枫
* 日期:2015/06/11
* 版本:V2.0
*/
/**
* LocalStorage 本地存储兼容函数
@xuanfeng
xuanfeng / hideWxMenu.js
Created May 26, 2015
隐藏微信右上角按钮
View hideWxMenu.js
//隐藏微信菜单
function initWeixinBridge(){
WeixinJSBridge.call('hideOptionMenu');
}
if (typeof WeixinJSBridge == "object" &&
typeof WeixinJSBridge.invoke == "function") {
initWeixinBridge();
} else {
if (document.addEventListener) {
document.addEventListener("WeixinJSBridgeReady", initWeixinBridge, false);
@xuanfeng
xuanfeng / css3Style.js
Created May 4, 2015
设置移动端transition、translate样式
View css3Style.js
// 设置动画、坐标移动样式(硬件加速、浏览器兼容、原生方式)
var CSS_PREFIX_MAP = ["webkit", "moz", "ms", "o", ""],
NUMBER_REG = /\-?[0-9]+\.?[0-9]*/g;
var setTransition = function(ele, css) {
var name, prefix, _i, _len, _results;
_results = [];
for (_i = 0, _len = CSS_PREFIX_MAP.length; _i < _len; _i++) {
prefix = CSS_PREFIX_MAP[_i];
name = prefix ? "" + prefix + "Transition" : "transition";
@xuanfeng
xuanfeng / bigger.js
Last active Aug 29, 2015
JS逼格(实用)代码-移动端
View bigger.js
// 1. 设置变量为undefined
var UNDEFINED = void 0;
// 2. 判断支不支持touch事件
var IsTouch = 'ontouchend' in window;
// 3. 各端事件兼容
START_EVENT = IsTouch ? 'touchstart' : 'mousedown';
You can’t perform that action at this time.