Skip to content

Instantly share code, notes, and snippets.

View devlights's full-sized avatar
🤧
hay fever....

devlights devlights

🤧
hay fever....
View GitHub Profile
@devlights
devlights / git_branch_confirm_upstream_settings.md
Created June 6, 2018 08:35
[git] ブランチに上流ブランチが設定されているかどうかを確認するコマンド (git, branch, upstream, -vv)

上流ブランチが設定されているかどうかを確認するコマンド

$ git branch -vv
@devlights
devlights / zmq_python_rep_example.py
Created May 21, 2018 08:30
[python][zeromq] REP-REQのサンプル (REPがサーバ、REQがクライアント)
import zmq
def main():
ctx = zmq.Context()
socket = ctx.socket(zmq.REP)
socket.bind('tcp://*:5560') #: https://stackoverflow.com/questions/6024003/why-doesnt-zeromq-work-on-localhost
while True:
m = socket.recv()
@devlights
devlights / ciso8601_example.py
Last active May 18, 2018 04:10
[python] 最速日付解析ライブラリ ciso8601 のサンプル
"""
日付解析ライブラリ:ciso8601のサンプル
最速らしいので試してみた。
"""
import argparse
import time
from datetime import datetime, timedelta
import ciso8601
@devlights
devlights / recursive_relog.py
Created May 17, 2018 03:54
[python][windows] relog コマンドを 再帰的に実行して blg ファイルを csv に変換 (パフォーマンスカウンタ, バイナリからCSVへ変換)
import argparse
import pathlib
import subprocess
def main(args):
for p in pathlib.Path(args.target_dir).rglob('*.blg'):
csv_path = p.with_suffix('.csv')
subprocess.call(f'relog "{p}" -o "{csv_path}" -f CSV')
@devlights
devlights / ipython_useful_magic_command.md
Created May 7, 2018 08:55
[python][ipython] よく使うマジックコマンド

ipython で よく使われる マジックコマンド

%quickref

マジックコマンドのクイックリファレンス

%debug

デバッガを起動

@devlights
devlights / ipython_timeit_magic_command.md
Created May 7, 2018 08:50
[python][ipython] timeit マジックコマンドについてのメモ

ipython の timeit マジックコマンド

%timeit

In [1]: %timeit 1+1
28.3 ns ± 4.08 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

単一のステートメントの実行時間を測定する。

@devlights
devlights / build_python_environment_on_mac.md
Last active May 7, 2018 08:44
[python][mac] MacでPythonの環境構築 (Anaconda使わないパターン, pipとvenvを使う標準パターン)

MacでPythonの環境構築 (pipとvenvを使う標準パターン)

Python インストール

$ brew install python

Python インタープリター起動 (venv前)

@devlights
devlights / sympy_rational_example.py
Created May 6, 2018 01:41
[python][sympy] python の sympy を使って分数指数計算
import sympy
# 指数部分を定義 (マイナス2分の1乗)
n = -sympy.Rational(1, 2)
print(n)
# 8のマイナス2分の1乗を求める
r = 8**n
@devlights
devlights / sympy_factor_example.py
Created May 5, 2018 14:16
[python][sympy] python の sympy つかって因数分解
import sympy
# x を定義
x = sympy.Symbol('x')
# 式定義
# x^3 - 2x^2 - 5x + 6
expr = x**3 - 2*(x**2) - 5*x + 6
print(expr)
@devlights
devlights / linux_time_command_for_windows.md
Created April 20, 2018 02:24
[windows][powershell] linux や mac の time コマンドに近いものを windows で (実行時間を計測)

linux や mac の time コマンドに近いものを windows で

Powershell の Measure-Command を利用する

$ Measure-Command { Start-Process python -argumentList "test1.py" -Wait -NoNewWindow }

-Wait-NoNewWindow をつけないとうまくいかない。