Skip to content

Instantly share code, notes, and snippets.

Avatar

Rio Swarawan Putra swarawan

View GitHub Profile
@swarawan
swarawan / proguard-rules.pro
Created Jan 6, 2021
Android Proguard (kotlin, retrofit, okhttp, gson)
View proguard-rules.pro
# 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 Jan 1, 2021
General Recycler View Adapter
View DiffCallback.kt
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 Mar 1, 2021
Git pre-commit hook to run maven test
View pre-push
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 Mar 18, 2020
Multithread in Java
View BookAgent.kt
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",
View Simple Calculator Using Higher-Order Function
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")
View Soal Binar: Data Class + Extension
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 Sep 13, 2018 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.
View delete_git_submodule.md

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
View publish.gradle
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 Mar 13, 2018
Use this class to check connection availability
View NetworkUtils
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();
View Latihan Kalkulator
Kalkulator
Nilai 1 : <inputA> // 5
Nilai 2 : <inputB> // 2
Pilih Operator:
1. Tambah
2. Kurang
3. Kali
4. Bagi
Pilihan (1..4) : <inputOperator> // 1