Skip to content

Instantly share code, notes, and snippets.

View blaugold's full-sized avatar

Gabriel Terwesten blaugold

View GitHub Profile
@blaugold
blaugold / typescript-firebase-database-rules.ts
Last active August 10, 2023 07:11
Firebase Database Rules with TypeScript
// Use the TypeScript compiler to check your database rules.
// You'll get the most out of type checking if you define a database schema
// through interfaces and use it both in the web client and with the database rules.
// The compiler will catch misspellings and structural errors.
// It won't check for completeness since all properties are optional.
// Only works with TypeScript 2.1 and up because of mapped types being used.
interface DatabaseRuleSet {
'.read'?: string | boolean
'.write'?: string | boolean
import { FirebaseDatabase } from '@blaugold/angular-firebase'
import 'rxjs/add/operator/map'
/**
* This example demonstrates the type checking ability when the database is used with a schema.
* Open this file with an ide like VS Code or WebStorm and you should see error highlighting.
*/
interface DBSchema {
todoLists: {
@blaugold
blaugold / cubic_bezier_spline.dart
Last active December 16, 2019 10:47
Creating smooth curves, which pass through points in a path, with cubic bezier curves.
import 'dart:ui';
/// Returns control points which can be used to create a bezier path which is smooth at the joins between [knots].
///
/// The result contains one less set of control points than there are [knots]. To construct a path start by moving to
/// the first knot and add cubic bezier segments for the other knots.
///
/// Ported from https://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Offsets-wit
List<List<Offset>> bezierSplineControlOffsets(List<Offset> knots) {
assert(knots != null);
@blaugold
blaugold / quadratic_bezier.dart
Created December 16, 2019 10:51
Util for smoothing of line joins, with quadratic beziers.
import 'dart:ui';
class QuadraticBezier {
final Offset p0;
final Offset p1;
final Offset p2;
/// Returns a list of [QuadraticBezier]s which represent smooth line joins between knots.
///
/// To reduce the smoothing at the joins reduce [maxJoinSegmentLength].
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
void withBuilder() {
return Builder(
builder: (context) {
return RaisedButton(
child: Text('Button'),
onPressed: () {
final renderObject = context.findRenderObject();
}
);
}
Matrix4 getAnchorToNavigatorTransform(RenderObject anchor, RenderObject navigator) {
// These two transforms project points from the local coordinate spaces of their
// respective RenderObjects to the global coordinates space.
Matrix4 anchorTransform = anchor.getTransformTo(null);
Matrix4 navigatorTransform = navigator.getTransformTo(null);
// This transform projects points from the local coordinates space of [anchor]
// to the global coordinate space and from there to the local coordinate space
// of [navigator] in one step.
return anchorTransform..multiply(Matrix4.tryInvert(navigatorTransform));
}
import 'package:flutter/material.dart';
/// Overlays [overlay] over [anchor], when pushed.
///
/// This route extends [PopupRoute], but if your implementing your own route
/// I suggest skimming the docs of [TransitionRoute], [ModalRoute] and
/// [PageRoute]. [PopupRoute] is just the most natural base class for a route
/// like this one.
class OverlayRoute<T> extends PopupRoute<T> with WidgetsBindingObserver {
OverlayRoute({
import 'package:flutter/foundation.dart';
void withAssert() {
assert(() {
runConditionalCode();
return true;
});
}
void withEnvironmentFlag() {
@blaugold
blaugold / main.dart
Created September 15, 2021 14:38
Flutter-Display-DevicePixelRatio
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override