Skip to content

Instantly share code, notes, and snippets.

View RanolP's full-sized avatar
๐Ÿค“
Otaku save the world

RanolP RanolP

๐Ÿค“
Otaku save the world
View GitHub Profile
@RanolP
RanolP / enumUtil.ts
Last active January 23, 2021 18:39
Add static method to enum without namespace in TypeScript
type NoConflict<
A extends Record<string | symbol, unknown>,
B extends string | number | symbol
> = { [K in keyof A]: K extends B ? never : A[K] };
type PropsUnion<A> = { [K in keyof A]: A[K] }[keyof A];
export function withMethods<
Origin extends Record<string | symbol, unknown>,
Methods extends Record<string | symbol, unknown>
@RanolP
RanolP / inverse-type.ts
Last active November 19, 2019 02:01
I'd like to introduce the `Inverse` type in TypeScript.
// For Readibility, I've separated it into type.
type Keyable = string | number | symbol;
// Get value union type.
// for `{ a: true, b: 3 }` it will give you `boolean | number` type.
// Also for array, it will give you commonest type of the array.
type GetValueUnion<T> = T[keyof T];
// This type will inverse keys and values.
// for `{ a: 'str', b: 3 }` it will give you `{ 3: 'b', str: 'a' }` type.
@RanolP
RanolP / rust_ps_input.rs
Last active July 10, 2020 04:33
Easier input processing in Rust when Problem Solving
//! This is free and unencumbered software released into the public domain.
//!
//! Anyone is free to copy, modify, publish, use, compile, sell, or
//! distribute this software, either in source code form or as a compiled
//! binary, for any purpose, commercial or non-commercial, and by any
//! means.
//!
//! In jurisdictions that recognize copyright laws, the author or authors
//! of this software dedicate any and all copyright interest in the
//! software to the public domain. We make this dedication for the benefit
@RanolP
RanolP / josa-ext.ts
Created August 23, 2020 13:00
์กฐ์‚ฌ๋ฅผ ์กฐ์‚ฌํ•˜์„ธ์š”
type TailId = -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27;
function tailIdOf(word: string): TailId {
if (word.length === 0) {
return -1;
}
const last = word[word.length - 1];
if (last < '๊ฐ€' || 'ํžฃ' < last) {
return -1;
}
@RanolP
RanolP / rke.ts
Last active May 7, 2022 13:55
rke(I like to call it '๊ฐ‡'), Replace Korean Entities
type TailId = -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27;
function tailIdOf(word: string): TailId {
if (word.length === 0) {
return -1;
}
const last = word[word.length - 1];
if (last < '๊ฐ€' || 'ํžฃ' < last) {
return -1;
}
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Preact Quickstart</title>
</head>
<body>
<script type="module">
import { html, render, useState, useEffect } from 'https://cdn.skypack.dev/[email protected]/preact/standalone';
const BoundType = Object.freeze({
Included: 'bound_type::included',
Excluded: 'bound_type::excluded',
});
class Bound {
constructor(type, value) {
this.type = type;
this.value = value;
}
@RanolP
RanolP / iosevka-nf-concentrator.mjs
Last active June 4, 2022 04:48
Download, Unzip, Classify.
import { promises as fs, constants as FS } from 'node:fs';
import { exec } from 'node:child_process';
import { promisify } from 'node:util';
import path from 'node:path';
const ColorRegex = /(?:\\([fFbB])([0-9]))|(\\0)/g;
function echo(templates, ...params) {
console.log(
String.raw(templates, ...params)
.replaceAll(ColorRegex, (_, fb, id, zero) =>
@RanolP
RanolP / Granola.c
Last active August 5, 2024 17:39
๋†€๋ผ์šด ๊ทธ๋ž˜ํ”„ C ๋‹จ์ผ ํŒŒ์ผ
/*
* y = f(x) ๊ผด์˜ ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆฌ๋Š” ํ”„๋กœ๊ทธ๋žจ์ž…๋‹ˆ๋‹ค.
* ์ด ํŒŒ์ผ์„ ๋นŒ๋“œํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” gdi32๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
* Dev C++ ๊ธฐ์ค€
* 1. ํŒŒ์ผ > ์ƒˆ๋กœ ๋งŒ๋“ค๊ธฐ > ํ”„๋กœ์ ํŠธ ์—์„œ Console Application์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.
* 2. ํ•ด๋‹น ํ”„๋กœ์ ํŠธ๊ฐ€ ์—ด๋ฆฐ ์ƒํƒœ์—์„œ, ํ”„๋กœ์ ํŠธ > ํ”„๋กœ์ ํŠธ ์˜ต์…˜์„ ์—ด๊ณ , ๋งค๊ฐœ๋ณ€์ˆ˜๋“ค ํƒญ์—์„œ Linker ์นธ์— "-lgdi32" (๋”ฐ์˜ดํ‘œ ์•ˆ์˜ ๊ฒƒ)์„ ๋„ฃ์Šต๋‹ˆ๋‹ค.
*
* ์‚ฌ์šฉ ๋ฐฉ๋ฒ•
* 1. y = f(x)์˜ ๊ทธ๋ž˜ํ”„์—์„œ f(x)์— ํ•ด๋‹นํ•˜๋Š” ๋ถ€๋ถ„์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
* ์ด ๋•Œ, ์—ฐ์‚ฐ์ž ์šฐ์„ ์ˆœ์œ„๋Š” ์ ์šฉ๋˜์ง€ ์•Š์œผ๋ฉฐ ์™ผ์ชฝ๋ถ€ํ„ฐ ๊ฒฐํ•ฉ๋ฉ๋‹ˆ๋‹ค
@RanolP
RanolP / prism2curse.mjs
Last active November 7, 2022 14:03
Prism ๋Ÿฐ์ฒ˜์˜ ๊ธฐ๊ธฐ๋ฌ˜๋ฌ˜ํ•œ .index ํด๋”์™€ mmc-pack.json์„ ์ž˜ ํƒ๊ตฌํ•ด์„œ Curseforge ๋ชจ๋“œํŒฉ์„ ๋งŒ๋“ค์–ด๋ณด์ž
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
const MODPACK_VERSION = '';
const MODPACK_AUTHOR = '';
const MODPACK_NAME = '';
const mmcPack = JSON.parse(
await fs.readFile('mmc-pack.json', { encoding: 'utf8' })
);