Skip to content

Instantly share code, notes, and snippets.

@tomoemon
tomoemon / thread_pool_executor_limited_queue.py
Last active March 25, 2022 01:55
submit できるキューに制限をかけながら実行する
import concurrent.futures
from threading import Semaphore
# ThreadPoolExecutor の _work_queue を差し替える方法もあるようだが、試したところ意図しない挙動になった(最後のタスクが終了しても制御が戻らない)
# https://stackoverflow.com/questions/48263704/threadpoolexecutor-how-to-limit-the-queue-maxsize
class ThreadPoolExecutorWithLimitedWorkQueue(concurrent.futures.ThreadPoolExecutor):
def __init__(self, max_queue_size, *args, **kwargs):
super().__init__(*args, **kwargs)
self.semaphore = Semaphore(max_queue_size)
@tomoemon
tomoemon / list_package_license.sh
Last active May 17, 2021 11:08
list package license
# js/ts npm package
## Command
```
jq -r ".dependencies | keys | .[]" package.json | xargs -I{} npm view {} name license
```
## Example
```
$ jq -r ".dependencies | keys | .[]" package.json | xargs -I{} npm view {} name license
package main
import "testing"
type I interface {
Hello()
}
type A struct {}
func (a A) Hello() {}
@tomoemon
tomoemon / datastore_comparison.go
Created October 16, 2020 09:01
appengine/datastore と cloud/datastore の timezone に関する挙動を確認する
package main
import (
"context"
"fmt"
"net/http"
"time"
cldatastore "cloud.google.com/go/datastore"
"google.golang.org/appengine"
@tomoemon
tomoemon / func_info.go
Last active November 2, 2018 05:18
任意の関数の情報を取得するための関数
import (
"reflect"
"regexp"
"runtime"
"strings"
"github.com/pkg/errors"
)
/*
@tomoemon
tomoemon / debugging_damerau_levenshtein.py
Last active April 21, 2016 10:58
testing Damerau-Levenshtein
def damerau_levenshtein_distance(s1, s2):
from pprint import pprint
from collections import defaultdict
if isinstance(s1, bytes) or isinstance(s2, bytes):
raise TypeError(_no_bytes_err)
len1 = len(s1)
len2 = len(s2)
infinite = len1 + len2
# -*- coding: utf-8 -*-
import sys
import re
from pypeg2 import *
"""
漢直 Win テーブル定義ファイルパーサ (要 python3)
Option: #define で定義される値
# -*- coding: utf-8 -*-
class Case(object):
__slots__ = []
def __init__(self, *args, **kwargs):
super_setattr = super(Case, self).__setattr__
slots = self.__slots__[:]
def parse_args(input_args, accept_args):
"""
>>> parse_args(["main.py"], {'--hoge': (1, 1)})
Traceback (most recent call last):
Exception: error: argument --hoge: expected 1 argument(s)
>>> parse_args(["main.py", "a", "b", "--hoge", "w", "x", "y", "z"], {"--hoge": (2, 2)})
({'--hoge': ['w', 'x']}, ['main.py', 'a', 'b', 'y', 'z'])
>>> parse_args(["main.py", "a", "b", "--hoge", "w", "x", "y", "z"], {"--hoge": (0, 0)})
({'--hoge': []}, ['main.py', 'a', 'b', 'w', 'x', 'y', 'z'])
>>> parse_args(["main.py"], {'--hoge': (1, 1, ["piyo"])})