Skip to content

Instantly share code, notes, and snippets.

View methane's full-sized avatar

Inada Naoki methane

View GitHub Profile
@methane
methane / router.txt
Last active August 29, 2015 14:02
トップレベルの router 廃止して slot 方式にする案
<source>
type in_tail
tag apache.t
</source>
<match apache.t>
type parser
format apache
tag apache.p
</match>
from __future__ import print_function, division, absolute_import
import flask
app = flask.Flask(__name__)
@app.route('/')
def index():
return u'Hello'
@app.after_request
@methane
methane / bench.py
Last active April 20, 2024 00:03
Benchmarking MySQL drivers (Python 3.4)
from __future__ import print_function
import time
def query_10k(cur):
t = time.time()
for _ in range(10000):
cur.execute("SELECT 1,2,3,4,5")
res = cur.fetchall()
assert len(res) == 1
assert res[0] == (1,2,3,4,5)
$ python sample.py
...........................................................................................................................................................................................................................................................ERROR:sqlalchemy.pool.QueuePool:Exception closing connection None
Traceback (most recent call last):
File "/Users/inada-n/venvs/flask-gevent-pymysql/lib/python2.7/site-packages/sqlalchemy/pool.py", line 244, in _close_connection
self._dialect.do_close(connection)
File "/Users/inada-n/venvs/flask-gevent-pymysql/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 411, in do_close
dbapi_connection.close()
AttributeError: 'NoneType' object has no attribute 'close'
Traceback (most recent call last):
File "/Users/inada-n/venvs/flask-gevent-pymysql/lib/python2.7/site-packages/gevent/greenlet.py", line 327, in run
import gevent.monkey
gevent.monkey.patch_all()
import flask
from flask.ext.sqlalchemy import SQLAlchemy
app = flask.Flask(__name__)
app.debug = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root@localhost/test'
db = SQLAlchemy(app)
import pymemcache.client
import time
client = pymemcache.client.Client(('localhost', 11211))
for _ in range(1000):
for i in range(10000):
k = "foo%d" % i
x = str(time.time())
if not isinstance(x, bytes):
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
namespace wsecho
{
class MainClass
{
static HttpListener listener;
@methane
methane / redis_test.go
Last active August 29, 2015 13:57
Redis benchmark in Golang
// To run this test.
// $ go get github.com/garyburd/redigo/redis
// $ go test -bench=.
package main
import (
"fmt"
"log"
"math/rand"
In [3]: filter?
Type: type
String Form:<class 'filter'>
Namespace: Python builtin
Docstring:
filter(function or None, iterable) --> filter object
Return an iterator yielding those items of iterable for which function(item)
is true. If function is None, return the items that are true.
In [2]: list.
list.append list.extend list.insert list.pop list.reverse
list.count list.index list.mro list.remove list.sort
In [2]: list.in
list.index list.insert
In [2]: list.index?
Type: method_descriptor
String Form:<method 'index' of 'list' objects>