Skip to content

Instantly share code, notes, and snippets.

View methane's full-sized avatar

Inada Naoki methane

  • KLab Inc,
  • Japan
  • 19:29 (UTC +09:00)
  • X @methane
View GitHub Profile
@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)
@methane
methane / f.py
Last active April 10, 2024 13:50
short-traceback
import sys
import os
import io
import traceback
import json
import pathlib
import sub
try:
Run uwsgi
uwsgi --wsgi-file=mt_sample.py --threads 8 --workers 4 --max-requests 40 --http-socket=:8000 --master --min-worker-lifetime=7 -L
Run hey[1]
hey -c 32 -z 10m 'http://127.0.0.1:8000/'
[1] hey: https://github.com/rakyll/hey
@methane
methane / mariadb_float.md
Last active February 26, 2024 13:25
mariadb float type
mysql> create table t (id integer primary key, f1 float, f2 float(10,4));

mysql> insert into t (id, f1, f2) values (1, 0.0001, 0.0001);

mysql> select f1, f1=0.0001, f1=0.0001e0, f2, f2=0.0001, f2=0.0001e0 from t;
+--------+-----------+-------------+--------+-----------+-------------+
| f1     | f1=0.0001 | f1=0.0001e0 | f2     | f2=0.0001 | f2=0.0001e0 |
+--------+-----------+-------------+--------+-----------+-------------+
| 0.0001 | 0 | 0 | 0.0001 | 1 | 0 |
package main
import (
"fmt"
"github.com/ugorji/go/codec"
)
var mh = codec.MsgpackHandle{}
@methane
methane / bench_indent.py
Last active July 29, 2023 02:05
bench_indent.py
# https://github.com/python/cpython/pull/107374
import sys
import textwrap
import timeit
filename = "Objects/unicodeobject.c"
if len(sys.argv) > 1:
filename = sys.argv[1]
diff -r ffdfb1066ac6 contrib/win32/hg.bat
--- a/contrib/win32/hg.bat Thu Mar 02 15:34:45 2023 +0100
+++ b/contrib/win32/hg.bat Wed Jun 28 18:53:44 2023 +0900
@@ -5,6 +5,7 @@
set HG=%~f0
set PYTHONLEGACYWINDOWSSTDIO=1
+set PYTHONLEGACYWINDOWSFSENCODING=1
rem Use a full path to Python (relative to this script) if it exists,
@methane
methane / flask_memcache.py
Created January 31, 2012 12:00
Sample using python-memcached in threaded Flask application.
"""Flask extension utility."""
from flask.sessions import SessionInterface, SessionMixin
from werkzeug.contrib.cache import MemcachedCache
import memcache # Use https://code.launchpad.net/~songofacandy/python-memcached/mixin-threading
def setup_cache(app):
"""
Setup ``app.cache``.
@methane
methane / myprofiler.py
Created December 5, 2011 08:54
Casual MySQL profiler using "SHOW FULL PROCESSLIST"
#!/usr/bin/env python
# coding: utf-8
"""myprofiler - Casual MySQL Profiler
https://github.com/methane/myprofiler
"""
import os
import sys
@methane
methane / gist:2185380
Created March 24, 2012 17:28
Tornado Example: Delegating an blocking task to a worker thread pool from an asynchronous request handler
from time import sleep
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import Application, asynchronous, RequestHandler
from multiprocessing.pool import ThreadPool
_workers = ThreadPool(10)
def run_background(func, callback, args=(), kwds={}):
def _callback(result):