Skip to content

Instantly share code, notes, and snippets.

View thetrav's full-sized avatar

Travis Dixon thetrav

View GitHub Profile
import 'package:flutter/material.dart';
import 'gd_button.dart';
class GdAsyncButton extends StatefulWidget {
final Widget child;
final Color color;
final bool flat;
final bool disabled;
@thetrav
thetrav / gd_list_view.dart
Created February 24, 2020 07:47
flutter list with filter and sort
import 'package:flutter/material.dart';
import 'gd_button.dart';
import 'gd_flex_row.dart';
import 'gt_text_field.dart';
import 'gd_green_bar.dart';
typedef FilterFunction<T> = bool Function(String, T);
typedef SortFunction<T> = int Function(T, T);
typedef HeaderBuilder<T> = Widget Function(BuildContext, FilterFunction<T>, SortFunction<T>);
typedef Listener<T> = void Function(List<T>);
@thetrav
thetrav / fancy_future_builder.dart
Created February 12, 2020 04:56
Combine navigation on error with FutureBuilder
import 'package:flutter/material.dart';
class FancyFutureBuilder<T> extends StatelessWidget {
final Future<T> future;
final Widget Function (BuildContext , AsyncSnapshot<T>) builder;
final Function doNavigation;
final bool Function(Object) shouldNavigate;
FancyFutureBuilder({
@thetrav
thetrav / flutter doctor
Created February 11, 2020 01:06
Test flutter routing
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, v1.15.3-pre.37, on Microsoft Windows [Version 10.0.18362.592], locale en-AU)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
X Android license status unknown.
Try re-installing or updating your Android SDK Manager.
See https://developer.android.com/studio/#downloads or visit https://flutter.dev/setup/#android-setup for detailed instructions.
[√] Chrome - develop for the web
[√] Android Studio (version 3.5)
[!] IntelliJ IDEA Community Edition (version 2019.3)
@thetrav
thetrav / gd_download_button.dart
Last active December 30, 2019 21:10
download files in flutter web
import 'dart:html';
import 'package:flutter/material.dart';
import 'package:growdata_shared_web/service/api.dart';
class GdDownloadButton extends StatelessWidget {
final String path;
final Api api;
GdDownloadButton(this.path, this.api);
@thetrav
thetrav / gd_file_input.dart
Last active December 29, 2019 03:58
File input widget
import 'dart:html';
import 'package:flutter/material.dart';
import 'package:growdata_shared_web/component/gd_red_text.dart';
class GdFileInput extends StatefulWidget {
final void Function(String, List<int>) fileSelected;
final List<String> extensions;
GdFileInput(this.fileSelected, {this.extensions});
@thetrav
thetrav / api.dart
Last active June 10, 2020 20:22
Upload file to server
import 'package:http/http.dart' as http;
import 'package:http_parser/http_parser.dart';
Future<http.Response> uploadFile(
String url,
Map<String, String> headers,
Map<String, String> fields,
String fileName,
List<int> fileBytes) async {
var request = new http.MultipartRequest("POST", Uri.parse(url));
@thetrav
thetrav / tbotc.pc
Last active February 22, 2018 07:40
psuedo code for a turn based offworld trading company
for each tick
for each company
execute destruction orders
productionBuildings
add resourceSource inputs
add stockPile inputs
add autoBuy inputs
consume power
@thetrav
thetrav / data.scala
Created April 6, 2017 03:44
generic Dao with Trait
trait Dao[T] {
val tableName: String
def find(id:String): ConnectionIO[Option[T]] =
Fragment.const("select * from $tableName where id = ") ++ fr"$id".query[T]
}
case class Foo(id: String, data: String)
object Foos extends Dao[Foo] {
@thetrav
thetrav / limes.py
Created March 27, 2017 21:35
Average daily price of limes
import requests
from bs4 import BeautifulSoup
def coles_price():
r = requests.get('http://shop.coles.com.au/online/mobile/national/limes-loose')
if r.status_code == 200:
soup = BeautifulSoup(r.text, 'html.parser')
price_text = soup.find('p', {'class': 'price'}).get_text()
return float(price_text.replace('$', ''))
else: