Skip to content

Instantly share code, notes, and snippets.

View amsokol's full-sized avatar

Aleksandr Sokolovskii amsokol

View GitHub Profile
@amsokol
amsokol / mutex-ex.go
Created January 25, 2019 14:02
mutex-ex.go
package importer
type MutexEx struct {
c chan bool
}
func (m *MutexEx) Lock() {
<-m.c
}
@amsokol
amsokol / flutter-grpc-tutorial.flutter_client.lib.bandwidth_buffer.dart
Last active January 14, 2019 08:33
flutter-grpc-tutorial.flutter_client.lib.bandwidth_buffer.dart
import 'dart:async';
class BandwidthBuffer<T> {
final Duration duration;
final void Function(List<T>) onReceive;
List<T> _list = <T>[];
Timer _timer;
BandwidthBuffer({this.duration, this.onReceive});
@amsokol
amsokol / flutter-grpc-tutorial.flutter_client.lib.chat_screen.dart
Created January 13, 2019 15:27
flutter-grpc-tutorial.flutter_client.lib.chat_screen.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'bandwidth_buffer.dart';
import 'chat_message.dart';
import 'chat_message_incoming.dart';
import 'chat_message_outgoing.dart';
import 'chat_service.dart';
@amsokol
amsokol / flutter-grpc-tutorial.flutter_client.lib.chat_service.dart
Last active January 13, 2019 17:18
flutter-grpc-tutorial.flutter_client.lib.chat_service.dart
import 'package:grpc/grpc.dart';
import 'api/v1/chat.pbgrpc.dart' as grpc;
import 'api/v1/google/protobuf/empty.pb.dart';
import 'api/v1/google/protobuf/wrappers.pb.dart';
import 'chat_message.dart';
import 'chat_message_outgoing.dart';
/// CHANGE TO IP ADDRESS OF YOUR SERVER IF IT IS NECESSARY
const serverIP = "127.0.0.1";
@amsokol
amsokol / flutter-grpc-tutorial.flutter_client.lib.chat_message_outgoing.dart
Last active January 13, 2019 13:47
flutter-grpc-tutorial.flutter_client.lib.chat_message_outgoing.dart
import 'package:flutter/material.dart';
import 'chat_message.dart';
/// Outgoing message author name
const String _name = "Me";
/// Outgoing message statuses
/// UNKNOWN - message just created and is not sent yet
/// SENT - message is sent to the server successfully
@amsokol
amsokol / flutter-grpc-tutorial.flutter_client.lib.chat_message_incoming.dart
Created January 13, 2019 13:13
flutter-grpc-tutorial.flutter_client.lib.chat_message_incoming.dart
import 'package:flutter/material.dart';
import 'chat_message.dart';
/// Incoming message author name
const String _server = "Server";
/// ChatMessageIncoming is widget to display incoming from server message
class ChatMessageIncoming extends StatelessWidget implements ChatMessage {
/// Incoming message content
@amsokol
amsokol / flutter-grpc-tutorial.flutter_client.lib.chat_message.dart
Last active January 13, 2019 13:29
flutter-grpc-tutorial.flutter_client.lib.chat_message.dart
import 'package:flutter/material.dart';
import 'package:uuid/uuid.dart';
/// Message is class defining message data (id and text)
class Message {
/// _uuid is unique ID generator
static var _uuid = Uuid();
/// id is unique ID of message
String id;
@amsokol
amsokol / flutter-grpc-tutorial.flutter_client.lib.app.dart
Created January 13, 2019 12:46
flutter-grpc-tutorial.flutter_client.lib.app.dart
import 'package:flutter/material.dart';
import 'chat_screen.dart';
/// FriendlychatApp is Flutter application
class FriendlychatApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Friendlychat",
@amsokol
amsokol / flutter-grpc-tutorial.flutter_client.lib.main.dart
Created January 13, 2019 12:43
flutter-grpc-tutorial.flutter_client.lib.main.dart
import 'package:flutter/material.dart';
import 'app.dart';
/// main is entry point of Flutter application
void main() {
runApp(FriendlychatApp());
}
@amsokol
amsokol / flutter-grpc-tutorial.go-server.cmd.server.main.go
Created January 13, 2019 10:08
flutter-grpc-tutorial.go-server.cmd.server.main.go
package main
import (
"context"
"fmt"
"os"
"github.com/amsokol/flutter-grpc-tutorial/go-server/pkg/protocol/grpc"
"github.com/amsokol/flutter-grpc-tutorial/go-server/pkg/service/v1"
)