This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Provider | |
include FindSubclassBySlug | |
end | |
module FindSubclassBySlug | |
extend ActiveSupport::Concern | |
class SubclassNotFound < StandardError; end | |
included { load_subclasses! } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ExtractParams<Template extends string> = | |
Template extends `${infer A}/${infer B}` ? ExtractParams<A> | ExtractParams<B> | |
: Template extends `/${infer A}` ? ExtractParams<A> | |
: Template extends `:${infer A}/${infer B}` ? A | ExtractParams<B> | |
: Template extends `:${infer A}` ? A | |
: never | |
type Params<Template extends string> = ExtractParams<Template> extends string ? Record<ExtractParams<Template>, string> : never | |
class TrieNode<Template extends `/${string}`, R> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Notion | |
class Task < Database::Page | |
self.database_id = 'e383bcee-e0d8-4564-9c63-900d307abdb0' | |
def event_date | |
property('作成日時') #=> Notion::Database::Property | |
end | |
def assignees | |
property('担当者') #=> Array<Notion::Database::Property> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class TimeoutError extends Error {} | |
export class Timeout<T> { | |
readonly controller: AbortController | |
readonly error = new TimeoutError() | |
readonly promise: Promise<T> | |
constructor( | |
fn: (signal: AbortSignal) => Promise<T>, | |
timeout: number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PlainTime | |
include Comparable | |
attr_reader :hour, :minute, :second | |
HOUR_PER_DAY = 24 | |
MINUTE_PER_HOUR = 60 | |
SECOND_PER_MINUTE = 60 | |
SECOND_PER_HOUR = HOUR_PER_DAY * MINUTE_PER_HOUR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module InheritByEnum | |
extend ActiveSupport::Concern | |
class_methods do | |
def inherit_by_enum(**options) | |
name, values = options.sole.to_a | |
plural_name = name.to_s.pluralize | |
self.inheritance_column = name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import toraViewer, { type Viewer } from '@toralab/tora-viewer'; | |
function finiteInteger<R extends number | null | undefined>(value: string | null, defaultValue: R = 0): R { | |
if (!value) { | |
return defaultValue | |
} | |
const parsed = parseInt(value) | |
if (!Number.isFinite(parsed)) { | |
throw new RangeError(`${value} cannot be parsed to finite number`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Byte { | |
static readonly units = { | |
terabyte: 2 ** 40, | |
gigabyte: 2 ** 30, | |
megabyte: 2 ** 20, | |
kilobyte: 2 ** 10, | |
}; | |
private unit = "byte"; | |
private divisor = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function memo<T extends (...args: any[]) => any>(fn: T): T { | |
const call = Object.assign(fn, { cache: null as ReturnType<T> | null }) | |
return ((...args: Parameters<T>) => call.cache ??= call(...args)) as T | |
} | |
export class Foo { | |
bar = memo(() => 1) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hljs from 'highlight.js' | |
import typescript from 'highlight.js/lib/languages/typescript' | |
const css = new CSSStyleSheet() | |
css.replaceSync(` | |
@import 'highlight.js/styles/github-dark.css'; | |
overflow-x: auto; | |
font-size: 12px; | |
border-radius: 8px; |
NewerOlder