Skip to content

Instantly share code, notes, and snippets.

View timnew's full-sized avatar

TimNew timnew

View GitHub Profile
@timnew
timnew / All
Last active February 3, 2024 06:47
Factorio Blueprint
0eNrsvduSW8mxpvkqbbxmylacI2S2+6JnnmCm72RlZSQrq5QmFsnOSmpv2Ta9+wBIJLAyMxz4PwdGdRBvShJV/BHLTxHh/rvHf795//Hr7Zf7u08P37///Plvb/7838c/+eXNn//y3+Bf2P5/dx8+f3r841/ufvr07uP2zx7+8eX2zZ/f3D3c/vzm7ZtP737e/q/7d3cf3/zz7Zu7Tz/c/tebP4d/vj37Vx5u/+vhy8d3D7c3H9/d/3R788vD50+3K4z4z+/evrn99HD3cHf7uIbd//jH95++/vz+9n7zI89+/ebDX9/dfbrZ/+jbN18+/7L5m58/bX9/u6LU/lTevvnHmz/fxM1/++d2gS/w4gHvl4cN4k9/fbjZfdYEazwhzXCSjJPbKZz8/PvML8v92Ze9ffPD3f3th8d/I09wC5FbCmflVtXvTeGk3JqME0/KrWtySxHKbRxwP3y9//vtD6Z19D1qfI5ZJphh4UY3VUII4uqysbrZF4fITXm+uqStLgUiu8wNb766Iq4uEtlVbs7z1TVuImkK1FHAzOngHvGle8QZ/ODGMl1nXLhe50Boh0gRfnCMXMPzdSYaWZbnq6sz0MzNJkxXV3S9pgPQeelVGrBefHSagTZug/OP7jRgKSoZ3LCnq0u6h0SgkhRoHBRUkhxeMv/oxM57B28O/aU3hxk88Jcn4PYcts1gC4cdglQr9u4N7AyIe4wB1GWgEuYfOtvk0+Cw7by284KMqUTbmGbqyUH3dGBMObKjO3SBnPiqBVvN/Jw2N7FccCgxgPSzWQK2mhuHVWwVndtSoraqe1jabyahnLfVsnDYdn61Bd7660EYVTnTlehMKgTjclzUs902Iu2AsnCDzyponYPOrLcU5/VAlGxl8APCNwbfnynuvMTB7mZY81Tmg8MKgbyCGxRw6Ro4rODSFe5q0KVrcua7LJeuWT0mA5euxXlXFYVQ1TWDiFEbWzP0ucr2vQgjRtVvYwm4dFs4rODSLejb6dPZIp136RbV1EOc28X
@timnew
timnew / example.dart
Created August 2, 2023 23:53
Dart override fails due to signature conflict
abstract class A {
@override
String toString({int param = 1}) => "A:$param";
}
mixin M {
String toString() => "M";
}
class B extends A with M {
@timnew
timnew / select_sdk
Last active March 1, 2023 05:11
Activate SDK from a bunch of installed ones
#!/usr/bin/env bash
# How to use
# 1. Put all unzipped SDKs into a folder
# 2. Put this file in the same folder
# 3. Update the `SYMOLIC_LINK` value to the one reffered by $PATH
# 4. call this script from anywhere, it would list all SDKs, and recreate the $SYMOLIC_LINK to the selected SDK
SYMOLIC_LINK=~/Workspace/flutter
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
@timnew
timnew / switch_demo.dart
Created February 8, 2023 07:51
Switch demo
import 'package:flutter/material.dart';
void main() => runApp(const SwitchApp());
class SwitchApp extends StatelessWidget {
const SwitchApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
@timnew
timnew / dart.json
Created November 16, 2022 00:54
VSCode Code snippet for Dart and Flutter
{
"for": {
"prefix": "for",
"body": ["for(int ${1:i} = ${2:0}; $1 < $3; $1++){", " $4", "}"],
"description": "For loop"
},
"fore": {
"prefix": "fore",
"body": ["for(final ${1:item} in ${2: list}){", " $3", "}"],
"description": "for each"
@timnew
timnew / dart-freezed.json
Last active November 16, 2022 00:50
VSCode Code Snippet for Freezed and Dart
{
"frf": {
"prefix": "frf",
"body": [
"import 'package:freezed_annotation/freezed_annotation.dart';",
"",
"part '$TM_FILENAME_BASE.freezed.dart';",
""
],
"description": "Frezed - file"
@timnew
timnew / exceptions.dart
Last active February 21, 2022 00:41
Firestore Helper
class DocumentNotFoundException implements Exception {
final String path;
DocumentNotFoundException(this.path);
@override
String toString() =>
'DocumentNotFoundException\n Document $path does not exist.';
}
@timnew
timnew / try_catch_not_working_in_async_generator.dart
Last active May 8, 2021 14:01
Try catch seems not working in async generator
Stream<String> test1(Future<String> future) async* {
try {
yield "a";
yield await future;
yield "b";
} catch (ex) {
yield ex.toString();
}
yield "c";
}
@timnew
timnew / never_issue_spread.dart
Created May 7, 2021 06:04
A more complex example of the type issue
abstract class Stated<T> {
const Stated._();
factory Stated.idle() => const _Idle<Never>();
const factory Stated.value(T value) = _Value;
TypeChecker<T> typeChecker() => TypeChecker<T>();
void someMethod(Future<T> future) async {
print(await future);
@timnew
timnew / unexpected_covariance_type_inference.dart
Created May 7, 2021 03:12
Unexpected covariance type inference
abstract class Stated<T> {
const Stated._();
factory Stated.idle() => const _Idle();
const factory Stated.value(T value) = _Value;
Type get valueType => T;
}
class _Idle<T> extends Stated<T>{