Skip to content

Instantly share code, notes, and snippets.

@yukithm
yukithm / encryption.rb
Created July 12, 2016 08:10
[Ruby] A simple example of AES encryption in Ruby
# encoding: utf-8
require "openssl"
require "base64"
CIPHER_ALGO = "AES-256-CBC"
SALT_SIZE = 8
def encrypt(data, pass)
salt = OpenSSL::Random.random_bytes(SALT_SIZE)
@yukithm
yukithm / docker-wrapper.sh
Last active June 14, 2018 07:46
docker subcommand wrapper
function docker() {
case "$1" in
"compose") docker-compose "${@:2}" ;;
"machine") docker-machine "${@:2}" ;;
*) command docker "${@:1}" ;;
esac
}
@yukithm
yukithm / oop.lua
Created August 22, 2018 03:46
[Lua] OOP example
function NewClass(baseClass)
local newClass = {}
if baseClass then
setmetatable(newClass, {__index = baseClass})
end
function newClass:super(...)
local newInst = {}
if baseClass then
newInst = baseClass:new(...)
end
@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:
@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 / 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 / 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 / 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 / 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 / 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})",