Skip to content

Instantly share code, notes, and snippets.

View hotdang-ca's full-sized avatar

James Robert Perih hotdang-ca

View GitHub Profile
@hotdang-ca
hotdang-ca / main.dart
Created April 24, 2023 14:56
Using ChangeNotifier as a Singleton
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() {
runApp(const SampleApp());
}
class SampleApp extends StatelessWidget {
const SampleApp({super.key});
@override
@hotdang-ca
hotdang-ca / query_params.dart
Created February 13, 2023 16:29
Query Params and the Uri Class
void main() {
final String url = "http://www.clickspce.com?foo=bar&fizz=buzz&name=Sebastian";
final Uri parsedUri = Uri.parse(url);
print(parsedUri.queryParameters['foo']);
print(parsedUri.queryParameters['fizz']);
print(parsedUri.queryParameters['name']);
print(parsedUri.queryParameters['probably_null']);
@hotdang-ca
hotdang-ca / gcloud_oauth_2_example.dart
Last active September 15, 2022 15:25
Exchange Google Service Account Private Key for OAuth2.0 Token
import 'dart:convert';
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
import 'package:http/http.dart' as http;
const _PATH_TO_SERVICES_JSON = './secrets/service_account.json';
const _GOOGLE_TOKEN_EXCHANGE_URL = 'https://oauth2.googleapis.com/token';
final _cachedToken = <String, DateTime>{};
/// Gets OAuth2.0 access token from a service account json
@hotdang-ca
hotdang-ca / tax_calc.dart
Created June 20, 2022 22:59
fun with tax rates
class ProfitekItem {
late final bool taxable1;
late final bool taxable2;
late final bool taxable3;
late final bool taxable4;
late final num? taxRate1;
late final num? taxRate2;
late final num? taxRate3;
late final num? taxRate4;
@hotdang-ca
hotdang-ca / doubles.dart
Last active May 26, 2022 16:52
Dart Double Fun
import 'dart:math';
double roundDouble(double value, double places) {
num mod = pow(10.0, places);
return ((value * mod).round().toDouble() / mod);
}
extension BetterDoubles on num {
num roundAsDoubleBetter(double places) {
final num mod = pow(10.0, places);
@hotdang-ca
hotdang-ca / dart_labels.dart
Created April 24, 2022 06:48
Dart has Labels!!
void main() {
ten:while(true) {
print('Hello world!');
continue ten;
break;
}
}
@hotdang-ca
hotdang-ca / isolates_fun.dart
Created April 24, 2022 06:47
Isolate Fun in Dart
import 'dart:async';
import 'dart:io';
import 'dart:isolate';
void main(List<String> arguments) async {
ReceivePort receivePort = ReceivePort();
Isolate fooIsolate = await Isolate.spawn(foo, receivePort.sendPort);
Isolate barIsolate = await Isolate.spawn(bar, receivePort.sendPort);
Isolate fooBarIsolate = await Isolate.spawn(fooBar, receivePort.sendPort);
@hotdang-ca
hotdang-ca / dart_reflection.dart
Last active August 16, 2022 17:30
Exploring Dart Mirrors 1
import "dart:mirrors";
class Product {
String type;
String brand;
String model;
Product(this.type, this.brand, this.model);
}
@hotdang-ca
hotdang-ca / potency_conversion.dart
Created March 22, 2022 14:59
Cannabis Potency conversation
class Cannabis {
final String uom;
final num p;
Cannabis(this.uom, this.p);
}
void main() {
List<Cannabis> product = [
Cannabis('%', 5),
@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;