Skip to content

Instantly share code, notes, and snippets.

@pranithan-kang
pranithan-kang / find_missing_page.py
Last active December 13, 2022 10:21
หนังสือเล่มหนึ่งมีเลขหน้าระบุไว้ทุกแผ่นโดยเริ่มจากหน้าที่ 1 โดยหนังสือมีหน้ากระดาษอยู่หนึ่งแผ่นที่ขาดหายไป และเมื่อผลรวมของเลขหน้าทุกหน้าที่เหลือยู่ได้ผลรวมเป็น 999 หน้ากระดาษที่หายไปคือหน้าอะไร
# โจทย์
# ----
# หนังสือเล่มหนึ่งมีเลขหน้าระบุไว้ทุกแผ่นโดยเริ่มจากหน้าที่ 1 โดยหนังสือมีหน้ากระดาษอยู่หนึ่งแผ่นที่ขาดหายไป และเมื่อผลรวมของเลขหน้าทุกหน้าที่เหลือยู่ได้ผลรวมเป็น 999
# หน้ากระดาษที่หายไปคือหน้าอะไร
# ที่มาของโจทย์: asiamediasoft
# ตีโจทย์
# ----
# ให้ p คือหน้าสุดท้ายของหนังสือ s คือผลรวมของหน้าที่เหลืออยู่ (จากโจทย์คือ 999) และ m คือหน้าที่หายไป
@pranithan-kang
pranithan-kang / forget_app_pass_code.py
Last active December 13, 2022 10:20
forget_app_pass_code
# โจทย์
# ----
# ลืมรหัสเข้า app บนมือถือจำได้แค่เพียงว่ารหัสมี 4 หลัก ขึ้นต้นด้วยเลข 6 และหารด้วย 69 และ 96 ลงตัว
# คำถามคือรหัสผ่านคืออะไร
# ที่มาของโจทย์: asiamediasoft
def find_forgotten_passcode():
set_a = {i for i in range(6000, 7000) if i % 69 == 0}
set_b = {i for i in range(6000, 7000) if i % 96 == 0}
/** @format */
import { PrismaClient } from "@prisma/client";
import { Batch, Product } from "./app.model";
import { IProductRepository } from "./app.repository";
import { AppService } from "./app.service";
import { AbstractUnitOfWork, PrismaUnitOfWork } from "./unitOfWork";
class FakeProductRepository implements IProductRepository {
constructor(private batches: Batch[]) {}
@pranithan-kang
pranithan-kang / solution.txt
Last active August 20, 2023 06:07
Wine glass solution
1-st pouring
n=1
0.500
2-nd pouring
n=2
1
0.500 0.500
@pranithan-kang
pranithan-kang / egg.py
Last active January 4, 2024 10:16
วาดรูปวงกลม วงรี และรูปไข่
# %%
from sympy import plot_implicit, symbols, Eq
from matplotlib import pyplot as plt
import numpy as np
x, y = symbols("x y")
def plot(equation, x_range, y_range, width=5, height=5, show=True):
p = plot_implicit(
@pranithan-kang
pranithan-kang / number-block.py
Last active January 4, 2024 08:49
number-block generate game
"""
this program generates a random number block and prints it
"""
import random
class NumberBlock:
# 1 - 2 - 3
# | | |
@pranithan-kang
pranithan-kang / area-calculation-playground.sql
Last active January 4, 2024 09:25
Area calculation from given lat, lng with SQL
drop table my_polygon;
create table my_polygon (
id integer primary key autoincrement,
polygon_set char(50),
vertex_order integer not null,
lat real not null,
lng real not null
);
insert into my_polygon (polygon_set, vertex_order, lat, lng)
values ('set_1', 1, 1, 8),
@pranithan-kang
pranithan-kang / rdbms-transaction-experimental.sql
Created February 2, 2024 09:47
RDBMS Transaction Experimental
create table abc (
a int primary key,
b text
) ;
begin transaction; -- begin transaction
insert into abc (a, b) values (1, 'testing'); -- success
insert into abc (a, b) values (1, 'testing2'); -- failed
commit; -- rollback
end; -- end transaction
@pranithan-kang
pranithan-kang / README.md
Last active February 22, 2024 04:17
phpenv installation

Install phpenv on mac

  • install phpenv from it's instruction, including optional steps

  • install the related libraries, refer to this issue

  • normally, on macos, you cannot use plain install command, otherwise, you face the problem configure: error: Please reinstall the [PACKAGE] distribution

  • so, install target php version available from php-build list

@pranithan-kang
pranithan-kang / GET_TB.sql
Last active March 4, 2024 08:48
GET TABLE NAME LIMITED BY ORACLE 30 CHARACTER RULE
CREATE OR REPLACE FUNCTION PDBADMIN.GET_TB(DJANGO_FULL_INSTANCE_NAME IN VARCHAR) RETURN VARCHAR
IS
/**
* GET TABLE NAME LIMITED BY ORACLE 30 CHARACTER RULE
* RELATED DJANGO CODE IS [HERE](https://github.com/django/django/blob/main/django/db/backends/utils.py#L283)
*
* PARAMETER
* ---------
* - DJANGO_FULL_INSTANCE_NAME [VARCHAR] IS DJANGO_APP_NAME PLUS '_' PLUS DJANGO_MODEL_NAME
* FOR EXAMPLE, IF YOU WOULD LIKE TO GET THE TABLE NAME OF RequestForCompensationAppealItem