Skip to content

Instantly share code, notes, and snippets.

View addeeandra's full-sized avatar
🐣
Nothing happening

Aditya Chandra addeeandra

🐣
Nothing happening
View GitHub Profile
@addeeandra
addeeandra / crop-snippet.php
Last active October 31, 2017 04:49
Cropping image on PHP
<?php
# START CROPPING -- it just need 4 lines of code to crop an image
$img = imagecreatefromjpeg('assets/img/myimage.jpg');
$size = min(imagesx($img), imagesy($img));
$img_squared = imagecrop($img, [ 'x' => 0, 'y' => 0, 'width' => $size, 'height' => $size ]);
if ($img_squared !== false) ($img_squared, 'assets/img/myimage-squared.jpg', 80);
# END OF CROPPING -- read the explanation below
# READ MORE here http://php.net/manual/en/function.imagecrop.php
@addeeandra
addeeandra / ActivityExtensions.kt
Last active April 28, 2021 08:41
Kotlin Extensions of BottomNavigation, Calendar, EditText, View, InputStream, String, Context, Activity
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.ViewModelProvider
import android.app.Activity
import android.content.Intent
inline fun <reified T : Any> Activity.openAndFinish(extras: Intent.() -> Unit = {}) {
open<T>(extras)
finish()
@addeeandra
addeeandra / AnyAdapter.kt
Last active November 12, 2022 16:37
Android - Kotlin Easy Adapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
abstract class AnyAdapter<T>(val items: MutableList<T>) : RecyclerView.Adapter<AnyViewHolder<T>>() {
abstract fun getLayoutId(): Int
abstract fun onCreateViewHolder(view: View): AnyViewHolder<T>
@addeeandra
addeeandra / ConnectionService.kt
Last active December 10, 2019 01:03
Connection Check on Android - Available in 3 state - Disconnected, Connected (no internet), Connected (with internet)
import android.content.Context
import android.net.ConnectivityManager
import java.net.InetAddress
import java.net.UnknownHostException
class ConnectionService(context: Context) {
companion object {
private var mInstance: ConnectionService? = null
@addeeandra
addeeandra / FieldConverters.kt
Last active October 31, 2019 03:09
Example of @TypeConverters in Room Persistence Database
import androidx.room.TypeConverters
import java.util.*
class FieldConverters {
@TypeConverters
fun fromTimestamp(value: Long?): Date? {
return value?.let { Date(it) }
}
@addeeandra
addeeandra / btn_rounded_primary.xml
Created April 26, 2019 20:39
Button Rounded Primary - with selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/btn_rounded_primary_disabled"/>
<item android:state_pressed="true" android:drawable="@drawable/btn_rounded_primary_pressed"/>
<item android:drawable="@drawable/btn_rounded_primary_normal"/>
</selector>
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.ViewPager
import com.google.android.material.tabs.TabLayout
open class AnyFragmentPagerAdapter(
fm: FragmentManager,
private val mPages: List<AnyPagerableFragment>
) : FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Region
import android.os.Build
import android.util.AttributeSet
import android.view.View
class ClipBoxView(ctx: Context, attrs: AttributeSet) : View(ctx, attrs) {
@addeeandra
addeeandra / koman.sh
Last active April 11, 2020 11:13
Common PHP & Mysql Setup Command in Ubuntu
# in case u need it (common)
sudo apt-get install curl wget unzip
# install mysql
sudo apt-get install mysql-server
# setup mysql
sudo mysql_secure_installation
# Optional step - if mysql can't login using other users
@addeeandra
addeeandra / AnyViewModelHolder.kt
Last active December 27, 2019 11:58
ViewModel Utility Classes
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
open class BindingViewHolder<T, V : ViewDataBinding, L : BindingListener<T>>(
private val binding: V,
private val listener: L?
) : RecyclerView.ViewHolder(binding.root) {
fun bind(data: T) {
binding.setVariable(BR.viewmodel, data)