Skip to content

Instantly share code, notes, and snippets.

View methane's full-sized avatar

Inada Naoki methane

  • KLab Inc,
  • Japan
  • 06:32 (UTC +09:00)
  • X @methane
View GitHub Profile
@methane
methane / mariadb_float.md
Last active February 26, 2024 13:25
mariadb float type
View mariadb_float.md
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 |
@methane
methane / bench_indent.py
Last active July 29, 2023 02:05
bench_indent.py
View 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]
View hg-legacywindowsfsencoding.patch
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 / bench_dict.py
Last active May 16, 2022 11:09
dict benchmark
View bench_dict.py
#!/usr/bin/env python3
import pyperf
def build_dict_str(n):
mydict = {str(k): k for k in range(n)}
return mydict, list(mydict)
def build_dict_int(n):
@methane
methane / siphash.cpp
Created October 8, 2021 05:45
create known hashes for siphash13
View siphash.cpp
// create known hash in test_hash
#include <cstdint>
#include <iostream>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
// copied from initconfig.c
View set_doubled.patch
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 2ccf183..db9b86b 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -302,7 +302,7 @@ set_table_resize(PySetObject *so, Py_ssize_t minused)
setentry small_copy[PySet_MINSIZE];
assert(minused >= 0);
- minused = (minused > 50000) ? minused * 2 : minused * 4;
+ minused *= 2;
View render.go
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"time"
)
View repository_pattern.py
from typing import Generic, TypeVar, Optional
class BaseModel:
pass
M = TypeVar('M', bound=BaseModel)
View bench-citylots.py
import io
from msgpack import fallback, packb
try:
from msgpack import _unpacker, _packer
has_ext = True
except ImportError:
has_ext = False
import timeit
View logbook-gzip-sample.py
"""
Compress FileHandler output with subprocess gzip.
"""
import subprocess
import logbook
from logbook.helpers import is_unicode
class GZFileHandler(logbook.FileHandler):