Skip to content

Instantly share code, notes, and snippets.

View axetroy's full-sized avatar
💭
Get busy living or get busy dying

Axetroy axetroy

💭
Get busy living or get busy dying
View GitHub Profile
@axetroy
axetroy / cycle.js
Last active December 6, 2017 02:48
环形数据结构
class Node {
constructor(prev, value, next) {
this.prev = prev;
this.next = next;
this.value = value;
}
}
const CURRENT_INDEX = Symbol('current index in cycle');
const ROUND_INDEX = Symbol('how many round in cycle');
@axetroy
axetroy / pool.go
Created November 27, 2017 15:12
Golang资源池
package pool
type CreatorFunc func() (interface{}, error)
type DestroyerFunc func(resource interface{}) (interface{}, error)
type Pool struct {
config Config
options Options
pool []interface{}
}
@axetroy
axetroy / emitter.go
Last active November 27, 2017 14:47
EventEmitter for golang
package pool
import "time"
type Event struct {
Time time.Time
Name string
Data interface{}
Id string
}
@axetroy
axetroy / hs.js
Created November 27, 2017 10:05
Http status code and message module
/**
* Generate a New status
* @param code
* @param message
* @constructor
*/
function Status(code, message) {
this.code = code;
this.message = message;
}
@axetroy
axetroy / README.md
Last active January 22, 2022 12:14
NodeJs项目目录结构

NodeJs 项目目录

.
├── logs                                                        # 存放日志
│   ├── 1.log
│   └── 2.log
├── package.json                                                # 依赖包
├── scripts                                                     # 脚本集合
│   └── do_some_thing.js
@axetroy
axetroy / README.md
Last active March 13, 2019 03:27
Thrift的Nodejs例子

Thrift的RPC

代码全部来源于官方教程

如何运行?

新建目录,把所有文件放在同一目录下

在该目录下执行命令

@axetroy
axetroy / kor.js
Last active November 4, 2017 10:15
整合koa + koa-router
const Koa = require('koa');
const Router = require('koa-router');
const methods = require('methods');
const router = new Router();
const KOA = Symbol('koa instance');
class Server {
constructor() {
this[KOA] = new Koa();
@axetroy
axetroy / hashCode.js
Last active November 18, 2017 10:00
获取一个对象/字符串/数组的hashCode
function hashCode(any) {
let hash = 0;
if (
any === null ||
any === void 0 ||
any === '' ||
any === 0 ||
any === false
) {
return 0;
@axetroy
axetroy / README.md
Last active April 21, 2019 15:38
跨平台,关闭xxx端口

有些时候程序开启了http服务,监听了某个端口。

然后关闭终端或者CTRL+C退出之后,进程没有被杀掉,端口还在监听,导致下次启动的时候报错。

这里就记录下来,查看进程监听的端口,以及杀死进程

Window

@axetroy
axetroy / .gitattributes
Last active September 26, 2017 03:10
开源项目常用的配置文件
# Auto detect text files and perform LF normalization
* text=auto
# JS and TS files must always use LF for tools to work
*.js eol=lf
bin/* eol=lf