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 / 📊 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 / 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 / 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(
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 / 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) {
@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);
import 'dart:async';
class Mutex {
Completer<void>? _completer;
Future<void> lock() async {
while (_completer != null) {
await _completer!.future;
}
_completer = Completer<void>();
@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;