Skip to content

Instantly share code, notes, and snippets.

View peketamin's full-sized avatar
🐔
Hello world!

Yuki Yokoyama peketamin

🐔
Hello world!
View GitHub Profile
@peketamin
peketamin / GLSL_Noise_Algorithm_in_Python.md
Last active November 6, 2023 13:33
"10年程前からビデオゲーム開発者の間で語り継がれている謎の一様乱数生成アルゴリズム" を Python で実装 (自信なし)

"10年程前からビデオゲーム開発者の間で語り継がれている謎の一様乱数生成アルゴリズム" を Python で実装 (自信なし)

元ネタ

@peketamin
peketamin / generate_user_list.md
Last active July 21, 2019 10:14
ユーザーレコードをDBから読み込んでCSVを出力するクラスを作る、というお題に対して、どうオブジェクト指向で実装するか (Python)

ユーザーレコードをDBから読み込んでCSVを出力するクラスを作る、というお題に対して、どうオブジェクト指向で実装するか (Python)

手続き指向での提出例

import datetime
from typing import Dict, List

import pandas as pd
@peketamin
peketamin / cumsum.py
Created July 20, 2019 02:42
Cumulative sum in Python
def sum(l: list):
if not l:
return 0
i = l.pop()
return sum(l) + i
print(sum([1,2,3,4,5]))
# 15
@peketamin
peketamin / class_like_obj.js
Created July 8, 2019 08:11
Lightweight ES5 class like object definition
var Person = {
init: function() {
this.first_name = '';
this.last_name = '';
return this;
},
getFullName: function() {
return this.first_name + ' ' + this.last_name;
},
};
@peketamin
peketamin / q_json.sql
Last active May 11, 2019 08:36
PostgreSQL: JSON query example
-- 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 13:31
Thread and BoundedSemaphore
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()
@peketamin
peketamin / slack_notification.py
Created April 24, 2019 03:23
Slack notification
"""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 April 8, 2019 04:25
モノリシックレポジトリ (単一レポ運用) についてリンク集
@peketamin
peketamin / report_celery_chunks_and_soft_time_limit_exceeded.rst
Last active April 2, 2019 16:49
Investigation: SoftTimeLimitExceeded occurred in task.chunks()

Experiment

Assuming: Using Celery with Django.

Target task is debug_task (in my_app.celery)

@peketamin
peketamin / maybe_number.isdigit.py
Created March 29, 2019 11:39
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