Skip to content

Instantly share code, notes, and snippets.

Łukasz Wiśniewski vishna

Block or report user

Report or block vishna

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 isolates_workaround.dart
import 'dart:async';
import 'package:flutter_driver/flutter_driver.dart';
/// Workaround for bug: https://github.com/flutter/flutter/issues/24703
///
/// USAGE
///
/// ```
/// FlutterDriver driver;
View repro_37852.sh
#!/bin/sh
# Makes the bash script to print out every command before it is executed except echo
trap '[[ $BASH_COMMAND != echo* ]] && echo $BASH_COMMAND' DEBUG
echo "Executing steps to repro issue #37852"
echo "https://github.com/flutter/flutter/issues/37852"
echo "MAKE SURE YOU'RE ON MASTER CHANNEL!"
echo "MAKE SURE YOU HAVE iOS SIMULATOR RUNNING"
View my_flutter_pubspec.yaml
name: my_flutter
description: A new flutter module project.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
@vishna
vishna / suspend_var.kt
Last active Jun 18, 2019
Suspened Variable in Kotlin - works kinda lateinit but if your variable is late, it will make you wait rather than crash
View suspend_var.kt
class SuspendedVariable<T>(var scope: CoroutineScope? = GlobalScope) {
private var actor = scope?.actor<Op<T>> {
var value : T? = null
val deferrals = mutableListOf<CompletableDeferred<T>>()
try {
for (message in channel) {
when (message) {
is Op.Set -> {
View suspend_var_actorless.kt
/**
* kinda like `lateinit var` but if it's really late it will make you wait rather than crash.
*/
class SuspendedVariable<T> {
private val callbacks = mutableListOf<((T) -> Unit)>()
private var value: T? = null
fun set(t: T) {
value = t
if (t != null) {
View MainActivity.kt
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
private const val tag = "2ndShare"
/**
* 1) Clear all the apps
* 2) Go to Google Photos, share image to this app
@vishna
vishna / doOnNextLayout.kt
Created Nov 23, 2018
View.doOnNextLayout
View doOnNextLayout.kt
// https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/core/ktx/src/main/java/androidx/core/view/View.kt
inline fun <T : View> T.doOnNextLayout(crossinline action: (view: T) -> Unit) {
addOnLayoutChangeListener(object : View.OnLayoutChangeListener {
override fun onLayoutChange(
view: View,
left: Int,
top: Int,
right: Int,
bottom: Int,
oldLeft: Int,
View better-safe-than-sorry.kt
inline fun <T> safe(block: () -> T?) : T? {
return try {
block.invoke()
} catch (t: Throwable) {
null // ¯\_(ツ)_/¯
}
}
@vishna
vishna / debounce-broadcast.kt
Created Nov 5, 2017
Debounce input from an EditText and relay to a TextView with a timeout.
View debounce-broadcast.kt
package me.vishna.kdebounce
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import android.widget.TextView
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.android.UI
@vishna
vishna / debounce-broadcast.kt
Created Nov 5, 2017
Debounce input from an EditText and relay to a TextView with a timeout.
View debounce-broadcast.kt
package me.vishna.kdebounce
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import android.widget.TextView
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.android.UI
You can’t perform that action at this time.