Skip to content

Instantly share code, notes, and snippets.

@yukithm
yukithm / bomreader.go
Created June 29, 2023 06:27
BOM aware Unicode Reader
package bomreader
import (
"bufio"
"bytes"
"io"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
)
@yukithm
yukithm / hash_strings.go
Created May 8, 2020 07:18
ハッシュ値の文字列長(Hex, Base64) https://play.golang.org/p/LQAUgxzAaIh
package main
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"encoding/base64"
"encoding/hex"
"fmt"
@yukithm
yukithm / .ideavimrc
Created December 18, 2019 00:43
.ideavimrc
set surround
set hlsearch
set incsearch
set nowrapscan
set ignorecase
set smartcase
set keymodel=startsel,stopsel
nnoremap gr gT
@yukithm
yukithm / JooqExt.kt
Created November 20, 2019 09:52
[kotlin] jOOQ: PostgreSQL's setval() for DSLContext
package com.example.jooqext
import org.jooq.DSLContext
import org.jooq.Sequence
import org.jooq.impl.DSL
fun <T : Number> DSLContext.setval(sequence: Sequence<T>, value: T, isCalled: Boolean = true) =
select(
DSL.field(
"setval({0}, {1}, {2})",
@yukithm
yukithm / generateMysqlAesKey.kt
Last active November 8, 2019 01:37
[kotlin] generateMysqlAesKey
fun generateMysqlAesKey(key: String): ByteArray {
val myKey = ByteArray(16)
key.forEachIndexed { i, c ->
myKey[i % 16] = (myKey[i % 16].xor(key[i].toByte()))
}
return myKey
}
@yukithm
yukithm / ldap-password.rb
Created October 17, 2019 04:06
[ruby] LDAP password utility
# encoding: utf-8
require 'digest/md5'
require 'digest/sha1'
require 'base64'
module Example
class LDAP
# LDAPパスワード生成クラス
class Password
@yukithm
yukithm / token.kt
Created July 18, 2019 10:51
[Kotlin] Create secure random token
import java.security.SecureRandom
import java.util.Base64
// Which is better?
val strong = SecureRandom.getInstanceStrong()
val sha1prng = SecureRandom.getInstance("SHA1PRNG")
println(strong.algorithm)
println(sha1prng.algorithm)
fun ByteArray.toHexString() = joinToString("") { "%02x".format(it) }
@yukithm
yukithm / cloud-config.yml
Last active February 22, 2024 09:23
Make swap by cloud-init
#cloud-config
mounts:
- [ "/swapfile", "none", "swap", "defaults", "0", "0" ]
runcmd:
- [ "dd", "if=/dev/zero", "of=/swapfile", "bs=1G", "count=4" ]
- [ "chmod", "600", "/swapfile" ]
- [ "mkswap", "/swapfile" ]
- [ "swapon", "/swapfile" ]
@yukithm
yukithm / temporal-query-example.kts
Last active November 16, 2018 10:56
TemporalQuery example in Kotlin
import java.time.*
import java.time.temporal.ChronoField
import java.time.temporal.TemporalAdjusters
import java.time.temporal.TemporalQuery
import java.time.temporal.UnsupportedTemporalTypeException
val year = Year.of(2018)
// 感謝祭
// 11月の第4木曜日
@yukithm
yukithm / docker-compose.yml
Last active September 20, 2018 01:43
Docker Rocket.Chat
version: "3"
services:
rocketchat:
container_name: rocketchat
image: rocket.chat:latest
restart: on-failure:3
volumes:
- ./uploads:/app/uploads
depends_on: