Skip to content

Instantly share code, notes, and snippets.

View MichaelTamm's full-sized avatar

Michael Tamm MichaelTamm

View GitHub Profile
enum A { foo, bar }
enum B { foo, bar, baz }
void main() {
final x = A.foo;
print(x == B.foo ? '$x == B.foo' : '$x != B.foo');
}
@MichaelTamm
MichaelTamm / main.dart
Last active February 17, 2023 14:22
Demonstrate Dart compiler issue https://github.com/dart-lang/sdk/issues/51444
class Factory<T> {
Factory(this.createInstance);
final T Function() createInstance;
}
T produce<T>(Factory<T> factory) {
return factory.createInstance();
}
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
final streamController = StreamController<String>();
final provider1 = StreamProvider<String>((_) => streamController.stream);
@MichaelTamm
MichaelTamm / main.dart
Created January 27, 2021 09:11
An important lesson (at least for me) about Dart mixins
// What do you think will be the output of this program?
class Base {
void foo() {
print("Base.foo()");
}
}
mixin FooMixin on Base {
@override
@MichaelTamm
MichaelTamm / WritableBuffer.ts
Created August 14, 2018 08:01
Node.js WritableBuffer class
import {Writable} from "stream"
class WritableBuffer extends Writable {
private _chunks: Array<Buffer> = []
_write(chunk: Buffer, encoding: "buffer", callback: (error?: Error) => void): void {
this._chunks.push(chunk)
callback()
}
@MichaelTamm
MichaelTamm / CountBytesStream.ts
Created August 14, 2018 07:52
Node.js CountBytesStream class
import {Transform} from "stream"
class CountBytesStream extends Transform {
counter = 0
finished = false
_transform(chunk: Buffer, encoding: "buffer", callback: Function): void {
this.counter += chunk.byteLength
callback(null, chunk)
}
@MichaelTamm
MichaelTamm / TestClass1.java
Created March 31, 2018 14:44
ParallelSuite and ParallelRunner
import com.googlecode.junittoolbox.ParallelRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Because this class uses the {@link ParallelRunner},
* the test methods are in parallel.
*/
@RunWith(ParallelRunner.class)
public class TestClass1 {
@MichaelTamm
MichaelTamm / ToggleFeaturesRunner.java
Created December 11, 2014 21:59
JUnit 4 Runner to run a test with all possible feature toggle combinations
import org.junit.internal.AssumptionViolatedException;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
import org.junit.runners.model.TestClass;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;