Skip to content

Instantly share code, notes, and snippets.

@whalemare
whalemare / doctor.sh
Created April 29, 2019 09:00
React Native doctor that can solve your problems
#!/usr/bin/env bash
# If you dont know what happened just start this script for automatically trying solve your problem.
# Clear all your build folders and dependencies.
# Install dependencies again
platform=$1
platform=$(echo "$platform" | tr '[:upper:]' '[:lower:]') # to lower string
echo "Moving to the root project folder"
@whalemare
whalemare / remote_url.md
Created April 15, 2019 13:42 — forked from hofnerb/remote_url.md
git remote set-url

Review and Change Remote URL

git remote -v
# View existing remotes

git remote set-url origin https://github.com/user/repo2.git
# Change the 'origin' remote's URL

git remote add origin https://github.com/user/repo2.git
@whalemare
whalemare / IxKotlin.kt
Created February 14, 2019 02:59 — forked from acrylic-origami/IxKotlin.kt
Rx operator implementations from the five major classes outlined in https://lam.io/writing/ReactiveX using Kotlin reactive channels
import kotlin.collections.*
import org.reactivestreams.*
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.reactive.*
import kotlinx.coroutines.*
import kotlin.coroutines.*
@ExperimentalCoroutinesApi
fun <T, U> Publisher<T>.debounce(timeout: Long, ctx: CoroutineContext) = GlobalScope.publish(ctx) {
var idx = 0;
fun TextView.onTextChanged(handler: (text: CharSequence) -> Unit): TextWatcher {
val watcher = object : TextWatcher {
override fun afterTextChanged(editable: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(text: CharSequence?, p1: Int, p2: Int, p3: Int) {
editSearch.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(editable: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(charSequence: CharSequence?, p1: Int, p2: Int, p3: Int) {
val text = charSequence?.toString() ?: ""
@whalemare
whalemare / WindowExt.kt
Created October 9, 2018 03:06
Android set status bar light
@TargetApi(Build.VERSION_CODES.M)
fun Window.setLightStatusBar(light: Boolean) {
var flags = decorView.systemUiVisibility
if (light && (flags and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR == View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)) {
return
} else if (!light && (flags and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) != View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) {
return
}
@whalemare
whalemare / ImageUtils.kt
Created April 14, 2018 08:47
Find image in urls by size ImageView
import kotlin.math.abs
/**
* @since 2018
* @author Anton Vlasov - whalemare
*/
object ImageUtils {
/**
* Choose prefer image size by map entry set.
* @param height your avatar holder height in px
@whalemare
whalemare / AttrsDelegate.java
Last active February 19, 2018 04:13
AttrsDelegate that can simply retrieve attrs for your custom widget
/**
* Helper in work with custom attributes on some widget
* <p>
* Just pass to this attributeSet from your widget constructor and {@link StyleableRes}
*
* @author Anton Vlasov - whalemare
* @since 2017
*/
public class AttrsDelegate {
@whalemare
whalemare / CalendarEventDelegate.kt
Created January 22, 2018 08:46
CalendarEventDelegate for create intent for pass it to app
/**
* Add event to calendars using pretty api
* @since 2018
* @author Anton Vlasov - whalemare
*/
class CalendarEventDelegate {
var title = ""
var description = ""
var startMillis = Long.MIN_VALUE
class TimberLinkingTree : Timber.Tree() {
private val CALL_STACK_INDEX = 4
private val ANONYMOUS_CLASS = Pattern.compile("(\\$\\d+)+$")
override fun log(priority: Int, tag: String, message: String, t: Throwable) {
val stackTrace = Throwable().stackTrace
if (stackTrace.size <= CALL_STACK_INDEX) {
throw IllegalStateException(
"Synthetic stacktrace didn't have enough elements: are you using proguard?")
}