Skip to content

Instantly share code, notes, and snippets.

View theniceboy's full-sized avatar
🥰

David Chen theniceboy

🥰
  • 03:57 (UTC -07:00)
View GitHub Profile
@theniceboy
theniceboy / main.dart
Created January 9, 2023 16:58 — forked from Luckey-Elijah/main.dart
Dart Loop Benchmarking
// Adding this line so we can perform the variable assignment: num eachElement = 0;
// ignore_for_file: unused_local_variable
import 'dart:collection';
import 'dart:math';
void main(List<String> args) {
final list = UnmodifiableListView(
List<int>.generate(200000000, (index) => index),
);
@theniceboy
theniceboy / state.dart
Last active October 31, 2023 01:38
Simple stream-based state management in Flutter/Dart
import 'dart:async';
import 'package:async/async.dart';
import 'package:flutter/widgets.dart';
/*
This class is a little bit different than the [ValueNotifier] class:
- Setting the value ALWAYS notifies listeners, even if the value is the same.
- It uses streams over [ValueListenableBuilder]'s setState approach to make it
easier to use with other async code.
@theniceboy
theniceboy / dart-pset-1.md
Last active July 9, 2022 05:00
Practice problem #1

Printing triangles

Part I

Write the function repeatString that takes a String and an integer, and returns a String built by repeating the given String given number of times.

For example, one should be able to call

print(repeatString("*", 10));

and get