This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.room.TypeConverters | |
import java.util.* | |
class FieldConverters { | |
@TypeConverters | |
fun fromTimestamp(value: Long?): Date? { | |
return value?.let { Date(it) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
OlderNewer