Skip to content

Instantly share code, notes, and snippets.

View timsneath's full-sized avatar

Tim Sneath timsneath

View GitHub Profile
String numToString(BigInt number) {
final buf = StringBuffer();
for (var v = 0; v < 8; v++) {
final charCode = (number & BigInt.parse('0xFF' + ('00' * v))) >> v * 8;
buf.write(String.fromCharCode(charCode.toInt()));
}
return buf.toString();
}
import 'dart:ffi';
class LOGFONT extends Struct {
// Should be (5 * 4) + (8 * 1) + (8 * 8) bytes = 92 bytes
// sizeOf<LOGFONT>() is 96 bytes
@Int32()
int lfHeight;
@Int32()
int lfWidth;
@Int32()
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(debugShowCheckedModeBanner: false, home: HomeScreen());
}
}
@timsneath
timsneath / knownfolder.dart
Created March 31, 2020 22:34
Buggy attempt to call SHGetKnownFolder from Dart
// knownfolder.dart
// Shows usage of Shell APIs to retrieve the user's home directory
import 'dart:ffi';
import 'package:ffi/ffi.dart';
////////////////////////////////////////////////////////////////////////////////
// DEFINES /////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@timsneath
timsneath / main.dart
Created December 2, 2019 02:00
Advent of Code: Day 1
import 'dart:io';
int fuelMassForModule(int moduleMass, [int massSoFar = 0]) {
var mass = (moduleMass / 3).floor() - 2;
if (mass <= 0) {
return 0;
} else {
return mass + fuelMassForModule(mass, massSoFar);
}
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Text Editing Demo',
home: SafeArea(
@timsneath
timsneath / keybase.md
Created March 19, 2019 22:45
Keybase Proof

Keybase proof

I hereby claim:

  • I am timsneath on github.
  • I am timsneath (https://keybase.io/timsneath) on keybase.
  • I have a public key ASBuO4qNQ37lc4xluDGHePGwLrbrh2z2Zj4trHu7OUugXgo

To claim this, I am signing this object:

$ aqueduct document client
-- Aqueduct CLI Version: 3.0.0
-- Aqueduct project version: 3.0.0
*** Uncaught error
[Bad state: Invalid documenter 'HeroesController'. Reached end of controller chain and found no operations. Path has summary 'null'., #0 Controller.documentOperations (package:aqueduct/src/http/controller.dart:307:9)
#1 Controller.documentOperations (package:aqueduct/src/http/controller.dart:313:28)
#2 _RouteController.documentPaths.<anonymous closure> (package:aqueduct/src/http/router.dart:219:27)
#3 _ListBase&Object&ListMixin.fold (dart:collection/list.dart:218:22)
#4 _RouteController.documentPaths (package:aqueduct/src/http/router.dart:195:27)
#5 Router.documentPaths.<anonymous closure> (package:aqueduct/src/http/router.dart:145:24)
@timsneath
timsneath / scopedConst.dart
Created May 4, 2018 21:07
Example of scoped constant.
const comments = <Comment>[
Comment(
"Creating apps is just faster and more fun with Flutter.",
"Posse Inc."),
Comment(
"Yesterday I was trying #Flutter for the first time, today I published an application.",
"@CristianDudca"),
Comment(
"This weekend: Met and fell in love with Flutter.",
"@FIREYOSE"),
@timsneath
timsneath / buildWidget.dart
Created May 4, 2018 20:28
Simple example of a Widget build method without new keyword in Dart 2.
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text(widget.title),
actions: <Widget>[
IconButton(
icon: Icon(Icons.info),
onPressed: _aboutAction,
),
IconButton(
icon: Icon(Icons.share),