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
peketamin / q_json.sql
Last active May 11, 2019
PostgreSQL: JSON query example
View q_json.sql
-- https://www.postgresql.org/docs/9.5/functions-json.html
WITH
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
peketamin / test_thread.py
Created May 10, 2019
Thread and BoundedSemaphore
View test_thread.py
import time
from threading import Thread, BoundedSemaphore
MAX_CONCURRENT_THREADS = 3
thread_limiter = BoundedSemaphore(value=MAX_CONCURRENT_THREADS)
class MyThread(Thread):
def run(self):
thread_limiter.acquire()
View slack_notification.py
"""Slack notification
This needs:
- requests==2.11.1
- slackclient==1.3.1
"""
import logging
import os
from socket import gethostname
@peketamin
peketamin / mono_repo.rst
Created Apr 8, 2019
モノリシックレポジトリ (単一レポ運用) についてリンク集
View mono_repo.rst
@peketamin
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

Experiment

Assuming: Using Celery with Django.

Target task is debug_task (in my_app.celery)

@peketamin
peketamin / maybe_number.isdigit.py
Created Mar 29, 2019
Check None, float('nan'), float('inf'): str(maybe_number).isdigit()
View maybe_number.isdigit.py
def zero_or_number(maybe_number):
if str(maybe_digit).isdigit():
return maybe_number
return 0
@peketamin
peketamin / contract.py
Created Mar 5, 2019
Example of Programming By Contract (契約プログラミングサンプル)
View contract.py
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
peketamin / a_way_to_fix_excel.md
Created Dec 12, 2018
One of way to fix "Removed Records: Named range from /xl/workbook.xml"
View a_way_to_fix_excel.md

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

@peketamin
peketamin / python_abc.py
Created Nov 29, 2018
Python Abstract class
View python_abc.py
"""
https://docs.python.org/3/library/abc.html
https://qiita.com/kaneshin/items/269bc5f156d86f8a91c4
https://stackoverflow.com/questions/13646245/is-it-possible-to-make-abstract-classes-in-python
https://docs.djangoproject.com/en/2.1/topics/db/models/
https://stackoverflow.com/questions/33335005/is-there-any-difference-between-using-abc-vs-abcmeta
"""
from abc import ABC
@peketamin
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"""
    try:
        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.