Skip to content

Instantly share code, notes, and snippets.

View andhikayuana's full-sized avatar
🌏
bertapa

Andhika Yuana andhikayuana

🌏
bertapa
View GitHub Profile
@andhikayuana
andhikayuana / write-fixer.py
Created April 18, 2024 03:18 — forked from ahmadrosid/write-fixer.py
Fixed typos, spelling mistakes, and grammar while maintaining clarity and a concise tone using Claude.
import sys
import anthropic
from dotenv import load_dotenv
load_dotenv()
client = anthropic.Anthropic()
prompt_template = """
Please review and edit the following text to ensure it is grammatically correct, clear, and concise. Aim to maintain a casual tone without being overly informal. Provide suggestions for improvement and explain any changes you make. Do not add double quotes in you rewrite answer. Answer in direct response.
@andhikayuana
andhikayuana / JsonRpc.kt
Created February 23, 2024 06:51 — forked from ntoskrnl/JsonRpc.kt
Retrofit-style JSON-RPC client in Kotlin (with gson serialization/deserialization)
fun <T, B> createJsonRpcService(service: Class<T>,
client: JsonRpcClient<B>,
resultDeserializer: Deserializer<B>,
logger: (String) -> Unit = {}): T {
val classLoader = service.classLoader
val interfaces = arrayOf<Class<*>>(service)
val invocationHandler = createInvocationHandler(service, client, resultDeserializer, logger)
@Suppress("UNCHECKED_CAST")
@andhikayuana
andhikayuana / working_effectively_with_legacy_code.md
Created November 30, 2023 08:09 — forked from jonnyjava/working_effectively_with_legacy_code.md
Working effectively with legacy code summary

WORKING EFFECTIVELY WITH LEGACY CODE

To me, legacy code is simply code without tests. I’ve gotten some grief for this definition. What do tests have to do with whether code is bad? To me, the answer is straightforward, and it is a point that I elaborate throughout the book: Code without tests is bad code. It doesn’t matter how well written it is; it doesn’t matter how pretty or object-oriented or well-encapsulated it is. With tests, we can change the behavior of our code quickly and verifiably. Without them, we really don’t know if our code is getting better or worse.

Chapter 1 Changing Software

Four Reasons to Change Software: For simplicity’s sake, let’s look at four primary reasons to change software.

import org.junit.Test;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Scheduler;
import rx.functions.Func1;
import rx.observers.AssertableSubscriber;
import rx.schedulers.TestScheduler;
@andhikayuana
andhikayuana / android-send-push-locally-using-adb.adoc
Created August 21, 2023 02:40 — forked from tolpp/android-send-push-locally-using-adb.adoc
This gist explains how to send push notification locally using ADB without need network connection.

Requirements:

  • Device should be a rooted (simulator’s are rooted by default)

  • adbd should be started as root. (Rub command: adb root )

Now, send local push message using command:

@andhikayuana
andhikayuana / BranchNetworkClient.java
Created July 24, 2023 08:53 — forked from elroid/BranchNetworkClient.java
BranchRemoteInterface using OkHttp3
import org.json.JSONObject;
import java.io.IOException;
import io.branch.referral.network.BranchRemoteInterface;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
@andhikayuana
andhikayuana / gist:4b5e1c4c94760d3ff44e478e527c18be
Created July 24, 2023 08:44 — forked from patrickhammond/gist:0b13ec35160af758d98c
Sample for how to use the Google Play Services dynamic security provider to keep the SSL library that the app will use to up date.
package com.mycompany.myapp.app;
import android.app.Application;
import android.content.Intent;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.security.ProviderInstaller;
import com.google.android.gms.security.ProviderInstaller.ProviderInstallListener;
public class MainApplication extends Application {
@andhikayuana
andhikayuana / MainActivity.java
Created July 12, 2023 06:33 — forked from rafaeltoledo/MainActivity.java
Intercept Autolinks in TextView
package net.rafaeltoledo.autolinks;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.text.SpannableString;
import android.text.style.URLSpan;
import android.util.Log;
import android.view.View;
@andhikayuana
andhikayuana / process.kt
Created July 10, 2023 03:54 — forked from seanf/process.kt
Execute process from Kotlin
import java.lang.ProcessBuilder.Redirect
import java.util.concurrent.TimeUnit
fun String.runCommand(workingDir: File? = null) {
val process = ProcessBuilder(*split(" ").toTypedArray())
.directory(workingDir)
.redirectOutput(Redirect.INHERIT)
.redirectError(Redirect.INHERIT)
.start()
if (!process.waitFor(10, TimeUnit.SECONDS)) {
@andhikayuana
andhikayuana / RealPathUtil.java
Created January 8, 2023 07:59 — forked from tatocaster/RealPathUtil.java
Real Path Utility class for Android, works for all API
public class RealPathUtil {
public static String getRealPath(Context context, Uri fileUri) {
String realPath;
// SDK < API11
if (Build.VERSION.SDK_INT < 11) {
realPath = RealPathUtil.getRealPathFromURI_BelowAPI11(context, fileUri);
}
// SDK >= 11 && SDK < 19
else if (Build.VERSION.SDK_INT < 19) {