This file contains hidden or 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
| fun EditText.maxLength(length: Int?): InputFilter.LengthFilter? { | |
| if (length == null) { | |
| filters = filters.filter { it !is InputFilter.LengthFilter }.toTypedArray() | |
| return null | |
| } | |
| val lengthFilter = InputFilter.LengthFilter(length) | |
| filters = filters.filter { it !is InputFilter.LengthFilter } | |
| .toMutableList() | |
| .apply { add(lengthFilter) }.toTypedArray() |
This file contains hidden or 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
| class EmptyAttributeSet : AttributeSet { | |
| override fun getAttributeCount(): Int = 0 | |
| override fun getAttributeName(index: Int): String? = null | |
| override fun getAttributeValue(index: Int): String? = null | |
| override fun getAttributeValue(namespace: String?, name: String?): String? = null | |
| override fun getPositionDescription(): String? = null | |
| override fun getAttributeNameResource(index: Int): Int = 0 | |
| override fun getAttributeListValue( | |
| namespace: String?, | |
| attribute: String?, |
This file contains hidden or 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
| fun <T: Any> byAtomic(initialValue: T) = object : ReadWriteProperty<Any?, T> { | |
| val ref = AtomicReference(initialValue) | |
| override fun getValue(thisRef: Any?, property: KProperty<*>): T = ref.get() | |
| override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) = ref.set(value) | |
| } | |
| fun <T: Any?> byAtomic(initialValue: T? = null) = object : ReadWriteProperty<Any?, T?> { | |
| val ref = AtomicReference<T?>(initialValue) | |
| override fun getValue(thisRef: Any?, property: KProperty<*>): T? = ref.get() | |
| override fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) = ref.set(value) |
This file contains hidden or 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 'dart:async'; | |
| import 'dart:convert'; | |
| import 'package:http/http.dart' as http; | |
| Stream<Iterable<Map<String, dynamic>?>?> fetchGitHubRepos(String? url) async* { | |
| while (url != null) { | |
| print("$url"); | |
| final response = await http.get(Uri.parse(url)); | |
| if (response.statusCode == 200) { |
This file contains hidden or 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
| /// Weights of [0,0] anchor: | |
| /// | j j j j j | |
| /// | 0 1 2 3 4 | |
| /// ----+----------- | |
| /// i 0 | 0 1 2 3 4 | |
| /// i 1 | 1 2 2 3 4 | |
| /// i 2 | 2 2 3 3 4 | |
| /// i 3 | 3 3 3 4 4 | |
| /// i 4 | 4 4 4 4 5 | |
| /// |
This file contains hidden or 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
| const Generator = Object.getPrototypeOf(function* () { }); | |
| Generator.prototype.map = function* (mapper) { | |
| for (const it of this) { | |
| yield mapper(it); | |
| } | |
| }; | |
| Generator.prototype.filter = function* (predicate) { | |
| for (const it of this) { | |
| if (predicate(it)) yield it; | |
| } |
This file contains hidden or 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
| /// | j j j j j | |
| /// | 0 1 2 3 4 < j-index | |
| /// ----+----------- round-th | |
| /// i 0 | 0 1 2 3 4 round-0: [0,0] | |
| /// i 1 | 1 2 3 4 5 round-1: [0,1][1,0] | |
| /// i 2 | 2 3 4 5 6 round-2: [0,2][1,1][2,0] | |
| /// i 3 | 3 4 5 6 7 round-3: [0,3][1,2][2,1][3,0] | |
| /// i 4 | 4 5 6 7 8 round-4: [0,4][1,3][2,2][3,1][4,0] | |
| /// round-5: [1,4][2,3][3,2][4,1] | |
| /// round-6: [2,4][3,3][4,2] |
This file contains hidden or 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
| /** | |
| * Compatibility | |
| * | |
| * See Also: androidx.core.content.res.use | |
| */ | |
| @OptIn(ExperimentalContracts::class) | |
| inline fun <T: TypedArray, R> T.use(block: (T) -> R): R { | |
| contract { | |
| callsInPlace(block, InvocationKind.EXACTLY_ONCE) | |
| } |
This file contains hidden or 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
| extension FutureZipX<T> on Future<T> { | |
| Future<(T, T2)> zipWith<T2>(Future<T2> future2) async { | |
| late T result1; | |
| late T2 result2; | |
| await Future.wait( | |
| [then((it) => result1 = it), future2.then((it) => result2 = it)]); | |
| return (result1, result2); | |
| } | |
| } |
NewerOlder