Skip to content

Instantly share code, notes, and snippets.

View evaisse's full-sized avatar

Emmanuel Vaïsse evaisse

  • none
  • Nancy, France
View GitHub Profile
@evaisse
evaisse / the_problem_with_dynamic.dart
Created September 13, 2024 14:17
The problem with `dynamic` in dart
void main() {
dynamic myDynamicValue = null;
myDynamicValue.length;
Object? myTypedValue = myDynamicValue;
myTypedValue.length; // that's helpful
@evaisse
evaisse / typed_generics.dart
Last active September 13, 2024 12:01
Show how extends at least `Object` allow to forbid passing dynamic generics
class Generic<T> {
final T that;
Generic(this.that);
}
class TypedGeneric<T extends Object> {
final T that;
TypedGeneric(this.that);
}
@evaisse
evaisse / castor_safe_try_as.dart
Last active September 13, 2024 10:32
cast0r — Safe try/as and transform extension that works on any object for Dart
/// Cast Or provide default value (optional or safely defaulted)
/// by the way, "castor" is the french word for beaver...
/// ```
/// ___
/// /. .\
/// =\_t_/=
/// [|]
/// ```
///
extension CastOrExtension<T extends Object> on T {
class Cool {
final int count;
Cool({ int? count = 20 }): this.count = count ?? 20;
}
class NotCool {
final int count;
NotCool({ this.count = 20 });
}
@evaisse
evaisse / pocketbase_csv_import_export.js
Created September 4, 2024 12:41
Basic javascript plugin to import/export into your PocketBase admin UI
console.log('coucouc');
@evaisse
evaisse / enum_generics_inferance.dart
Last active August 30, 2024 13:37
Dart ssmple to explain Enum with generics inference
enum ManyGenerics<T> {
myInt<int>(defaultValue: 3),
myString<String>(defaultValue: 'hello');
final T defaultValue;
const ManyGenerics({required this.defaultValue});
}
typedef WrappedAccess = ({ManyGenerics val});
@evaisse
evaisse / sealed_state_example.dart
Created July 25, 2024 13:07
dart sealed class and unstructuring of switch case in pattern matching
enum ScoreLevel {
rookie,
maestro
}
sealed class MyState {
}
@evaisse
evaisse / main.dart
Last active June 19, 2024 12:15
Example of ValueNotifier & ValueListenerBuilder to replace Rx from Getx.
import 'package:flutter/material.dart';
///
/// @see https://api.flutter.dev/flutter/widgets/ValueListenableBuilder-class.html
/// @see https://api.flutter.dev/flutter/foundation/ValueNotifier-class.html
///
ValueNotifier<int> counter = ValueNotifier<int>(0);
void main() {
runApp(const MyApp());
@evaisse
evaisse / dart_generic_inheritance.dart
Last active April 26, 2022 16:04
Describe how to implement a twin generics inheritance with dart
///
/// @see https://dartpad.dev/660a4ec4fcb91ff648a632705ea4697a
///
import 'package:flutter_test/flutter_test.dart';
/// base controller, just to explain the main inheritance
class BaseController {}
class BaseScreen<T extends BaseController> {
late final T controller;
@evaisse
evaisse / log4jscan.py
Last active January 25, 2022 18:57
A log4j version scan over a given path.
#!/usr/bin/python
"""
sudo python3 log4jscan.py evaisse -d /System/Volumes/Data/Applications/Transporter.app/Contents/itms/share
Output stuff like this :
Script version: 2.1 (scans jar/war/ear/zip files)
Start scanning on "/System/Volumes/Data/Applications/Transporter.app/"
========================================================================