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: utf-8 -*- | |
import sys | |
from logging import getLogger, Formatter, StreamHandler, DEBUG, NOTSET | |
def get_logger(name, level=DEBUG, formatter=None, handler=None): | |
_formatter = formatter or Formatter('%(levelname)s:%(name)s:%(asctime)s:%(message)s') |
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: utf-8 -*- | |
from itertools import chain | |
class Namespace(dict): | |
"""Create a namespace. | |
Compared with types.SimpleNamespace, this class supports |
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
d = { | |
'key': 'value' | |
} | |
# https://tokibito.hatenablog.com/entry/20130406/1365232594 | |
class Mapper(object): | |
# https://docs.python.jp/3/reference/datamodel.html#object.__init_subclass__ | |
def __init_subclass__(cls, fields, **kwargs): | |
super().__init_subclass__(**kwargs) |
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
# Following doc is deprecated. | |
# https://github.com/neovim/neovim/blob/master/runtime/doc/msgpack_rpc.txt#L56 | |
nvim --api-info | python -c 'import msgpack, sys, json, neovim.api.common; \ | |
print(json.dumps(neovim.api.common.walk(neovim.api.common.decode_if_bytes, \ | |
msgpack.unpackb(sys.stdin.buffer.read())), indent=4))' |
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: utf-8 -*- | |
from PyQt5.QtCore import * | |
from PyQt5.QtWidgets import * | |
class Form(QWidget): | |
def __init__(self, parent=None): | |
super(Form, self).__init__(parent) |
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
# FYI: Homebrew example | |
# CONFIG_ARGS = "'--prefix=/usr/local/opt/python' '--enable-ipv6' '--datarootdir=/usr/local/opt/python/share' '--datadir=/usr/local/opt/python/share' '--enable-framework=/usr/local/opt/python/Frameworks' '--without-ensurepip' '--with-dtrace' '--without-gcc' '--enable-loadable-sqlite-extensions' 'MACOSX_DEPLOYMENT_TARGET=10.12' 'CC=clang' 'PKG_CONFIG_PATH=/usr/local/opt/sqlite/lib/pkgconfig:/usr/local/opt/openssl/lib/pkgconfig:/usr/local/opt/xz/lib/pkgconfig' 'PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.12'" | |
# | |
# FYI: pyenv example | |
# CONFIG_ARGS = "'--prefix=/Users/tatsuro/.anyenv/envs/pyenv/versions/3.3.6' '--libdir=/Users/tatsuro/.anyenv/envs/pyenv/versions/3.3.6/lib' '--enable-framework' '--enable-framework=/Users/tatsuro/.anyenv/envs/pyenv/versions/3.3.6' 'LDFLAGS=-L/usr/local/opt/readline/lib -L/usr/local/opt/readline/lib -L/Users/tatsuro/.anyenv/envs/pyenv/versions/3.3.6/lib ' 'CPPFLAGS=-I/usr/local/opt/readline/include -I/usr/local |
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: utf-8 -*- | |
# | |
# https://docs.python.org/3.5/howto/pyporting.html#prevent-compatibility-regressions | |
from __future__ import absolute_import | |
from __future__ import division | |
from __future__ import print_function | |
def flatten(_iter): | |
''' Flatten iterable even if it includes other iterables. |
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 os, shutil | |
p = 'path' | |
moves = [(dirpath, filenames) for dirpath, dirnames, filenames in os.walk(p)] | |
for dirpath_src, filenames in moves: | |
dirpath_dest = dirpath_src.replace('java', 'groovy') | |
if not os.path.exists(dirpath_dest): | |
os.mkdir(dirpath_dest) | |
for f in filenames: | |
abspath_src = os.path.join(dirpath_src, f) |
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: utf-8 -*- | |
# | |
# https://docs.python.org/3.5/howto/pyporting.html#prevent-compatibility-regressions | |
from __future__ import absolute_import | |
from __future__ import division | |
from __future__ import print_function | |
from logging import getLogger, Formatter, StreamHandler, DEBUG | |
import pprint |
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
$ ifconfig en0 | awk '/inet addr:/{$2=substr($2,6)} /inet /{print $2}' | |
10.5.2.55 |