Skip to content

Instantly share code, notes, and snippets.

View iota9star's full-sized avatar
๐Ÿ‘ป
Keep alive

ๆˆ‘ๅฟƒ้‡Œๅฑ้™ฉ็š„ไธœ่ฅฟ iota9star

๐Ÿ‘ป
Keep alive
View GitHub Profile
@iota9star
iota9star / export.dart
Last active September 17, 2024 10:22
Quickly create export files for all directories. Why are export files needed? To reduce the number of imports at the top of files and improve the Dart library import experience.
import 'dart:convert';
import 'dart:io';
import 'package:path/path.dart' as path;
Future<void> main() async {
final root = Directory.current;
final lib = Directory(path.join(root.path, 'lib'));
final projectName = await getProjectName(root);
createExport(lib, lib, fileName: projectName, skipChildren: true);
@iota9star
iota9star / private_fork.md
Created May 6, 2024 05:03 — forked from 0xjac/private_fork.md
Create a private fork of a public repository

The repository for the assignment is public and Github does not allow the creation of private forks for public repositories.

The correct way of creating a private frok by duplicating the repo is documented here.

For this assignment the commands are:

  1. Create a bare clone of the repository. (This is temporary and will be removed so just do it wherever.)

git clone --bare [email protected]:usi-systems/easytrace.git

@iota9star
iota9star / mutex_queue.dart
Last active February 8, 2023 05:20
Execute a specified number of tasks in parallel.
import 'dart:async';
import 'dart:collection';
import 'package:collection/collection.dart';
import 'package:tuple/tuple.dart';
typedef QueueTask<T> = Tuple3<int, FutureOr<T> Function(), Completer<T>>;
extension QueueTaskExtension<T> on QueueTask<T> {
int get taskId => item1;
@iota9star
iota9star / notifiers.dart
Created October 30, 2022 09:46
ValueListenable notifiers.
import 'package:flutter/foundation.dart';
class NewValueNotifier<T> extends ChangeNotifier implements ValueListenable<T> {
NewValueNotifier(this._value);
@override
T get value => _value;
T _value;
set value(T value) {
import 'dart:async';
class Mutex {
Completer<void>? _completer;
Future<void> lock() async {
while (_completer != null) {
await _completer!.future;
}
_completer = Completer<void>();
import 'dart:async';
import 'dart:collection';
Future<void> main() async {
final list = await [
Future.delayed(const Duration(milliseconds: 1500), () => 1),
Future.delayed(const Duration(milliseconds: 5000), () => throw '2'),
Future.delayed(const Duration(milliseconds: 1200), () => 3),
Future.delayed(const Duration(milliseconds: 8000), () => throw '4'),
Future.delayed(const Duration(milliseconds: 4300), () => 5),
@iota9star
iota9star / never_catch.dart
Last active October 30, 2022 10:55
No try catch, safe use await in one line.
import 'dart:async';
Future<void> main() async {
final a = await err().noc();
print(a);
print(a.runtimeType);
print(a.hasErr);
print(a.value);
print(a.value.runtimeType);
@iota9star
iota9star / gen_qr_code.dart
Created August 9, 2021 07:07
Generate QR code by dart native.
import 'dart:io';
import 'package:image/image.dart';
import 'package:qr/qr.dart';
void main() async {
var bytes1 = _genQRCode('ๅคงๅฎๅฅฝๅމๅฎณ๏ผ๏ผ๏ผ', rectSize: 20);
File('test1.png').writeAsBytesSync(bytes1);
var bytes2 = _genQRCode('ๅคงๅฎๅฅฝๅމๅฎณ๏ผ๏ผ๏ผ', size: 500);
File('test2.png').writeAsBytesSync(bytes2);
@iota9star
iota9star / ๐Ÿ“Š Weekly development breakdown
Last active September 8, 2021 00:49
wakatime-github-profile
Vue.js 26 hrs 41 mins โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Šโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ 65.8%
YAML 4 hrs 29 mins โ–ˆโ–ˆโ–Žโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ 11.1%
Rust 2 hrs 7 mins โ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ 5.2%
SQL 1 hr 38 mins โ–Šโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ 4.0%
XML 1 hr 18 mins โ–‹โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ 3.2%
@iota9star
iota9star / trans_demo.dart
Created May 31, 2021 12:48
็ฎ€็นไฝ“่ฝฌๆข
import 'dart:convert';
import 'dart:io';
void main(List<String> arguments) {
get('ๅกๅท็™ป้™†่ˆฐๅฎ‰็†ไผš็š„', func: TransType.ZH_HANT)
.then((value) => print(value))
.catchError((e) => print(e));
}
Future<R> get(