Skip to content

Instantly share code, notes, and snippets.

View fathonyfath's full-sized avatar
💻
Now you can also bring your work status here

Fathony Teguh Irawan fathonyfath

💻
Now you can also bring your work status here
  • Nowhere
View GitHub Profile
@fathonyfath
fathonyfath / main.zig
Last active November 16, 2023 05:33
Zig implementation of singly linked list.
const std = @import("std");
const Allocator = std.mem.Allocator;
pub const LinkedList = struct {
head: ?*Node,
tail: ?*Node,
count: usize,
allocator: Allocator,
const Node = struct {
@fathonyfath
fathonyfath / SampleFragment.kt
Last active September 24, 2023 07:06
An implementation of saved state registry that automatically register the value so it is easier to use on Activity and Fragment
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.fragment.app.Fragment
class SampleFragment : Fragment(R.layout.fragment_sample) {
private lateinit var countLabel: TextView
private lateinit var decrement: Button
@fathonyfath
fathonyfath / content.md
Created January 28, 2023 03:10
Hugo template to create complex table. Has `caption`, `tfoot`, and `colgroup` HTML feature.

{{< create-table src="my-table" >}}

#!/bin/sh
check_ffmpeg() {
# Check if the `ffmpeg` command is available
if which ffmpeg >/dev/null; then
# If `ffmpeg` is available, return 0
return 0
else
# If `ffmpeg` is not available, return 1
return 1
@fathonyfath
fathonyfath / MockInvocationHandler.kt
Created August 21, 2021 16:34
Simplified mock library
package id.thony.mockbyreflection
import java.lang.reflect.InvocationHandler
import java.lang.reflect.Method
class MockInvocationHandler : InvocationHandler {
override fun invoke(proxy: Any?, method: Method?, args: Array<out Any>?): Any {
method ?: throw IllegalStateException("method args is null")
val argsList = args?.toList() ?: emptyList()
@fathonyfath
fathonyfath / SimpleFrameLayout.kt
Created October 4, 2020 04:23
Simple FrameLayout implementation
package id.thony.customview
import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.view.ViewGroup
import androidx.core.view.children
class SimpleFrameLayout @JvmOverloads constructor(
@fathonyfath
fathonyfath / MainActivity.kt
Last active September 10, 2020 08:51
Simple example difference between multithreaded vs non-multithreaded code
package id.thony.examplethread
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
@fathonyfath
fathonyfath / build.gradle
Created September 8, 2019 08:48
Snippets that you can use to deploy stand-alone Java application
def mainClassName = 'sample.app.AppKt'
def embeddedJRE = true
jar {
manifest {
attributes(
'Main-Class': mainClassName,
'Class-Path': configurations.default.collect { it.getName() }.join(' ')
)
}
@fathonyfath
fathonyfath / PrimitiveConverterFactory.java
Created January 30, 2016 02:09
Converter factory for Retrofit 2 which is convert response to primitive type class such as Integer, Float, Double, Boolean, etc. For now there are only String, Integer, Double, and Boolean converter. You can expand it by yourself easily.
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;
/**
* Created by bradhawk on 1/29/2016.