Skip to content

Instantly share code, notes, and snippets.

View hotdang-ca's full-sized avatar

James Robert Perih hotdang-ca

View GitHub Profile
/**
*
* Detect Ad Blockers
*
* Copyright (c) 2020 Four And A Half Giraffes, Ltd.
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
@hotdang-ca
hotdang-ca / singleton_example.dart
Last active May 27, 2021 15:41
Dart Singleton Example
import 'package:flutter/material.dart';
class State with ChangeNotifier {
late num _count;
num get count => _count;
void setCount(newCount) {
_count = newCount;
notifyListeners();
}
@hotdang-ca
hotdang-ca / dart_fold.dart
Created September 9, 2021 21:10
Sample of dart fold method
class PaymentLine {
double price;
String name;
int qty;
PaymentLine({ this.price, this.name, this.qty });
}
void main() {
List<PaymentLine> payments = <PaymentLine>[];
@hotdang-ca
hotdang-ca / distance.dart
Created November 24, 2021 16:48
Dart code to calculate distance between two lat/lng decimal coordinates
import 'dart:math';
/// Describes a distance unit for conversion
enum Unit {
miles,
kilometers,
nauticalMiles,
}
/// Describes a decimal coordinate
@hotdang-ca
hotdang-ca / dart_mirror.dart
Last active February 3, 2022 20:20
Basic Object name via Reflection in Dart
import 'dart:mirrors';
class User {
final String email;
final String name;
const User({required this.email, required this.name});
}
extension DeclarationMirrorExtension on DeclarationMirror {
/// Name of this object or field
@hotdang-ca
hotdang-ca / example.js
Created July 16, 2019 15:17
CamelCase to Camel Case
console.log("JamesPerihIsCool".replace(/(?<!^)(?=[A-Z])/g, ' '));
@hotdang-ca
hotdang-ca / throw_rethrow.dart
Created February 27, 2022 19:18
Dart Async Throw and Rethrow
Future<void> doAThing() async {
await Future.delayed(Duration(milliseconds: 500));
try {
print('Trying a dangerous thing...');
await doADangerousThing();
} catch (e) {
print('There was a minor error: $e');
rethrow;
}
@hotdang-ca
hotdang-ca / resolutions.dart
Created March 17, 2022 09:49
Screen resolutions, in Dart
/// Describes a television screen resolution
class ResolutionSize {
/// The natural width of this resolution
final int width;
/// The natural height of this resolution
final int height;
/// A shorter technical name
final String name;
@hotdang-ca
hotdang-ca / main.dart
Last active March 17, 2022 10:07
Fizzbuzzing Dart
/// Oct 23, 2020
/// Updated March 17, 2021
/// (c) 2020 James Robert Perih c/o Four And A Half Giraffes, Ltd.
void main() {
const int theStart = 1;
const int theEnd = 100;
DartFlutterOutputFactory().printIteration(
from: theStart,
@hotdang-ca
hotdang-ca / random_stream.dart
Last active March 17, 2022 10:07
Random Flutter Stream
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:math';
void main() {
runApp(MyApp());
}
class RandomNumberStream {
final StreamController<int> _nextRandomNumberController = StreamController<int>();