Skip to content

Instantly share code, notes, and snippets.

View swarawan's full-sized avatar

Rio Swarawan Putra swarawan

  • Jakarta, Indonesia
View GitHub Profile
@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 = "[(])";
@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 / 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 / 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 / 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",
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")
x = 10
y = 5
10 + 5 = 15
10 - 5 = 5
10 * 5 = 50
10 / 5 = 2
syaratnya:
- gunakan data class untuk menyimpan nilai x dan y
@swarawan
swarawan / delete_git_submodule.md
Created September 13, 2018 09:42 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
apply plugin: 'maven-publish'
publishing {
publications {
aar(MavenPublication) {
setGroupId 'com.swarawan'
artifactId project.getName()
version libraryVersion
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
@swarawan
swarawan / NetworkUtils
Created March 13, 2018 12:51
Use this class to check connection availability
public class NetworkUtils {
private static boolean isConnected;
public NetworkUtils(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager == null) return;
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();