Skip to content

Instantly share code, notes, and snippets.

View dnys1's full-sized avatar

Dillon Nys dnys1

View GitHub Profile
@dnys1
dnys1 / main.dart
Created November 1, 2023 14:28
primal-lantern-1698
class ServiceManager {
final _instances = <Type, Object>{};
void register<T extends Object>(T instance) {
_instances[T] = instance;
}
bool isRegistered<T extends Object>() {
return isRegisteredByType(T);
}
@dnys1
dnys1 / main.dart
Created September 12, 2023 02:18
primal-lantern-1698
enum ABC { a, b, c }
void main() {
switch (ABC.a) {
case ABC.a:
print('a');
case != ABC.a:
print('b or c');
}
}
@dnys1
dnys1 / main.dart
Created August 30, 2023 00:46
astonishing-spray-3881
import 'dart:async';
void main() async {
// A function marked async will implicitly return a Future.
future(sync: true).then(print);
future(sync: false).then(print);
print('main (sync)');
// clear pending futures
await Future<void>.delayed(Duration.zero);
@dnys1
dnys1 / main.dart
Created June 14, 2023 15:19
bustling-aurora-9307
sealed class AuthState {}
abstract class AuthUserSignedIn extends AuthState {
AuthUser get user;
}
abstract class AuthUserSignedOut extends AuthState {
AuthUser get user;
}
@dnys1
dnys1 / main.dart
Created June 5, 2023 23:02
bustling-aurora-9307
enum MfaType { sms, totp }
T _useCurrent<T>(T value) => value;
Future<void> setMfaPreferences({
Set<MfaType> Function(Set<MfaType>) enabled = _useCurrent,
MfaType? Function(MfaType?) preferred = _useCurrent,
}) async {
// TODO
}
@dnys1
dnys1 / main.dart
Created May 9, 2023 17:08
bustling-aurora-9307
void main() {
switch ('hello') {
case 'hello':
print("Hello!");
continue s;
s: case String _:
print("It's a string!");
}
}
@dnys1
dnys1 / main.dart
Created May 6, 2023 05:37
lively-gorge-9708
class Serializable {
String toJson() => 'json';
}
void main() {
switch (Serializable() as dynamic) {
case dynamic(:final Object? Function() toJson):
print(toJson());
case _:
throw ArgumentError('Not serializable');
@dnys1
dnys1 / main.dart
Created May 6, 2023 05:37
lively-gorge-9708
class Serializable {
String toJson() => 'json';
}
void main() {
switch (Serializable() as dynamic) {
case dynamic(:final Object? Function() toJson):
print(toJson());
case _:
throw ArgumentError('Not serializable');
@dnys1
dnys1 / main.dart
Created May 5, 2023 19:00
bustling-aurora-9307
abstract class PluginOptions {}
abstract class Plugin<Options extends PluginOptions> {
Options get options;
}
class MyPluginOptions extends PluginOptions {}
class MyPlugin extends Plugin<MyPluginOptions> {
static const pluginKey = PluginKey<MyPluginOptions, MyPlugin>();
import { PreSignUpTriggerHandler } from "aws-lambda";
import { CognitoIdentityProvider } from "@aws-sdk/client-cognito-identity-provider";
const CLIENT = new CognitoIdentityProvider({});
export const handler: PreSignUpTriggerHandler = async (event) => {
console.log(`Got event: ${JSON.stringify(event, null, 2)}`);
const {
triggerSource,