Skip to content

Instantly share code, notes, and snippets.

View bsutton's full-sized avatar

Brett Sutton bsutton

  • @mention onepub
  • Melbourne, Australia
  • 19:47 (UTC +11:00)
View GitHub Profile
I think your basic approach is flawed. You should be decoding it as a json object.
I've not tested this but it looks about right - chat gpt generated by asking 'change this code to decode it into a class'
```dart
void main() async {
try {
var response = await http.post(
Uri.parse(AppSecrecy.CharacterCreatemysql),
headers: {"Content-Type": "application/json"},
@bsutton
bsutton / main.dart
Last active December 22, 2021 04:42
#! /usr/bin/env dcli
import 'dart:io';
import 'package:dcli/dcli.dart';
void main(List<String> arguments) {
final pubspec = DartProject.fromPath('.').pubSpec;
final isFlutter = pubspec.dependencies.containsKey('flutter');
@bsutton
bsutton / main.dart
Last active September 14, 2021 21:25
#! /usr/bin/env dcli
import 'dart:io';
import 'package:dcli/dcli.dart';
/// Outputs a hexi-decimal representation of a file
/// along with an asci representation.
void main(List<String> args) {
This script takes a tcp port no and prints out the process that has that port open.
I find it handy in development if I've left some server app running and its holding a port open that I'm trying to use.
import 'package:tree_iterator/tree_iterator.dart';
class Course {
var prerequisites = <Course>[];
String name;
Course(this.name);
void add(Course course) => prerequisites.add(course);
@override
@bsutton
bsutton / main.dart
Created June 14, 2020 07:44
non-null use after null check should not generate an error
class A
{
String? get startScriptPath => null;
bool addToPath(String path) {
if (startScriptPath != null) {
if (!exists(startScriptPath)) {
print('hi');
}
} else {
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
---
include: package:pedantic/analysis_options.yaml
# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
@bsutton
bsutton / main.dart
Last active March 1, 2020 00:23
Renew Lets Encrypt certificate
#! /usr/bin/env dshell
import 'dart:io';
import 'package:dshell/dshell.dart';
void main(List<String> args) {
var parser = ArgParser();
parser.addFlag("production", abbr: 'p', defaultsTo: false);
var result = parser.parse(args);
if (result.rest.length != 2) {
@bsutton
bsutton / main.dart
Created February 29, 2020 12:17
Copy directory tree
void copyTree(String fromPath, String toPath) {
var list = find(
'*',
root: from,
recursive: true,
).toList();
for (var file in list) {
var target = join(toPath, relative(file, from: fromPath));
@bsutton
bsutton / main.dart
Last active February 29, 2020 11:53
Convert to json
#! /usr/bin/env dshell
import 'dart:convert';
import 'package:dshell/dshell.dart';
void main() {
var json =
'wget -qO- https://jsonplaceholder.typicode.com/todos/1'.toJson();
print('Title: ${json["title"]}');
}