View test_generator_async.js
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
'use strict' | |
const thunk = require('thunks')() | |
const co = require('co') | |
function * test (i) { | |
return yield Promise.resolve(i) | |
} | |
// async function test (i) { |
View selectors.go
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
package main | |
import "fmt" | |
type T0 struct { | |
x int | |
} | |
func (i *T0) M0() int { | |
return i.x * 110 |
View pipeling_request.js
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
'use strict' | |
const net = require('net') | |
const thunk = require('thunks')() | |
const buf = new Buffer('GET / HTTP/1.1\r\nHost: localhost:3333\r\nConnection: keep-alive\r\n\r\n') | |
thunk(function * () { | |
var server | |
console.log('\n=== Http server ===') | |
server = getHttpServer() |
View thunk-redis-bench.js
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
'use strict'; | |
const Thunk = require('thunks')(); | |
const redis = require('../index'); | |
Thunk(function*() { | |
var timeT = 0; | |
var testLen = 50000; | |
var titleT = 'redis(T):'; | |
var clientT = redis.createClient(6379); |
View test-co.js
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
'use strict'; | |
/*global console*/ | |
var len = 1000, times = 1000; | |
var tasks = []; | |
function task(callback) { | |
callback(); | |
} |
View catch-err.js
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
'use strict'; | |
/*global console*/ | |
var co = require('co'); | |
function task(callback) { | |
callback(null, 1); | |
}; | |
setImmediate(function () { |
View demo.js
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
'use strict'; | |
/*global console*/ | |
// co version 3.0.6 | |
var co = require('co'); | |
function task(callback) { | |
callback(null, 1); | |
}; |
View FizzBuzzWhizz.js
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 game(a, b, c) { | |
for (var i = 1, s = ''; i <= 100; i++) { | |
s = (i + '').indexOf(a) >= 0 ? 'Fizz' : | |
(i % a ? '' : 'Fizz') + (i % b ? '' : 'Buzz') + (i % c ? '' : 'Whizz'); | |
console.log(s || i); | |
}; | |
} |
View ngPagination.js
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
'use strict'; | |
angular.module('app.directives', []). | |
directive('ngPagination', function () { | |
// <div ng-pagination="pagination" class="pagination"></div> | |
// 基于Bootstrap框架,从父作用域继承下面四个属性 | |
// scope.sizePerPage = [25, 50, 100]; | |
// scope.pageSize = 25; | |
// scope.pageIndex = 1; | |
// scope.total = 10; |
View CacheLRU.js
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 CacheLRU(capacity) { | |
/* 利用Buffer写的一个LRU缓存,capacity为缓存容量,为0时不限容量。 | |
myCache = new CacheLRU(capacity); //构造缓存 | |
myCache.get(key); //读取名为key的缓存值 | |
myCache.put(key, value); //写入名为key的缓存值 | |
myCache.remove(key); //删除名为key的缓存值 | |
myCache.removeAll(); //清空缓存 | |
myCache.info(); //返回myCache缓存信息 | |
LRU原理:对所有缓存数据的key构建hash链表,当对某一数据进行get或put操作时,将其key提到链表前端(最新)。当进行put数据超出容量时,删除链表尾端(最旧)的缓存数据。 | |
hash链表操作可直接定位key,无需历遍整个hash对象,故读写极快。缓存容量不再影响读写速度。 |
NewerOlder