Skip to content

Instantly share code, notes, and snippets.

View addeeandra's full-sized avatar
🧭
I am, therefore I am.

Aditya Chandra addeeandra

🧭
I am, therefore I am.
View GitHub Profile
@addeeandra
addeeandra / PartRequest.kt
Created November 18, 2020 17:16
A snippet code to build MultipartBody.Part easily.
object PartRequest {
@JvmStatic
fun buildFileBody(file: File): RequestBody {
return RequestBody.create(MediaType.parse("image/jpg"), file)
}
@JvmStatic
fun buildTextBody(value: String): RequestBody {
return RequestBody.create(MediaType.parse("text/plain"), value)
@addeeandra
addeeandra / dockerinfo.sh
Created July 31, 2020 17:56
Linux utility stuffs.
#/bin/bash
GREEN='\033[1;32m'
WHITE='\033[1;38m'
NC='\033[0m'
# Getting common docker information
# - Container(s) information
# - Default Network (bridge) information
# - Available Images(s) information
@addeeandra
addeeandra / gitairhooks.php
Last active July 27, 2020 04:55
Git Kanban to Airtable Basic Hooks
<?php
/**
* Host this code on a server and point your github webhooks to this file.
* it's a single directional API for Github to Airtable. It excludes the Airtable to Github.
*
* What to prepare?
* 1. Make an airtable Base,
* 2. Make a special table on airtable for Github Kanban (ex. Report),
* 3. Enable 'project' on Github to get the Kanban view,
@addeeandra
addeeandra / ButtonWithShadow.kt
Created May 22, 2020 12:18
Button with Shadow. What else?
import android.content.Context
import android.graphics.BlurMaskFilter
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.widget.TextView
class ButtonWithShadow : TextView {
@addeeandra
addeeandra / CombinedTransformation.kt
Created May 14, 2020 14:19
Combined Transformation of LiveData(s) using MediatorLiveData
class CombinedTransformation<T>(
vararg liveData: LiveData<*>,
private val onAllChanged: (data: List<Any?>) -> T
) : MediatorLiveData<T>() {
private val mLiveDataList: MutableList<Any?> = MutableList(liveData.size) { null }
init {
liveData.forEachIndexed { index, liveDatum ->
super.addSource(liveDatum) { datum ->
@addeeandra
addeeandra / AppPagedRecyclerViewAdapter.kt
Last active June 7, 2021 05:43
Simple (Paged) RecyclerViewAdapter
abstract class AppPagedRecyclerViewAdapter<BIND : ViewDataBinding, M : Any>(
diffUtil: DiffUtil.ItemCallback<M>
) : PagedListAdapter<M, AppPagedRecyclerViewAdapter.ViewHolder<BIND>>(diffUtil) {
abstract fun onCreateViewBindingHolder(inflater: LayoutInflater, parent: ViewGroup): BIND
abstract fun onPrepareBindViewHolder(binding: BIND, model: M)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder<BIND> {
val inflater = LayoutInflater.from(parent.context)
@addeeandra
addeeandra / APIManager.java
Created April 22, 2020 13:36 — forked from sideffect0/APIManager.java
Retrofit Client with Persistent Cookie
class APIManager {
// client with persistent Cookie
public static OkHttpClient getRetrofitClient(final Context context) {
OkHttpClient client = new OkHttpClient();
CookieManager cookieManager = new CookieManager(new PersistentCookieStore(context), CookiePolicy.ACCEPT_ALL);
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
client.setCookieHandler(cookieManager);
return client;
}
@addeeandra
addeeandra / Validator.kt
Last active April 23, 2020 15:33
Fields Validator (idea)
class Validator {
companion object {
val EMAIL_REGEX =
Regex("(?:[a-z0-9!#\$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#\$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])")
val NUMBER_REGEX = Regex("^[0-9]+$")
}
enum class Field {
@addeeandra
addeeandra / covid19map.html
Created April 13, 2020 14:14
Experiment with covid19api + Google Map
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Covid19 Cases in Countries</title>
</head>
<body style="padding: 0; margin: 0;">
<!-- Peta -->
@addeeandra
addeeandra / DatePickerBindingAdapter.kt
Last active October 21, 2022 09:16
Binding Adapter of Spinner, DatePicker, View, TextView, RecyclerView and SwipeRefreshLayout
import android.widget.DatePicker
import android.widget.Spinner
import androidx.databinding.BindingAdapter
import androidx.databinding.InverseBindingAdapter
import androidx.databinding.InverseBindingListener
import java.util.*
@BindingAdapter(value = ["selectedDate", "selectedDateAttrChanged"], requireAll = false)
fun DatePicker.selectedDate(
newSelectedDate: Date?,