Skip to content

Instantly share code, notes, and snippets.

View rsj217's full-sized avatar

rsj217 rsj217

  • Smart Finance
  • Beijing
View GitHub Profile
var cluster = require('cluster');
if (cluster.isMaster) {
/* var cpu_count = require('os').cpus().length;
require('os').cpus().forEach(function() {
cluster.fork();
});*/
var cpu_count = 2;
for (var i = 0; i < cpu_count; i++){
cluster.fork();
@rsj217
rsj217 / db.py
Created May 6, 2014 15:36
a python class to use mysql. mysql 的连接关闭查询的python封装
# -*- coding: utf-8 -*-
__author__ = 'ghost'
import time, uuid, functools, threading, logging
def next_id(t=None):
"""
"""
if t is None:
def extract_params(request):
if not isinstance(request, HTTPServerRequest):
request = request.request
parse_url = urlparse.urlparse(request.uri)
path, params, query, fragment = parse_url.path, parse_url.params, parse_url.query, parse_url.fragment
uri = urlparse.urlunparse((request.protocol, request.host, path, params, query, fragment))
async def main():
coroutine1 = do_some_work(1)
coroutine2 = do_some_work(2)
coroutine3 = do_some_work(4)
tasks = [
asyncio.ensure_future(coroutine1),
asyncio.ensure_future(coroutine2),
asyncio.ensure_future(coroutine3)
]
package main
import (
"database/sql"
"strconv"
"log"
"net/http"
"fmt"
"bytes"
"gopkg.in/gin-gonic/gin.v1"
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import socket
import sys
import threading
from itertools import chain
from queue import LifoQueue, Full, Empty
import os
@rsj217
rsj217 / go-poiter-new-make-nil.go
Created July 22, 2017 09:53
go-poiter-new-make-nil
package main
import "fmt"
func main() {
// 声明一个变量 aVar 类型为 string
var aVar string
fmt.Printf("aVar: %p %#v\n", &aVar, aVar) // 输出 aVar: 0xc42000e240 ""
aVar = "This is a aVar"
#!/usr/bin/env
# coding: utf-8
import asyncio
import requests
import tornado.gen as gen
import tornado.httpclient as httpclient
import tornado.httpserver as httpserver
import tornado.options as options
@rsj217
rsj217 / connect_event.py
Last active January 16, 2019 08:58
python socket
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Tornado source code write comments in `iostream._handle_events` which links is https://github.com/tornadoweb/tornado/blob/master/tornado/iostream.py#L695:
```
# Most IOLoops will report a write failed connect
# with the WRITE event, but SelectIOLoop reports a
# READ as well so we must check for connecting before
# coding=utf8
import base64
import io
import hashlib
from M2Crypto import RSA