Skip to content

Instantly share code, notes, and snippets.

@hiropppe
hiropppe / split_tel_number.py
Created March 6, 2025 02:52
コードメモ:ハイフンなし電話番号の分割
TEL_DIGITS = {
"050": 4, # IP電話
"070": 4, # 携帯電話/PHS
"080": 4, # 携帯電話
"090": 4, # 携帯電話
# その他
"020": 3,
"0120": 3,
"0800": 3,
"0570": 3,
@hiropppe
hiropppe / nohup_with_time.sh
Created January 9, 2025 00:22
シェルメモ:nohup で実行するコマンドを time したいとき
bash -c "time (sleep 3 && echo \"zzz..\" && sleep 2 && echo \"woke up\")" 2>&1
$ sh ./test.sh
$ nohup sh ./test.sh &
$ nohup sh ./test.sh > test.log &
@hiropppe
hiropppe / check_variance_to_identify_garbage_text.ipynb
Created December 25, 2020 17:50
文字や単語の分散が悪戯テキストの検出に使えそうなサンプル
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hiropppe
hiropppe / wv_cosine_similarity_matrix_for_small_data.ipynb
Last active December 25, 2020 17:56
Gensim で作成した小さめの wv からコサイン類似度行列の作り方
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python
# -*- coding:utf8 -*-
from __future__ import unicode_literals
import codecs
import gzip
import re
import sys
import unicodedata
@hiropppe
hiropppe / pandas_apply_udf_sample.py
Last active February 7, 2018 21:53
Pandasで各行に任意の関数を適用するサンプル。遅いらしい:-)
In [1]: import pandas as pd
In [2]: data = {'a': [0,1,2], 'b': [3,4,5]}
...: df = pd.DataFrame(data)
...: df
...:
Out[2]:
a b
0 0 3
1 1 4
@hiropppe
hiropppe / pandas_SQL_analytic_and_aggregate_functions_like_operation_sample.py
Last active March 19, 2021 13:07
Pandas で count( * ) over ( partition by ... 的な結果がしたかった
In [1]: import pandas as pd
...:
...: data = {'m': ['m1','m2','m2','m3','m3','m3','m4','m4','m4','m4'],
...: 'e': ['e1','e2','e3','e4','e5','e6','e7','e1','e2','e8'],
...: 'p': [0.9, 0.2, 0.8, 0.7, 0.1, 0.2, 0.3, 0.1, 0.2, 0.4]}
...: df = pd.DataFrame(data)
...: df
...:
Out[1]:
e m p
@hiropppe
hiropppe / print_twogtp_winratio.py
Last active January 26, 2018 13:22
Simple python script which prints player winning ratio from gogui-twogtp result sgf files.
from __future__ import division
import re
import sys
from collections import defaultdict
is_alternate_game = False
if len(sys.argv) > 1:
is_alternate_game = sys.argv[1] in ('--alternate', '-a')