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
package net.ayataka.marinetooler.utils.web | |
import java.io.IOException | |
import java.net.* | |
import java.nio.charset.Charset | |
class WebClient( | |
val cookie: CookieManager = CookieManager(), | |
val timeout: Int = 10000, // 10 sec | |
val encoding: String = "UTF-8" |
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
const val ENCRYPT_ALGORITHM = "AES" | |
fun String.encrypt(key: String): String { | |
val keySpec = SecretKeySpec(key.toByteArray(Charsets.UTF_8), ENCRYPT_ALGORITHM) | |
val iv = SecureRandom().generateSeed(keySpec.encoded.size) | |
val encrypted = Cipher.getInstance("$ENCRYPT_ALGORITHM/CBC/PKCS5PADDING").run { | |
init(Cipher.ENCRYPT_MODE, keySpec, IvParameterSpec(iv)) | |
doFinal(this@encrypt.toByteArray(Charsets.UTF_8)) | |
} | |
return "${hex(iv)}/${hex(encrypted)}" |
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 RateLimiter(private val period: Long, private val rate: Int) { | |
private val times = LinkedList<Long>() | |
fun check(): Boolean { | |
synchronized(times) { | |
val currentTime = System.currentTimeMillis() | |
times.removeIf { it < currentTime - period } | |
val isLimited = times.size >= rate | |
if (!isLimited) { |
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
fun Int.seconds() = this.toLong() * 1000 | |
fun Int.minutes() = this.toLong() * 1000 * 60 | |
fun Int.hours() = this.toLong() * 1000 * 60 * 60 |
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
package net.ayataka.bas.utils | |
import kotlinx.coroutines.experimental.* | |
import net.ayataka.bas.LOGGER | |
import kotlin.system.measureTimeMillis | |
fun CoroutineScope.timer(interval: Long, fixedRate: Boolean = true, action: suspend TimerScope.() -> Unit): Job { | |
return launch { | |
val scope = TimerScope() |
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
fun PipelineContext<*, ApplicationCall>.setSession(id: String, value: String) { | |
val session = call.sessions.get<Session>() ?: Session() | |
session.data[id] = value | |
call.sessions.set(session) | |
} | |
fun PipelineContext<*, ApplicationCall>.getSession(id: String): String? { | |
return call.sessions.get<Session>()?.data?.get(id) | |
} |
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
var inner_diameter = 2.5; // 2.5mm | |
var wrap_count = 9; // 9 wraps | |
var wrap_spacing = 0.01; // the default value for micro coil wrapping | |
var wire_width = ; // the diameter of the coil (mm) (https://www.steam-engine.org/wirewiz) | |
var coil_heat_capacity = ; // the heat capacity of the coil (mJ/K) | |
var coil_width = wire_width * wrap_count + wrap_spacing * (wrap_count - 1); | |
var inner_heat_capacity = Math.pow(inner_diameter / 10 / 2, 2) * Math.PI * coil_width / 10 * 2285.6225; | |
var result = inner_heat_capacity / coil_heat_capacity; |