Skip to content

Instantly share code, notes, and snippets.

View hawkkiller's full-sized avatar
🎯
Focusing

Michael Lazebny hawkkiller

🎯
Focusing
View GitHub Profile
@hawkkiller
hawkkiller / global_key.dart
Created March 23, 2023 15:53
Dart global key showcase
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@hawkkiller
hawkkiller / cronjob.yaml
Created April 29, 2023 10:45
mysql backup to s3
{{ if .Values.mysql.backup.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ .Release.Name }}-mysql-backup
spec:
schedule: {{ .Values.mysql.backup.schedule | quote }}
jobTemplate:
spec:
ttlSecondsAfterFinished: {{ .Values.mysql.backup.ttlSecondsAfterFinished }}
@hawkkiller
hawkkiller / main.dart
Created June 28, 2023 19:53
Transformers
import 'dart:async';
final transformer = StreamTransformer<int, int>.fromHandlers(
handleData: (data, sink) {
print('transformed');
sink.add(data * 2); // For every data event, we double the value.
},
handleError: (error, stacktrace, sink) {
sink.addError('An error occurred: $error'); // We transform any error.
},
@hawkkiller
hawkkiller / main.dart
Last active July 8, 2023 12:33
Open-closed principle violation example
sealed class Shape {}
class Circle extends Shape {
Circle(this.radius);
final double radius;
}
class Rectangle extends Shape {
Rectangle(this.width, this.height);
@hawkkiller
hawkkiller / main.dart
Created July 8, 2023 13:58
Open-closed principle example
sealed class Shape {
double calcSquare();
}
class Circle extends Shape {
Circle(this.radius);
final double radius;
@override
@hawkkiller
hawkkiller / main.dart
Created July 9, 2023 17:16
OCP violation example
abstract interface class Account {
double get balance;
}
class SavingsAccount implements AccountType {
double balance;
SavingsAccount(this.balance);
}
@hawkkiller
hawkkiller / main.dart
Last active July 9, 2023 17:24
LSP signature requirement violation
class Bird {
void fly() {
print('The bird is flying.');
}
}
class Ostrich extends Bird {
@override
void fly() {
throw UnsupportedError('Ostriches cannot fly.');
void main() {
// create final variables that reference canonical object
final a = const A('A');
final b = const A('A');
// check if both a and b reference the same object
print(identical(a, b)); // True
// strings are const by default
// note, that str reference canonical object of type String
@hawkkiller
hawkkiller / eventloop.dart
Created August 3, 2023 14:50
Event Loop unloading
import 'dart:async';
import 'package:crypto/crypto.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatefulWidget {
@hawkkiller
hawkkiller / prefs.dart
Created September 5, 2023 11:49
shared prefs
import 'package:shared_preferences/shared_preferences.dart';
/// {@template preferences_dao}
/// Class that provides seamless access to the shared preferences.
///
/// Inspired by https://pub.dev/packages/typed_preferences
/// {@endtemplate}
abstract base class PreferencesDao {
final SharedPreferences _sharedPreferences;