This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function asyncRandom() { | |
return function (fn) { | |
setTimeout(function () { | |
fn(Math.random()); | |
}, 10); | |
}; | |
} | |
function *gen1() { | |
var a = yield asyncRandom(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Drupal", | |
"members": [ | |
{ | |
"name": "Wang Qiu", | |
"role": "Team Lead", | |
"motto": "", | |
"avatar": "https://2.gravatar.com/avatar/7ed23c4532204410539c551c405ce213?d=https%3A%2F%2Fidenticons.github.com%2Fe66953f95ec27b59aab57b32b630cfda.png&r=x&s=460" | |
} | |
/*, others */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" don't bother with vi compatibility | |
set nocompatible | |
" vundle start | |
filetype off " required | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
Plugin 'gmarik/Vundle.vim' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($, ShowDown, CodeMirror) { | |
"use strict"; | |
$(function() { | |
if (!document.getElementById('entry-markdown')) | |
return; | |
//var delay; | |
var converter = new ShowDown.converter(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function run(element, cssProperty, value, duration) { | |
var initalValue = parseFloat(window.getComputedStyle(element)[cssProperty]); | |
var start = new Date().getTime(); | |
window.requestAnimationFrame(function step() { | |
var progress = new Date().getTime() - start; | |
var newValue = bounce(progress, initalValue, parseFloat(value) - initalValue, duration); | |
element.style[cssProperty] = newValue + 'px'; | |
if (progress < duration) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let obj = { | |
data: [ 'hello', 'world' ], | |
[Symbol.iterator]() { | |
const self = this; | |
let index = 0; | |
return { | |
next() { | |
if (index < self.data.length) { | |
return { | |
value: self.data[index++] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 算法本身 | |
for(var i = 0 ; i < arr.length - 1 ; i++){ | |
for(var ii = i + 1; ii < arr.length ; ii++){ | |
if(arr[i] > arr[ii]) | |
normalSwap(arr, i, ii); | |
} | |
} | |
// 利用了Mr.Async.Interpreter的方式 | |
eval(Mr.Async.recode(function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 一个实现了Mr.Deferred的通用异步方法 | |
// 等待一秒钟,计算一个0到1的随机数 | |
function asyncRandom(callback){ | |
var de = Mr.Deferred(); | |
setTimeout(function(){ | |
var random = Math.random(); | |
if(typeof callback == 'function') | |
callback(random); | |
de.resolve(random); | |
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eval(Mr.Async.recode(function(){ | |
var i = $await(delay()); // 等待 | |
console.log(i); | |
})); |
OlderNewer