Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Alashov Berkeli alashow

🏠
Working from home
Block or report user

Report or block alashow

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View AppBarLifListeners.kt
// activity
private val onAppBarLiftListeners = HashSet<AppBarLiftListener>()
val appBar = findViewById<AppBarLayout>(R.id.appBar)
if (appBar != null) {
appBar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
onAppBarLiftListeners.forEach { it.onAppBarLift(verticalOffset) }
})
}
@alashow
alashow / DateTimePickerLocalizer.kt
Created May 4, 2019
Android Localize months in DatePickerDialog or am/pm in TimePickerDialog
View DateTimePickerLocalizer.kt
import timber.log.Timber
/**
* Patch date picker or time picker to use custom months or am/pm
* From: https://stackoverflow.com/a/33599403/2897341
*
* @param picker [android.widget.DatePicker] or [android.widget.TimePicker]
* @param values months or am/pm
*/
fun localizePicker(picker: Any, values: Array<String>) {
@alashow
alashow / CalendarDateRange.kt
Created Apr 17, 2019
Kotlin Calendar/Date utils
View CalendarDateRange.kt
import java.util.Calendar
import java.util.Date
class CalendarRange(override val start: Calendar, override val endInclusive: Calendar, val field: Int = Calendar.DAY_OF_YEAR) :
ClosedRange<Calendar>, Iterable<Calendar> {
override fun iterator(): Iterator<Calendar> {
return CalendarIterator(start, endInclusive, field)
}
}
@alashow
alashow / AppViewModelFactory.kt
Last active Apr 1, 2019
ViewModel dynamic parameters hack
View AppViewModelFactory.kt
class AppViewModelFactory @Inject constructor(
private val creators: @JvmSuppressWildcards Map<Class<out ViewModel>, Provider<ViewModel>>
) : ViewModelProvider.Factory {
var onViewModelCreate: ((viewModel: ViewModel) -> Unit)? = null
override fun <T : ViewModel> create(modelClass: Class<T>): T {
var creator: Provider<out ViewModel>? = creators[modelClass]
if (creator == null) {
for ((key, value) in creators) {
View BaseActivity.kt
package tm.alashow.x.ui.base
import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProvider
import android.arch.lifecycle.ViewModelProviders
import android.databinding.DataBindingUtil
import android.databinding.ViewDataBinding
import android.os.Bundle
import android.support.annotation.LayoutRes
import android.support.annotation.StringRes
@alashow
alashow / Fibonacci.kt
Created Oct 2, 2017
Fibonacci in Kotlin
View Fibonacci.kt
package tm.alashow.homework.datastructures.second.kt
import java.math.BigInteger
fun main(args: Array<String>) {
Fibonacci.init()
}
object Fibonacci {
@alashow
alashow / Fibonacci.java
Last active Oct 2, 2017
Fibonacci in Java using tail call.
View Fibonacci.java
package tm.alashow.homework.datastructures.second;
import java.util.Locale;
import java.util.Scanner;
/**
* Created by alashov on 10/1/17.
*/
public class Fibonacci {
View fix_permissions.sh
# run in "root" folder (e.g /home/datmusic/api.datmusic.xyz/)
chown -R datmusic:www-data storage .env
find storage -type f -exec chmod 664 {} \;
find storage -type d -exec chmod 775 {} \;
chgrp -R www-data storage .env
chmod -R ug+rwx storage .env
View U.java
/**
* Part of my utils class that I use in my apps.
* Contains only functions related to showing snackbars and toasts.
* Some string/resources are missing in this gist. Names of resources are self explanatory. Hence, it shouldn't be hard to define it in your resources.
*/
public class U {
public static float density = 1;
public static final int SNACK_DEFAULT = 0;
View ImageUtils.java
/*
* Copyright (c) 2016 Alashov Berkeli
* It is licensed under GNU GPL v. 2 or later. For full terms see the file LICENSE.
*/
package tm.asmanoky.aziada.util.glide;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
You can’t perform that action at this time.