Skip to content

Instantly share code, notes, and snippets.

View hatemogi's full-sized avatar
๐Ÿ˜ƒ

Daehyun Kim hatemogi

๐Ÿ˜ƒ
View GitHub Profile
@hatemogi
hatemogi / tracing_subscriber_init.rs
Created November 19, 2024 01:17
tracing_subscriber ์ดˆ๊ธฐํ™”
tracing_subscriber::registry()
.with(fmt::layer())
.with(
EnvFilter::try_from_default_env()
.unwrap_or_else(|_| EnvFilter::new("{crate_name}=debug")),
)
.init();
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
export default {
input: 'src/index.ts',
output: {
dir: 'public',
format: 'cjs'
},
@hatemogi
hatemogi / update_view_metadata.sql
Created January 25, 2023 05:53
PG's view columns do not follow "NOT NULL" from the original table's
-- PostgreSQL์—์„œ view๋ฅผ ์ƒ์„ฑํ•˜๋ฉด, ํ•ด๋‹น view์˜ ์ปฌ๋Ÿผ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ์ค‘์—, null์—ฌ๋ถ€๊ฐ€ ์ž˜ ์ €์žฅ๋˜์ง€ ์•Š๋Š” ๋ฌธ์ œ.
-- ์ข€ ์ฐœ์ฐœํ•˜์ง€๋งŒ, ๋ทฐ ์ƒ์„ฑ ํ›„์— view์˜ metadata๋ฅผ ์ˆ˜๋™์œผ๋กœ ์—…๋ฐ์ดํŠธ ํ•ด์„œ, NOT NULL ์ •๋ณด๋ฅผ ์—…๋ฐ์ดํŠธ ํ•  ์ˆ˜ ์žˆ์Œ.
CREATE VIEW a_view_from_table AS
SELECT *
FROM original_table
; -- WHERE {conditions}
UPDATE pg_attribute
SET attnotnull=true
@hatemogi
hatemogi / elm-format.md
Created January 18, 2023 04:57
elm-format์„ M1์šฉ ๋ฐ”์ด๋„ˆ๋ฆฌ๋กœ ๋นŒ๋“œํ•˜๊ธฐ

๋ฌธ์ œ

  • M1 ๋งฅ๋ถํ”„๋กœ์—์„œ, elm-format์ด ๋•Œ๋กœ ๋А๋ฆฌ๊ฒŒ ๋ฐ˜์‘ํ•œ๋‹ค.
  • ์ฐพ์•„๋ณด๋‹ˆ, ๊ธฐ๋ณธ ์„ค์น˜๋˜๋Š” elm-format์€ x86๋ฐ”์ด๋„ˆ๋ฆฌ๋‹ค.
  • M1์šฉ์œผ๋กœ ๋ฐ”์ด๋„ˆ๋ฆฌ๋ฅผ ๋งŒ๋“ค๋ฉด ๋นจ๋ผ์ง€์ง€ ์•Š์„๊นŒ?

์ •๋ณด

  • ํ•ด๋‹น ์ด์Šˆ๋ฅผ ๊ฒ€์ƒ‰ํ•ด๋ณด๋‹ˆ avh4/elm-format#723 ์—ฌ๊ธฐ์— ์ด๋ฏธ ์–ธ๊ธ‰๋จ.
  • ์—ฌ๋Ÿฌ ์ด์œ ๋กœ ์•„์ง m1๋ฐ”์ด๋„ˆ๋ฆฌ๋Š” ๋ฐฐํฌ๋˜๊ณ  ์žˆ์ง€ ์•Š์ง€๋งŒ, ๋กœ์ปฌ์—์„œ ๋”ฐ๋กœ ๋นŒ๋“œํ•  ์ˆ˜๋Š” ์žˆ๊ฒ ๋‹ค.
@hatemogi
hatemogi / object_id.sql
Created January 13, 2023 14:44
PG function generates a mongodb's objectId
CREATE SEQUENCE IF NOT EXISTS object_id_counter AS int;
CREATE OR REPLACE FUNCTION generate_object_id() RETURNS CHAR(24)
AS $$
DECLARE
id CHAR(24);
BEGIN
SELECT right(to_hex(floor(extract(epoch from now()))::integer), 8)
|| right(lpad(to_hex(pg_backend_pid()), 10, '0'), 10)
|| right(lpad(to_hex(nextval('object_id_counter')), 6, '0'), 6)
-- x์›์†Œ๋ฅผ n๊ฐœ๋งŒํผ ๊ฐ–๊ณ  ์žˆ๋Š” 1์ฐจ์› ๋ฐฐ์—ด์„ ์ƒ์„ฑ
CREATE OR REPLACE FUNCTION array_replicate(x anycompatible, n integer)
RETURNS anycompatiblearray AS $$
BEGIN
RETURN array_fill(x, ARRAY[n]);
END
$$ LANGUAGE plpgsql;
-- ๋ฐฐ์—ด xs์—์„œ ์ตœ๋Œ€ n๊ฐœ์˜ ์š”์†Œ๋งŒ ์ถ”์ถœ.
@hatemogi
hatemogi / gist:56338b0863dedf7ee38964d990c7351a
Created July 18, 2022 14:01
favicon.png -> favicon.ico ๋ณ€ํ™˜
convert favicon.png -bordercolor white -border 0 \
\( -clone 0 -resize 16x16 \) \
\( -clone 0 -resize 32x32 \) \
\( -clone 0 -resize 48x48 \) \
\( -clone 0 -resize 64x64 \) \
\( -clone 0 -resize 128x128 \) \
\( -clone 0 -resize 256x256 \) \
-delete 0 -alpha off -colors 256 favicon.ico
@hatemogi
hatemogi / .scalafmt.conf
Last active February 16, 2023 08:07
scalafmt ์„ค์ • ํŒŒ์ผ
version = 3.7.1
maxColumn = 120
runner.dialect=scala3
@hatemogi
hatemogi / Time.java.md
Created March 8, 2021 08:25
java.time.Instant ๋ฅ˜์˜ ์ฐจ์ด์ 

Instant, LocalDateTime, OffsetDateTime, ZonedDateTime

  • Instant๋Š” UTC๊ธฐ์ค€ ์œ ๋‹‰์Šค ํƒ€์ž„์Šคํƒฌํ”„. ์ดˆ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” long, nano์ดˆ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” int๋กœ ๊ตฌ์„ฑ๋จ.
  • LocalDateTime์€, ์‹œ๊ฐ„๋Œ€๋Š” ์—†์ด, ์‹œ๊ฐ„ ์ž์ฒด๋งŒ nano์ดˆ๋‹จ์œ„๊นŒ์ง€ ํ‘œํ˜„.
  • OffsetDateTime์€, ์‹œ๊ฐ„๋Œ€ ์ •๋ณด๋ฅผ UTC๊ธฐ์ค€ ์˜คํ”„์…‹(ZoneOffset)์œผ๋กœ ๊ด€๋ฆฌํ•˜๋Š” ์‹œ๊ฐ„. ์˜ˆ) UTC+09
  • ZonedDateTime์€, ์‹œ๊ฐ„๋Œ€ ์ •๋ณด๋ฅผ ZoneId๋กœ ๊ด€๋ฆฌ. ์˜ˆ) Asia/Tokyo

๊ฐ๊ฐ์˜ ์ฐจ์ด

  • LocalDateTime vs. OffsetDateTime|ZonedDateTime => ์‹œ๊ฐ„๋Œ€ ์ •๋ณด ํฌํ•จ ์—ฌ๋ถ€
type Signal = LazyList[Boolean]
def inv(xs: => Signal): Signal = xs map { ! _ }
def reg(init: => Boolean, d: => Signal): Signal = init #:: d
val tff: Signal = {
def d: Signal = inv(q)
def q: Signal = reg(false, d)
q
}