Skip to content

Instantly share code, notes, and snippets.

View yt8492's full-sized avatar
😇
study

Yuta Tomiyama yt8492

😇
study
View GitHub Profile
@yt8492
yt8492 / gist:fe4047e2e256d6ce0fbd78907322fad2
Created March 31, 2024 18:06
ChromeExtensionPrivacyPolicy
策定日 バージョン
2024年4月1日
1.0.0

@yt8492が開発したGoogle Chrome Extensionで利用者の個人情報もしくはそれに準ずる情報を取り扱う際に、当開発者が遵守する方針を以下のとおりプライバシーポリシーとして定めます。

  • 以下、@yt8492を「当開発者」と記述します
  • 以下、Google Chrome Extensionを「ブラウザ拡張」と記述します
  • 以下、プライバシーポリシーを「本ポリシー」と記述します
@yt8492
yt8492 / fastIsBlank.kt
Created February 27, 2024 04:17
fastIsBlank
inline fun CharSequence.fastIsBlank(): Boolean {
for (i in 0..<length) {
val c = this[i]
if (!Character.isWhitespace(c) &&
c != '\u00a0' && c != '\u2007' && c != '\u202f') {
return false
}
}
return true
}
@yt8492
yt8492 / loading.kt
Last active August 29, 2021 11:15
loading
typealias RefreshFunc = () -> Unit
@Composable
fun loading(
loadMs: Long = 300
): Pair<Boolean, RefreshFunc> {
val (loading, setLoading) = remember {
mutableStateOf(true)
}
LaunchedEffect(key1 = loading) {
@yt8492
yt8492 / Debounce.kt
Last active August 27, 2021 08:19
Composable Debounce
@Composable
fun <T> rememberDebounce(
value: T,
delayMs: Long = 750
): T {
val (debouncedValue, setValue) = remember {
mutableStateOf(value)
}
LaunchedEffect(key1 = value) {
delay(delayMs)
@yt8492
yt8492 / Sieve.kt
Created March 15, 2021 08:39
Sieve of Eratosthenes
class Sieve(val max: Int) {
private val isPrimeArray: BooleanArray
init {
val array = BooleanArray(max + 1) {
true
}
array[0] = false
array[1] = false
val root = sqrt(max.toDouble()).toInt()
@yt8492
yt8492 / FooBuilder.kt
Created February 12, 2021 15:02
TypeSafeBuilder.kt
fun main() {
val result = FooBuilder.new()
.a("a")
.b("b")
.c("c")
.d("d")
.build()
println(result)
}
@yt8492
yt8492 / MatrixChainOrder.kt
Created August 17, 2020 19:31
MatrixChainOrder
fun main() {
val dimensionSequence = readLine()!!.splitToSequence(",").map(String::toInt).toList()
val (cost, parens) = matrixChainOrder(dimensionSequence)
println(cost)
println(parens)
}
fun matrixChainOrder(dimensionSequence: List<Int>): Pair<Int, String> {
val n = dimensionSequence.size - 1
val costTable = Array(n) {
@yt8492
yt8492 / Strassen.kt
Created August 13, 2020 18:37
Strassen
fun strassen(matrixA: List<List<Int>>, matrixB: List<List<Int>>): List<List<Int>> {
if (matrixA.size == 1) {
return listOf(listOf(matrixA[0][0] * matrixB[0][0]))
}
val (a11, a12, a21, a22) = div2(matrixA)
val (b11, b12, b21, b22) = div2(matrixB)
val s1 = matrixSub(b12, b22)
val s2 = matrixAdd(a11, a12)
val s3 = matrixAdd(a21, a22)
val s4 = matrixSub(b21, b11)
sealed class HuffmanNode {
abstract val codeSize: Int
data class CodeInfo(val code: Char, override val codeSize: Int) : HuffmanNode()
data class TreeNode(val left: HuffmanNode, val right: HuffmanNode, override val codeSize: Int) : HuffmanNode()
}
fun main() {
val text = "HELLO"
val result = huffman(text)
@yt8492
yt8492 / FileLineInputIterator.kt
Created August 4, 2020 16:20
Kotlin/Native posix FileLineInputIterator
import kotlinx.cinterop.ByteVar
import kotlinx.cinterop.allocArray
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.toKString
import platform.posix.fclose
import platform.posix.fgets
import platform.posix.fopen
class FileLineInputIterator(
filename: String