Skip to content

Instantly share code, notes, and snippets.

@wanshot
wanshot / gist:c9ac1b955e359beae0edc12d5818f4f5
Last active December 7, 2023 09:47
ローカル開発をDocker for macからGitHub Codespacesに移行して便利に使っている話
@wanshot
wanshot / gist:b29da948229694278168d35c8539cde7
Last active December 10, 2018 08:52
Djangoのview内でのトランザクション
views.py
def hoge(request):
    with transaction.atomic():
        tasks.huga.delay()
    retrun response
  • 上記コードのトランザクションの範囲は、celeryのジョブキューにタスクを積むという処理に対してかかるので意味がない。
  • hoge関数の処理にトランザクションをかけたい場合は、タスクの処理内にトランザクションを記述する。
diff --git a/beproudbot/plugins/alias.py b/beproudbot/plugins/alias.py
index 153b635..4ccb1de 100644
--- a/beproudbot/plugins/alias.py
+++ b/beproudbot/plugins/alias.py
@@ -3,6 +3,7 @@ from slackbot.bot import respond_to
from utils.slack import get_user_name, get_slack_id_by_name
from db import Session
from beproudbot.plugins.alias_models import UserAliasName
+from beproudbot.arg_validator import BaseArgValidator, register_arg_validator, ValidationError
alembic
============
1. install alembic
-----------------------
::
$ pip install alembic
@wanshot
wanshot / gist:c96a5715130233926f8588fc25c28c97
Last active June 28, 2022 10:29
【Vim】バッファ同士でdiffをとる
1. Vimを起動してそのままdiffを取りたい内容を貼り付け
2. enewで新しいバッファを開く
3. 1.のバッファと比べたい内容を貼り付け
4. 3.のバッファでdiffthis
5. 1.のバッファでdiffthis
class MultiKeyDict(dict):
"""
>>> format_ = MultiKeyDict({(f.name, f.status): f.id for f in User.objects.all()})
>>> format_.get(u"test")
1L
>>> format_.get(1)
1L
"""
def __init__(self, *args, **kwargs):
for a in args: