Skip to content

Instantly share code, notes, and snippets.

View gladimdim's full-sized avatar
💭
Unreal Engine

Dmytro Gladkyi gladimdim

💭
Unreal Engine
View GitHub Profile
@gladimdim
gladimdim / circular_progress_animated.dart
Created February 15, 2022 13:13
Circular progress bar with animations
import 'package:flutter/material.dart';
import 'dart:math' as Math;
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@gladimdim
gladimdim / isolates.dart
Created February 9, 2022 12:09
Isolates emiting numbers and another stream sums them
import 'dart:async';
import 'dart:collection';
import 'dart:isolate';
import 'package:rxdart/rxdart.dart';
void main() async {
await sumTwoLists();
print("done");
}
@gladimdim
gladimdim / list_extension.dart
Created January 4, 2022 13:47
List Extensions
import 'dart:math';
extension Divide<T> on List<T> {
List<List<T>> divideBy(int number) {
List<T> list = this;
List<List<T>> result = [];
while (list.isNotEmpty) {
result.add([...list.take(number)]);
try {
list = list.sublist(number);
class JsonParserIsolate {
final String input;
JsonParserIsolate(this.input);
Future parseJson({Function(String)? onError}) async {
final completer = Completer();
var port = ReceivePort();
var errorPort = ReceivePort();
/// https://www.hackerrank.com/challenges/pairs/problem
int findPairs(List<int> pairs, int diff) {
var counter = 0;
// save all values into Set
Set map = {};
for (var el in pairs) {
map.add(el);
// use math to determine if there is a value as difference between value and diff
if (map.contains(el - diff)) {
/// https://www.hackerrank.com/challenges/gem-stones/problem
///
/// There is a collection of rocks where each rock has various minerals embedded in it. Each type of mineral is designated by a lowercase letter in the range .
/// There may be multiple occurrences of a mineral in a rock. A mineral is called a gemstone if it occurs at least once in each of the rocks in the collection.
///
int calcGemStones(List<String> input) {
var map = {};
// go over the input collection and calculate amount of string where the character is present
// In order not to count "aaa" as three times we maintain ignoreSet set
/// Given a pointer to the head of a linked list and a specific position, determine the data value at that position. Count backwards from the tail node. The tail is at postion 0, its parent is at 1 and so on.
/// https://www.hackerrank.com/challenges/get-the-value-of-the-node-at-a-specific-position-from-the-tail
int? findNthElementInList(Node? head, int n) {
var current = head;
var counter = 0;
Node? result = head;
while (current != null) {
// when we processed nth element in list let's move result pointer to its next object
if (counter > n) {
result = result!.next;
/// You are given a string containing characters and only. Your task is to change it into a string such that there are no matching adjacent characters. To do this, you are allowed to delete zero or more characters in the string.
//
// Your task is to find the minimum number of required deletions.
// https://www.hackerrank.com/challenges/alternating-characters
int alternateCharactersLoop(String input) {
if (input.isEmpty) {
return 0;
}
var first = input[0];
class Node<T> {
T value;
Node<T>? next;
Node(this.value, [this.next]);
}
/// Given pointers to the heads of two sorted linked lists, merge them into a single, sorted linked list. Either head pointer may be null meaning that the corresponding list is empty.
/// https://www.hackerrank.com/challenges/merge-two-sorted-linked-lists/
Node? mergeTwoLists(Node? l1, Node? l2) {
// import 'package:cli/linked_list.dart';
/// https://www.hackerrank.com/challenges/compare-two-linked-lists/
/// Compare two linked lists
int equalLinkedLists(Node a, Node b) {
Node? f1 = a;
Node? f2 = b;
while (true) {
if (f1 == null || f2 == null) {
return f1 == f2 ? 1 : 0;
}