Skip to content

Instantly share code, notes, and snippets.

View okabe-yuya's full-sized avatar
🏠
Working from home

okbee okabe-yuya

🏠
Working from home
View GitHub Profile
  • TODO
    • A
    • B
  • C
@okabe-yuya
okabe-yuya / sample_data.sql
Last active September 4, 2023 12:14
JOINがインデックス作成前後でどのようなパフォーマンス変化を生じさせるのかを検証した際に使用したテーブルです。
BEGIN;
CREATE TABLE IF NOT EXISTS students (
student_id SERIAL PRIMARY KEY,
first_name VARCHAR(30) NOT NULL,
last_name VARCHAR(30) NOT NULL,
birthday DATE NOT NULL,
gender CHAR(1),
created_at TIMESTAMP,
updated_at TIMESTAMP
);
@okabe-yuya
okabe-yuya / fsm.ex
Created May 27, 2023 03:00
有限状態機械のサンプルコード
defmodule StateServer do
@transitions %{
initial: %{ receive_order: :check_stock },
check_stock: %{ purchase: :ready_for_snipment },
ready_for_snipment: %{ snipment: :package_arrive },
package_arrive: %{ initial: :initial }
}
def run do
spawn(fn -> server(:initial) end)
@okabe-yuya
okabe-yuya / generata_hash_from_list.rb
Created May 16, 2023 11:42
配列からハッシュを作る際のパフィーマンスを測定するコードです
require 'benchmark'
list = (1..10000).to_a
Benchmark.bm(20) do |x|
x.report('for:') do
hash = {}
for n in list do
hash[n.to_s] = n * 2
end
end
@okabe-yuya
okabe-yuya / verification_sqls.md
Created March 9, 2023 01:32
中間テーブルには複合インデックスと単一インデックスどちらを作成すれば良いのかで使用するsql

JOINのみ

EXPLAIN ANALYZE SELECT
  *
FROM
  user_products AS up
JOIN
  users AS u
ON
@okabe-yuya
okabe-yuya / sample_data.md
Created March 9, 2023 01:26
検証データの詳細

table

BEGIN;
  CREATE TABLE IF NOT EXISTS users (
    user_id SERIAL PRIMARY KEY,
    user_name VARCHAR(50) NOT NULL
  );
  CREATE TABLE IF NOT EXISTS products (
 product_id SERIAL PRIMARY KEY,
@okabe-yuya
okabe-yuya / verification_multiindex.md
Last active March 9, 2023 01:43
中間テーブルに対して作成したインデックスの種類による実行結果

検証結果

中間テーブルの情報。現在はインデックスはuser_product_idにのみ付与。

                                       Table "public.user_products"
     Column      |  Type   | Collation | Nullable |                        Default                         
-----------------+---------+-----------+----------+--------------------------------------------------------
 user_product_id | integer |           | not null | nextval('user_products_user_product_id_seq'::regclass)
 user_id         | integer |           |          | 
 product_id      | integer |           |          | 
# ref: https://www.paweldabrowski.com/articles/rails-enum-under-the-hood
module Channel
def enum_channels(mappings)
mappings.each_pair do |name, values|
singleton_class.define_method("#{name}_hash") { values }
values.each_pair do |key, value|
define_method("#{key}?") { self.status == value }
end
@okabe-yuya
okabe-yuya / splatoon_equipments.sql
Created January 31, 2023 12:09
スプラトゥーン3のER図を考える【キャラクター編】の装備側のSQL
/* プレイヤー情報 */
CREATE TABLE IF NOT EXISTS players (
player_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
name_changed_at TIMESTAMP NOT NULL,
last_loggined_at TIMESTAMP NOT NULL
);
@okabe-yuya
okabe-yuya / splatoon_style.sql
Last active January 31, 2023 12:09
スプラトゥーン3のER図を考える【キャラクター編】のスタイル側のSQL
/* プレイヤー情報 */
CREATE TABLE IF NOT EXISTS players (
player_id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
name_changed_at TIMESTAMP NOT NULL,
last_loggined_at TIMESTAMP NOT NULL
);