Skip to content

Instantly share code, notes, and snippets.

View swarawan's full-sized avatar

Rio Swarawan Putra swarawan

  • Jakarta, Indonesia
View GitHub Profile
fun main(args: Array<String>) {
try {
print("Nilai 1: ")
val nilai1 = readLine()?.toInt()
print("Nilai 2: ")
val nilai2 = readLine()?.toInt()
println("1. Tambah")
println("2. Kurang")
println("3. Kali")
@swarawan
swarawan / BookAgent.kt
Created March 18, 2020 05:14
Multithread in Java
class BookAgent(private val bookService: BookService) : Thread() {
override fun run() {
val uuid = UUID.randomUUID().toString()
for (n in 0..10) {
sleep(5000)
bookService.save(
BookDataRequestModel(
name = "Book $uuid version: $n",
excerpt = "excerpt",
@swarawan
swarawan / DiffCallback.kt
Last active January 1, 2021 09:52
General Recycler View Adapter
class DiffCallback : DiffUtil.Callback() {
private var oldList: List<Any> = emptyList()
private var newList: List<Any> = emptyList()
fun setList(oldList: List<Any>, newList: List<Any>) {
this.oldList = oldList
this.newList = newList
}
@swarawan
swarawan / proguard-rules.pro
Created January 6, 2021 12:20
Android Proguard (kotlin, retrofit, okhttp, gson)
# Kotlin
# COMMON KOTLIN
-dontnote kotlin.**
-dontwarn kotlin.**
-keepclassmembernames class kotlinx.** {
volatile <fields>;
}
-dontnote kotlinx.**
-keep class kotlinx.coroutines.**
# retrofit
@swarawan
swarawan / pre-push
Last active March 1, 2021 03:45
Git pre-commit hook to run maven test
echo "========== Hook: Run Maven Test =========="
# run maven test
mvn clean test
if [ $? -ne 0 ]; then
echo "========= Hook: Error While Testing The Code =========="
exit 1
fi
@swarawan
swarawan / BalanceBrackets.java
Created February 2, 2024 08:17
Balance Brackets
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class BalanceBrackets {
public static void main(String[] args) {
String message = "([])(){}(())()()";
String message2 = "()()[{()})]";
String message3 = "[(])";