Skip to content

Instantly share code, notes, and snippets.

@ailabs-software
ailabs-software / file.dart
Created August 7, 2022 02:13
On line 15, how to break out of scope and reference dart String type?
enum DataType
{
None(false, BASE_OPERATOR_TITLE_MAP), // Null or nil is this language.
Boolean(false, BASE_OPERATOR_TITLE_MAP),
Number(false, BASE_OPERATOR_TITLE_MAP),
String(false, BASE_OPERATOR_TITLE_MAP),
Date(false, BASE_OPERATOR_TITLE_MAP),
StringArray(true, BASE_OPERATOR_TITLE_MAP), // An array of strings
Object(false, BASE_OPERATOR_TITLE_MAP), // A catch-all type for objects types.
DateTime(false, BASE_OPERATOR_TITLE_MAP),
@ailabs-software
ailabs-software / main.dart
Created July 25, 2022 17:40
More of more specific generic type parameter assigned to variable, causing loss of type checking.
class Foo<T>
{
late T value;
}
void main() {
Foo<Object?> foo1 = new Foo<String>();
Foo<Object?> foo2 = new Foo<int>();
@ailabs-software
ailabs-software / gist:fbdbea61e2c8999d745feab4264770ab
Created June 21, 2022 02:35
Trying to send dart compile js output to stdout
% dart compile js web/main.dart -o /dev/stdout --no-source-maps
Almost works, but at the end there is an error:
if (typeof dartMainRunner === "function")
dartMainRunner(callMain, []);
else
callMain([]);
});
})();
The compiler crashed: FileSystemException: Cannot create file, path = '/dev/stdout.deps' (OS Error: Operation not permitted, errno = 1)
targets:
$default:
sources:
- lib/**
- web/**
# Note that it is important to include these in the default target.
- pubspec.*
- $package$
builders:
# -----------------------
@ailabs-software
ailabs-software / test.dart
Created December 23, 2021 17:09
Trying to figure out a way say type are in class extends a generic type (IVisitor), _without_ filling in the R type parameter of visitor from the class type arg, but instead from a method named accept(). This would then enable use of visitor pattern without coupling accept() to what visit methods exist, and therefore what node types exist. This …
abstract class IVisitor<R> {
// visitX() methods not declared here, but
// on implementing class, so we can add new node types,
// without coupling the code calling accept() to that knowledge.
}
abstract class NodeVisitor<R> implements IVisitor<R> {
R visitParen(Node token);
}
@ailabs-software
ailabs-software / build.yaml
Created June 3, 2021 00:30
Example build.yaml. You might also set -O4 instead
targets:
$default:
sources:
- lib/**
- web/**
# Note that it is important to include these in the default target.
- pubspec.*
- $package$
builders:
# -----------------------
@ailabs-software
ailabs-software / gist:391c0ffde63b4f6066107d11bef387e9
Created May 27, 2021 17:49
Attempting to extend both an interface (abstract class) & implement overrides of those methods, using extension.
abstract class IDataType
{
void render();
}
class StringDataType implements IDataType
{
@override
void render()
@ailabs-software
ailabs-software / main.dart
Last active June 23, 2020 21:02
How can I use fields of const-constructed objects in switch cases?
class Property
{
final String foo;
const Property(String this.foo);
}
const Property MARGIN = const Property("margin");
const Property PADDING = const Property("padding");
@ailabs-software
ailabs-software / main.dart
Last active June 22, 2020 17:49
Using type of property key argument's type argument to infer T, and statically check that value type matches.
class LayoutBox { }
class RgbColour { }
class LayoutProperty<T>
{
static final LayoutProperty<LayoutBox> margin = new LayoutProperty<LayoutBox>();
static final LayoutProperty<RgbColour> colour = new LayoutProperty<RgbColour>();
1) Needs more RAM (swap is 1.6GB often times)
2) Disc is getting too full (82%), causing more SSD garbage collection/moving stuff around on disc.
3) Not enough cores to handle 100 max_connections -- intrbiz says look at adding cores first as your load average is over core count.
4) Application processes stealing CPU from postgres
5) Poorly designed queries -- peerce
Intrbiz says: Log only slow queries so you can get an idea if it is certain queries which are consistently slow.
6) A possible change is that we are getting a lot of concurrent visits putting strain on the system through analytics caused by bots/spam filters visiting all links at once. We have been seeing that this results in a bunch of INSERT queries getting stuck running for many seconds. Do we need to change the isolation level so these INSERT queries can run smoothly concurrently?