Skip to content

Instantly share code, notes, and snippets.

@anhulife
anhulife / countDown.js
Last active December 18, 2015 22:49
倒计时
var countDown = (function($){
var counts = {}, countTime, stopped = true, id = 0;
function count(){
var length = 0;
$.each(counts, function(key, countObj){
var timeObj, seconds = countObj.seconds - ((new Date().getTime() - countObj.startTime) /1000);
if(seconds > 0){
timeObj = {
@anhulife
anhulife / WeixinDetection.js
Created January 17, 2014 09:22
判断网页是否是在微信内嵌浏览器中打开
document.addEventListener('WeixinJSBridgeReady', function(){
//如果执行到这块的代码,就说明是在微信内部浏览器内打开的.
alert('当前页面在微信内嵌浏览器中打开!');
});
//format('hello {0}!', 'world') => 'hello world!'
//format('hello {0}!{1}', 'world', 'OK') => 'hello world!OK'
//format('hello {0}!', ['world']) => 'hello world!'
//format('hello {0}!{1}', ['world', 'OK']) => 'hello world!'
function format(str){
var dataList = (/array/i).test(Object.prototype.toString.apply(arguments[1])) ? arguments[1] : Array.prototype.slice.apply(arguments, [1]);
return str.replace(/\{(\d+)\}/g, function(target, index){
index = parseInt(index, 10);
return dataList[index] || '';
function TreeNode(val){
this.val = val;
this.left = null;
this.right = null;
}
function addNodeToTree(root, val){
if (val < root.val){
if (!root.left){
root.left = new TreeNode(val);
/**
* 动画函数
* @param {Object} opts 动画参数
* @param {Number} opts.duration 持续时间
* @param {Function} [opts.delta] 动画进度计算函数默认为线性
* @param {Function} opts.complete 动画完成之后执行的函数
* @param {Function} opts.render 动画渲染函数
*/
function animate(opts) {
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
@anhulife
anhulife / loadToDataURL.js
Created July 15, 2016 06:55
loadToDataURL
function loadToDataURL(url, callback) {
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function () {
callback(reader.result);
reader = null;
}
reader.readAsDataURL(xhr.response);
@anhulife
anhulife / WXHttpAdapter.java
Created December 11, 2018 06:23
Weex 的网络适配器,使用 OkHttp,并启用了缓存
import android.content.Context;
import android.text.TextUtils;
import com.taobao.weex.adapter.IWXHttpAdapter;
import com.taobao.weex.common.WXRequest;
import com.taobao.weex.common.WXResponse;
import java.io.File;
import java.io.IOException;
import java.util.Set;