Skip to content

Instantly share code, notes, and snippets.

@mmaitlen
mmaitlen / gist:ef1d73f4767c6cda758726fa34679e6b
Last active March 5, 2025 17:25
Null callback shortcut?
Stumbled upon this, the code at the bottom compiles, but there is no output,
when I was thinking it might output something like >> list 123, 456
Was looking for a shorthand to
final cb = callback;
if (cb != null) {
cb(['123','456']);
}
Created a shelf server with 'dart create -t server-shelf server1' in a mono repo using Melos.
So the server is located in myrepo/apps/server1.
The server runs just fine with 'dart run bin/server.dart', but when I try the Docker command
from the README.md file 'docker build . -t myserver' I get a bunch of unfound file errors (ERROR OUTPUT below)
I can see the files with an ls, so they are in my pub-cache
> ls /Users/michaelmaitlen/.pub-cache/hosted/pub.dev/shelf-1.4.2/lib
shelf.dart shelf_io.dart src
I created another test server with the dart create command, by itself, not inside a mono
@mmaitlen
mmaitlen / a_websocket_client.dart
Created July 11, 2024 00:26
A simple Flutter/Dart websocket client
/// A simple websocket client Flutter app
/// thanks to Simon Lightfoot @devangelslondon and Craig Labenz @craig_labenz
/// #boringshow https://youtu.be/AaQzV1LTmo0?si=2xjcfH0FA5tt4nyW
import 'package:flutter/material.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
void main() {
runApp(const MainApp());
}
@mmaitlen
mmaitlen / a_websocket_server.dart
Last active July 11, 2024 00:23
Flutter/Dart Websocket server
/// A simple websocket server Flutter app that can ping a connected client
/// thanks to Simon Lightfoot @devangelslondon and Craig Labenz @craig_labenz
/// #boringshow https://youtu.be/AaQzV1LTmo0?si=2xjcfH0FA5tt4nyW
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
@mmaitlen
mmaitlen / gist:8bd89314cadf5401feda
Created June 29, 2014 18:36
Determine Google or Amazon device
private static final String AMAZON_MANUFACTURED_DEVICE = "amazon";
private interface DeviceType {
public static final int GOOGLE_DEVICE = 1;
public static final int AMAZON_DEVICE = 2;
}
private int getDeviceType() {
int type = 0;
String manufacturer = Build.MANUFACTURER;
String model = Build.MODEL;