Skip to content

Instantly share code, notes, and snippets.

View nsmirosh's full-sized avatar

Nikolay Miroshnychenko nsmirosh

View GitHub Profile
@nsmirosh
nsmirosh / git_log_formatter.py
Created September 2, 2021 10:19
Python program that parses the git log output and writes the formmatted output to a separate file
import re
first_message_index = 4
step_index = 6
def get_first_alphabetic_character_pos(s):
m = re.search(r'[a-z]', s, re.I)
if m is not None:
return m.start()
return 0
@nsmirosh
nsmirosh / test_task_solution_live_coding.kt
Created March 3, 2021 18:17
my solution to the task during live coding
data class User(val id: String, val nickname: String)
data class Message(val id: String, val message: String?, val user: User)
val users = listOf(
User("000", "Bender"),
User("001", "Leela"),
User("002", "Fry"),
User("003", "Zoidberg")
)
data class User(val id: String, val nickname: String)
data class Message(val id: String, val message: String?, val user: User)
val users = listOf(
User("000", "Bender"),
User("001", "Leela"),
User("002", "Fry"),
User("003", "Zoidberg")
)
@nsmirosh
nsmirosh / stream_controller_callbacks.dart
Created November 7, 2020 18:40
StreamController callbacks example
import 'dart:async';
void main() async {
final subscription = numberStreamWithController(8)
.listen((event) => print("received $event"));
await Future.delayed(Duration(seconds: 3));
print("idling for 2 seconds");
subscription.pause();
@nsmirosh
nsmirosh / future_builder_example.dart
Last active August 19, 2020 10:07
FutureBuilder example
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(body: MyStatefulWidget()),
);
@nsmirosh
nsmirosh / future_error_handling.dart
Last active August 17, 2020 15:19
Future error handling with catchError and whenComplete
void main() {
Future.delayed(Duration(seconds: 1), () => throw 'Boom!')
.catchError(
(e) => print('error we caught: $e'),
)
.whenComplete(() =>
print('doing something regardless of what happened previously'));
}
@nsmirosh
nsmirosh / await_error.dart
Last active August 17, 2020 20:14
Future error handling with the await
void main() async {
try {
await Future.delayed(Duration(seconds: 1), () => throw 'Boom!');
} catch (e) {
print('error we caught: $e');
} finally {
print('doing something regardless of what happened previously');
}
}
@nsmirosh
nsmirosh / future_with_then.dart
Last active August 15, 2020 12:28
Future with then and showing a null return type
void main() {
final myFuture = _runTheFuture();
print('myFuture.runtimeType: ${myFuture.runtimeType}');
}
_runTheFuture() {
print('print statement before invoking the future');
Future.delayed(Duration(seconds: 2), () {
print('Future completed!');
@nsmirosh
nsmirosh / await_demo.dart
Last active August 15, 2020 11:59
Dart's await demo
void main() async {
final myFuture = _runTheFuture();
print('myFuture.runtimeType: ${myFuture.runtimeType}');
}
_runTheFuture() async {
print('print statement before invoking the future');
final myValue = await Future.delayed(Duration(seconds: 2), () {
print('Future completed!');
@nsmirosh
nsmirosh / event_loop_demo.dart
Last active August 14, 2020 14:50
event loop process demonstration
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: RaisedButton(