Skip to content

Instantly share code, notes, and snippets.

View winsonwq's full-sized avatar
🎯
Focusing

Wang Qiu winsonwq

🎯
Focusing
  • 可好玩乐
  • Chengdu China
View GitHub Profile
@winsonwq
winsonwq / minico.js
Created March 3, 2014 06:15
mini_co implementation
function asyncRandom() {
return function (fn) {
setTimeout(function () {
fn(Math.random());
}, 10);
};
}
function *gen1() {
var a = yield asyncRandom();
@winsonwq
winsonwq / members.json
Created March 13, 2014 04:32
members
{
"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 */
@winsonwq
winsonwq / .vimrc
Last active August 29, 2015 14:04
this is my vimrc
" 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'
@winsonwq
winsonwq / ghost_markdown_image_upload.js
Created December 3, 2014 03:02
Ghost Markdown 改吧改吧
(function($, ShowDown, CodeMirror) {
"use strict";
$(function() {
if (!document.getElementById('entry-markdown'))
return;
//var delay;
var converter = new ShowDown.converter(),
@winsonwq
winsonwq / .ctags
Created December 10, 2014 02:56
ctags for javascript
--regex-JavaScript=/(^|^[^\/*]+[[:blank:]])([A-Za-z0-9._$]+)[[:blank:]]*[:=][[:blank:]]*new[[:blank:]]+Object\(/\2/o,object/
--regex-JavaScript=/(^|^[^\/*]+[[:blank:]])([A-Za-z0-9._$]+)[[:blank:]]*[:=][[:blank:]]*\{/\2/o,object/
--regex-JavaScript=/(^|^[^\/*]+[[:blank:]])(^[^\?][[:blank:]]*)([A-Za-z0-9_]+)[[:blank:]]*[:][[:blank:]]*[A-Za-z0-9._$'"()]+/\3/m,member/
--regex-JavaScript=/(^|^[^\/*]+[[:blank:]])([A-Za-z0-9._$]+)[[:blank:]]*[:=][[:blank:]]*new[[:blank:]]+Array\(/\2/a,array/
--regex-JavaScript=/(^|^[^\/*]+[[:blank:]])([A-Za-z0-9._$]+)[[:blank:]]*[:=][[:blank:]]*\[/\2/a,array/
--regex-JavaScript=/(^|^[^\/*]+[[:blank:]])([^! ]+[^= ]+)[[:blank:]]*=[[:blank:]]*[^""]'[^'']*/\2/s,string/
--regex-JavaScript=/(^|^[^\/*]+[[:blank:]])([A-Za-z0-9._$()]+)[[:blank:]]*[:=][[:blank:]]*function[[:blank:]]*\(/\2/f,function/
--regex-JavaScript=/(^|^[^\/*]+[[:blank:]])this\.([A-Za-z0-9._$()]+)[[:blank:]]*[:=][[:blank:]]*function[[:blank:]]*\(/\2/f,function/
--regex-JavaScript=/(^|^[^\/*]+[[:blank:]])function[[:blank:]
@winsonwq
winsonwq / run.js
Created December 29, 2014 05:50
demo: tranditional implementation of animation
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) {
@winsonwq
winsonwq / symbol-iterator.js
Created January 4, 2015 02:17
Iterability [3] in ECMAScript 6 is one such customization. An object is iterable if it has a method whose key is the symbol (stored in) Symbol.iterator. In the following code, obj is iterable.
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++]
@winsonwq
winsonwq / bubbleSortOfMrAsyncInterpreter.js
Created January 3, 2012 08:21
BubbleSort of Mr.Async.Interpreter
// 算法本身
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(){
@winsonwq
winsonwq / MrDeferredInAwait.js
Created January 3, 2012 08:24
How to use $await in Mr.Async
// 一个实现了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);
@winsonwq
winsonwq / simpleAwait.js
Created January 3, 2012 08:26
How to use Mr.Async.recode method
eval(Mr.Async.recode(function(){
var i = $await(delay()); // 等待
console.log(i);
}));