Skip to content

Instantly share code, notes, and snippets.

Avatar

Kosuke Okumura kokumura

View GitHub Profile
View sync_pipfile_versions.py
#!/usr/bin/env python
"""sync_pipfile_versions.py
sync Pipfile dependency versions from Pipfile.lock
requires:
- Python >= 3.8
- tomlkit
"""
@kokumura
kokumura / marubatu.py
Last active Jan 29, 2020
論理クイズソルバー
View marubatu.py
"""
論理クイズ(https://kuizy.net/user/Noir_KUS)のソルバー
"""
from typing import Callable, Sequence
class State:
"""
マルバツ全10問に対する答えの、ひとつの組み合わせ表現するimmutableなオブジェクト.
@kokumura
kokumura / exporter.py
Last active Nov 7, 2018
construct `__all__` automatically in Python
View exporter.py
from typing import Collection, List, Dict
class Export:
"""
construct __all__ using decorator
Example:
>>> import os, sys
>>> from exporter import Export
@kokumura
kokumura / lineinfile.sh
Created May 25, 2018
lineinfile in Shell Script
View lineinfile.sh
# Ansible 'lineinfile' like function in Shell Script.
# Works on both Bash and Zsh.
function lineinfile(){
if [[ $# != 3 ]];then
local THIS_FUNC_NAME="${funcstack[1]-}${FUNCNAME[0]-}"
echo "$THIS_FUNC_NAME - 3 arguments are expected. given $#. args=[$@]" >&2
echo "usage: $THIS_FUNC_NAME PATTERN LINE FILE" >&2
return 1
fi
@kokumura
kokumura / string_heap_set.go
Created May 11, 2018
Golang StringHeapSet
View string_heap_set.go
package main
import "container/heap"
type StringHeapSet struct {
heap stringHeapData
}
func (h *StringHeapSet) Push(v string) {
heap.Push(&h.heap, v)
@kokumura
kokumura / dataframe_to_wikitable.py
Created Aug 22, 2017
PandasのDataFrameをJIRAのテーブル(Wikiマークアップ)文字列に変換
View dataframe_to_wikitable.py
import pandas as pd
def dataframe_to_wikitable(df):
lines = []
columns = df.columns.values
lines.append('|| ' + ' || '.join(columns) + ' ||')
for ix, row in df.iterrows():
line = '| ' + ' | '.join(str(row[col]) for col in columns) + ' |'
lines.append(line)
return '\n'.join(lines)
@kokumura
kokumura / katan-haibun.py
Last active May 7, 2017
katan-haibun.py
View katan-haibun.py
import random
import sys
C = ['ヒツジ', '麦', 'レンガ', '木', '石']
def katan(n):
import collections
c = collections.defaultdict(lambda: 0)
for i in range(n):
@kokumura
kokumura / yaml_config.py
Last active Apr 27, 2017
include とマージを伴う YAMLベースの configパーサー (試作)
View yaml_config.py
# -*- coding: utf-8 -*-
import yaml
import os
def _yaml_constructor_include(loader, node):
spl = node.value.split(' ')
if len(spl) == 1:
file = spl[0]
keys = None
@kokumura
kokumura / adder-with-sed.py
Last active Apr 27, 2017
calcurate expression including fixed-length integer, add, substruct with sed
View adder-with-sed.py
# coding:utf-8
"""
usage: python adder-with-sed.py <max_num_digits> <max_num_terms>
$ echo '55+77-250+442' | sed -E -f <(python adder-with-sed.py 5 5)
=> 324
"""
from collections import defaultdict
def sed_adjust_digits(digits):
"""
View RecommendationApiParamSearch.py
import requests
import time
import json
class AzureReco:
BASE_URL = 'https://westus.api.cognitive.microsoft.com/recommendations/v4.0'
def __init__(self, subscription_key):
self._subscription_key = subscription_key