Skip to content

Instantly share code, notes, and snippets.

Hello world!

Yuki Yokoyama peketamin

Hello world!
Block or report user

Report or block peketamin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
peketamin / q_json.sql
Last active May 11, 2019
PostgreSQL: JSON query example
View q_json.sql
virtual_table AS (SELECT key, value FROM jsonb_each('{"k": {"sub_key": 10}, "k2": {"sub_key": 20}}')),
extracted_values AS (SELECT value->'sub_key' AS sub_key FROM virtual_table)
SELECT * FROM extracted_values
peketamin /
Created May 10, 2019
Thread and BoundedSemaphore
import time
from threading import Thread, BoundedSemaphore
thread_limiter = BoundedSemaphore(value=MAX_CONCURRENT_THREADS)
class MyThread(Thread):
def run(self):
"""Slack notification
This needs:
- requests==2.11.1
- slackclient==1.3.1
import logging
import os
from socket import gethostname
peketamin / mono_repo.rst
Created Apr 8, 2019
モノリシックレポジトリ (単一レポ運用) についてリンク集
View mono_repo.rst
peketamin / report_celery_chunks_and_soft_time_limit_exceeded.rst
Last active Apr 2, 2019
Investigation: SoftTimeLimitExceeded occurred in task.chunks()
View report_celery_chunks_and_soft_time_limit_exceeded.rst


Assuming: Using Celery with Django.

Target task is debug_task (in my_app.celery)

peketamin /
Created Mar 29, 2019
Check None, float('nan'), float('inf'): str(maybe_number).isdigit()
def zero_or_number(maybe_number):
if str(maybe_digit).isdigit():
return maybe_number
return 0
peketamin /
Created Mar 5, 2019
Example of Programming By Contract (契約プログラミングサンプル)
from logging import getLogger
import pandas as pd
from core.db import get_new_user_id
from user_management import tasks # celery tasks
logger = getLogger(__name__)
peketamin /
Created Dec 12, 2018
One of way to fix "Removed Records: Named range from /xl/workbook.xml"

Replace double-width parentheses "()" to single-width parentheses "()" of sheet's names.

peketamin /
Created Nov 29, 2018
Python Abstract class
from abc import ABC
peketamin / example_of_exception_handling.rst
Last active Nov 9, 2018
Example of Exception handling
View example_of_exception_handling.rst
def greeting(user_id):
    """Parent func"""
        user_name = get_user_name(user_id)
    except User.DoesNotExists as e:
        logger.error("[greeting] user: {user_id} not found.")
        return None
    print(f"Hello, {user_name}")
You can’t perform that action at this time.