Skip to content

Instantly share code, notes, and snippets.

View perrie625's full-sized avatar

Perrie perrie625

  • Zhejiang, Hangzhou
View GitHub Profile
@perrie625
perrie625 / immutabledict.py
Last active January 2, 2018 05:50
python不可变字典
class ImmutableDict(dict):
_HASH = None
def __new__(cls, *args, **kwargs):
ImmutableDict._HASH = hash(frozenset(args[0].items()))
return super(ImmutableDict, cls).__new__(cls, args)
def __hash__(self):
return self._HASH

Performance of Flask, Tornado, GEvent, and their combinations

Wensheng Wang, 10/1/11

Source: http://blog.wensheng.org/2011/10/performance-of-flask-tornado-gevent-and.html

When choosing a web framework, I pretty much have eyes set on Tornado. But I heard good things about Flask and Gevent. So I tested the performance of each and combinations of the three. I chose something just a little more advanced than a "Hello World" program to write - one that use templates. Here are the codes:

1, Pure Flask (pure_flask.py)

@perrie625
perrie625 / pre-receive.py
Created July 15, 2017 04:27
python pre-receive for check same blob object
#!/usr/bin/python
import sys
import subprocess
data = sys.stdin.read()
_, new_obj, _ = data.split()
def command_output(command):
output = subprocess.check_output(
@perrie625
perrie625 / RedisPythonPubSub1.py
Created July 10, 2017 13:11 — forked from jobliz/RedisPythonPubSub1.py
A short script exploring Redis pubsub functions in Python
import redis
import threading
class Listener(threading.Thread):
def __init__(self, r, channels):
threading.Thread.__init__(self)
self.redis = r
self.pubsub = self.redis.pubsub()
self.pubsub.subscribe(channels)
@perrie625
perrie625 / gist:30ee377d207c798ab4e9417dbfaf40c4
Created July 3, 2017 08:20 — forked from tmc/gist:787105
gevent nonblocking stdin
import os
import sys
import fcntl
import gevent
from gevent.socket import wait_read
def print_every(s, repeat=1):
print s
if repeat:
@perrie625
perrie625 / bench_test.go
Created May 25, 2017 10:45 — forked from SchumacherFM/bench_test.go
GoLang Benchmark: Map, StringSlice, Array, StructSlice
package main
// run with: $ go test --bench=. -test.benchmem .
// @see https://twitter.com/karlseguin/status/524452778093977600
import (
"math/rand"
"strconv"
"testing"
)
@perrie625
perrie625 / hashset.go
Created April 19, 2017 09:55
Golang Gist
var itemExists = struct{}{}
type Set struct {
items map[interface{}]struct{}
}
func New() *Set {
return &Set{items: make(map[interface{}]struct{})}
}
@perrie625
perrie625 / chat.go
Created April 15, 2017 03:12
simple golang chat server
package main
import (
"bufio"
"net"
)
type Client struct {
incoming chan string
outgoing chan string
@perrie625
perrie625 / nesign.py
Created October 25, 2015 03:47 — forked from rumisle/nesign.py
网易云音乐签到(pc android)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import logging
import requests
'''
A module for helping you to finish the daily task on Neteasy Music
'''