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 / 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 をつけないとうまくいかない。

@devlights
devlights / display_only_directory_with_ls.md
Last active April 15, 2018 16:58
[linux][mac] ls コマンドでディレクトリのみを表示する (ls, directory)

以下で表示される

$ ls -ld */

もしくは

$ ls -d */
@devlights
devlights / retrieve_physmemory_on_mac.md
Created April 15, 2018 16:34
[mac] メモリ量をコマンドラインから取得 (top, grep, memory physmem)

Mac で 使用メモリ量 を コマンドライン から取得

$ top -l 1 | grep -i physmem

出力例

PhysMem: 6359M used (1524M wired), 1832M unused.
@devlights
devlights / rxpy_example.py
Created April 13, 2018 09:26
[python][rxpy][reactive python] RxPYのサンプル
"""
Reactive Python (RxPy) のサンプル
2018/04/13:まだ途中
REFERENCES::
https://auth0.com/blog/reactive-programming-in-python/
https://github.com/ReactiveX/RxPY
"""
import threading
@devlights
devlights / sentry_logging_example.py
Last active April 5, 2018 08:31
[python][sentry] Sentryとloggingモジュールの組み合わせサンプル
"""
Sentry と logging の組み合わせのサンプル
DSN は 環境変数 SENTRY_DSN に設定してから起動します。
(*) Windowsの場合、一時設定するには以下のようにします。
$ set SENTRY_DSN=xxxxx
REFERENCES::
https://docs.python.jp/3/library/logging.config.html#logging-config-dictschema
https://docs.sentry.io/clients/python/integrations/logging/
@devlights
devlights / logging_config.json
Last active April 6, 2018 06:58
[python] logging.config.dictConfigのサンプル
{
"version": 1,
"disable_existing_loggers": "true",
"formatters": {
"console": {
"format": "[%(asctime)s][%(levelname)s] %(name)s %(filename)s:%(funcName)s:%(lineno)d | %(message)s",
"datefmt": "%Y/%m/%d %H:%M:%S"
}
},
"handlers": {
@devlights
devlights / fd_cat.py
Last active April 4, 2018 09:31
[python] subprocess.popen で ファイルディスクリプタを渡して別プロセス側でも同じファイルを同一 fd で読み取るサンプル (pass_fds)
"""
起動引数で指定された fd (ファイルディスクリプタ) を使ってデータを読み取り表示します。
(注意) subprocess.popen経由で呼び出されることを想定しています。
"""
import itertools
import os
import sys
def go():
@devlights
devlights / find_file_command_on_windows.md
Created April 2, 2018 08:36
[windows] windows で linux の find コマンドのようにファイルを検索するコマンド

where コマンドを利用する

> where /r ベースフォルダ 検索対象ファイルパターン(ワイルドカード指定可能)

現在のフォルダから再帰的に *.ini にマッチするファイルを検索する