Skip to content

Instantly share code, notes, and snippets.

View qwert2603's full-sized avatar

Alexander Zhdanov qwert2603

View GitHub Profile
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)
fun getString(): String {
null?.let { return "fish" }
}
fun main() {
println(getString().length)
}
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")
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',
@qwert2603
qwert2603 / BaseViewModel.kt
Last active September 7, 2022 11:09
ViewModelStateFlow
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)
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
class SomeViewModel : BaseViewModel() {
val flow = createViewModelStateFlow(0)
suspend fun load() {
flow.setValue(1)
delay(1000)
flow.setValue(flow.value + 1)
}
}
class SomeFragment {
private val vm = SomeViewModel()
fun onCreate() {
val currentValue: Int = vm.flow.value
// vm.flow.setValue(4) // compilation error
}
}
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)
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)