View lineinfile.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
View xljj.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding:utf8 -*- | |
import optparse | |
import sys | |
from contextlib import closing | |
import yaml | |
import jinja2 | |
from openpyxl import load_workbook |
View marubatu.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
論理クイズ(https://kuizy.net/user/Noir_KUS)のソルバー | |
""" | |
from typing import Callable, Sequence | |
class State: | |
""" | |
マルバツ全10問に対する答えの、ひとつの組み合わせ表現するimmutableなオブジェクト. |
View sync_pipfile_versions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""sync_pipfile_versions.py | |
sync Pipfile dependency versions from Pipfile.lock | |
requires: | |
- Python >= 3.8 | |
- tomlkit | |
""" |
View UnsafeLambdaUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.function.Consumer; | |
import java.util.function.Function; | |
import java.util.function.Supplier; | |
final public class UnsafeLambdaUtil { | |
private UnsafeLambdaUtil(){} | |
public static class ExceptionWrapper extends RuntimeException { | |
private static final long serialVersionUID = 1L; |
View exporter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Collection, List, Dict | |
class Export: | |
""" | |
construct __all__ using decorator | |
Example: | |
>>> import os, sys | |
>>> from exporter import Export |
View string_heap_set.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "container/heap" | |
type StringHeapSet struct { | |
heap stringHeapData | |
} | |
func (h *StringHeapSet) Push(v string) { | |
heap.Push(&h.heap, v) |
View dataframe_to_wikitable.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
View katan-haibun.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import sys | |
C = ['ヒツジ', '麦', 'レンガ', '木', '石'] | |
def katan(n): | |
import collections | |
c = collections.defaultdict(lambda: 0) | |
for i in range(n): |
View yaml_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
NewerOlder