Skip to content

Instantly share code, notes, and snippets.

View yusuf-raza's full-sized avatar

Syed Yusuf Raza Zaidi yusuf-raza

View GitHub Profile
@yusuf-raza
yusuf-raza / queue_ds.dart
Created September 3, 2025 12:46
Queue datas structure with dart
//List to implement stack behavior (LIFO)
class Queue<T> {
final List<T> _items = [];
/// Adds an item to the back of the queue.
void enqueue(T item) => _items.add(item);
/// Removes and returns the item from the front of the queue.
/// Returns `null` if the queue is empty.
@yusuf-raza
yusuf-raza / gist:fd8ecb31253b1653272cb11a61952cd4
Last active September 3, 2025 12:40
Stack data structure with dart
//dart does not have bult in stack data type, so we will implement it with List
class Stack<T> {
final List<T> _items = [];
/// Pushes an item onto the top of the stack.
void push(T item) => _items.add(item);
/// Removes and returns the item at the top of the stack.
/// Returns `null` if the stack is empty.
@yusuf-raza
yusuf-raza / .dart
Created May 22, 2025 10:45
listening to app lifecycle in Flutter app without using WidgetsBindingObserver class
//declare AppLifeCyleListener
late final AppLifecycleListener _lifecycleListener;
//initialize AppLifeCycleListener
@override
void onInit() {
super.onInit();
_lifecycleListener = AppLifecycleListener(
onResume: () => debugPrint('app resumed'),
@yusuf-raza
yusuf-raza / .yaml
Created December 13, 2024 09:37
analysis_options
# Specify analysis options.
#
# For a list of lints, see: https://dart.dev/tools/linter-rules
# For guidelines on configuring static analysis, see:
# https://dart.dev/tools/analysis
#
# There are other similar analysis options files in the flutter repos,
# which should be kept in sync with this file:
#
# - analysis_options.yaml (this file)
@yusuf-raza
yusuf-raza / armstrong_numbers.dart
Created May 25, 2022 20:51
Armstrong Numbers - Excercism - Dart
import 'dart:math';
class ArmstrongNumbers {
bool isArmstrongNumber(int number) {
int userGivenNumber = number;
int temp = 0;
int totalDigits = 0;
int individualDigit = 0;
int sum = 0;
@yusuf-raza
yusuf-raza / reverse_string.dart
Created May 25, 2022 00:29
Reverse String - Excercism - Dart
String reverse(String inputString) {
String reversedString;
//using split() method to splt the string into characters
List<String> chars = inputString.split("");
//using .reversed.join() to joing the charaters to form a reversed string
reversedString = chars.reversed.join();
return reversedString;
}
@yusuf-raza
yusuf-raza / prime_factors.dart
Created May 25, 2022 00:27
Prime Factors - Excercism - Dart
class PrimeFactors {
List<int> result = [];
List<int> factors(int num) {
for (var i = 2; i < num; i++) {
if (num % i == 0) {
break;
} else {
result.add(i);
}
}
@yusuf-raza
yusuf-raza / leap.dart
Created May 25, 2022 00:26
Leap - Excercism - Dart
class Leap {
bool leapYear(int year) {
if (year % 4 == 0 && year % 400 == 0) {
return true;
} else {
return false;
}
}
}
@yusuf-raza
yusuf-raza / hello_world.dart
Created May 25, 2022 00:25
Hello World - Exercism - Dart
String helloWorld() {
return "Hello, World!";
}
@yusuf-raza
yusuf-raza / two_fer.dart
Created May 25, 2022 00:07
Two Fer - Exercism - Dart
String twoFer([String? name = null]) {
if (name == null) {
return 'One for you, one for me.';
} else {
return 'One for ' + name + ', one for me.';
}
}