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 requests | |
ids = [1, 2, 3, 4, 5, 6] | |
frs = {} | |
for id in ids: | |
r = requests.get('https://api.vk.com/method/friends.get', {'user_id': id}) | |
frs.update({id: r.json()['response']}) | |
print(r) |
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 getString(): String { | |
null?.let { return "fish" } | |
} | |
fun main() { | |
println(getString().length) | |
} |
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 urllib.request | |
import json | |
import os | |
import datetime | |
dumps_dir = 'github dumps {}'.format(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) | |
os.makedirs(dumps_dir, exist_ok=True) | |
response = urllib.request.urlopen("https://api.github.com/users/qwert2603/repos?per_page=9000") | |
response_string = response.read().decode("utf-8") |
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 'package:flutter/material.dart'; | |
import 'package:circular_reveal_animation/circular_reveal_animation.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'CRA Demo', |
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 androidx.lifecycle.ViewModel | |
import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.StateFlow | |
sealed class ViewModelStateFlow<T>(stateFlow: StateFlow<T>) : StateFlow<T> by stateFlow | |
private class ViewModelStateFlowImpl<T>( | |
initial: T, | |
val wrapped: MutableStateFlow<T> = MutableStateFlow(initial) | |
) : ViewModelStateFlow<T>(wrapped) |
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
protected class ViewModelStateFlowImpl<T>(initial: T) : ViewModelStateFlow<T> { | |
val wrapped = MutableStateFlow(initial) | |
override val value: T | |
get() = wrapped.value | |
override val replayCache: List<T> | |
get() = wrapped.replayCache | |
@InternalCoroutinesApi |
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 SomeViewModel : BaseViewModel() { | |
val flow = createViewModelStateFlow(0) | |
suspend fun load() { | |
flow.setValue(1) | |
delay(1000) | |
flow.setValue(flow.value + 1) | |
} | |
} |
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 SomeFragment { | |
private val vm = SomeViewModel() | |
fun onCreate() { | |
val currentValue: Int = vm.flow.value | |
// vm.flow.setValue(4) // compilation error | |
} | |
} |
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 main() { | |
val koin = startKoin { | |
val module1 = module { | |
declareMultibinding<String, Int>() | |
intoMultibinding("one", 1) | |
intoMultibinding("two", 2) | |
intoMultibinding("three", 3) | |
declareMultibinding<String, Double>() | |
intoMultibinding("one", 1.0) |
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
inline fun <reified K, reified V> Module.intoMultibinding(key: K, value: V) { | |
var multibinding: Multibinding<K, V>? = null | |
single( | |
qualifier = named("${K::class.getFullName()}_${V::class.getFullName()}_$key"), | |
createdAtStart = true, | |
) { | |
multibinding = get(multibindingQualifier<K, V>()) | |
multibinding!![key] = value | |
}.onClose { | |
multibinding?.remove(key) |