Skip to content

Instantly share code, notes, and snippets.

View seaneagan's full-sized avatar

Sean Eagan seaneagan

View GitHub Profile
@library_en
import 'package:intlx/src/locale/plural/en.dart' as plural_locale_en;
@library_de
import 'package:intlx/src/locale/plural/de.dart' as plural_locale_de;
// ...
Future<bool> loadLocale([String locale]) {
const library_en = const DeferredLibrary('plural_locale_en');
const library_de = const DeferredLibrary('plural_locale_de');
@seaneagan
seaneagan / month.dart
Created March 20, 2013 02:12
An attempted improvement on how to expose weekday and month constants, they are currently all dumped in DateTime, and have ugly abbreviations.
// Month constants returned by [DateTime.month].
library month;
const int JANUARY = 1;
const int FEBRUARY = 2;
const int MARCH = 3;
const int APRIL = 4;
const int MAY = 5;
const int JUNE = 6;
const int JULY = 7;
class Polygon {
Polygon(List<Point> vertices);
Polygon.regular(Point centroid, num sideCount, num sideLength, {num radians = 0});
Point get centroid;
List<Point> get vertices;
Path get perimeter;
Polygon translate(Point vector);
// by default [about] is the first vertex
@seaneagan
seaneagan / foo.js
Last active December 11, 2015 22:08
function foo() {
alert('hi')
}
@seaneagan
seaneagan / interval.dart
Created May 17, 2012 15:27
Generic Dart Interval class
/// A contiguous interval of [Comparable]s, by default inclusive of it's [min] and exclusive of it's [max]
class Interval<T extends Comparable> {
const Interval(this.min, this.max, {this.containsMin = true, this.containsMax = false});
final T min, max;
final bool containsMin, containsMax;
bool contains(T test) {
@seaneagan
seaneagan / duration.dart
Created May 4, 2012 15:02
Adding weeks, months, and years to Duration
interface Duration default DurationImplementation {
// exact
static final int MONTHS_PER_YEAR = 12;
static final int DAYS_PER_WEEK = 7;
static final int MINUTES_PER_HOUR = 60;
static final int SECONDS_PER_MINUTE = 60;
static final int SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR;
static final int MILLISECONDS_PER_HOUR = MILLISECONDS_PER_MINUTE * MINUTES_PER_HOUR;
static final int MILLISECONDS_PER_MINUTE = MILLISECONDS_PER_SECOND * SECONDS_PER_MINUTE;
interface Command {
const Command(this.executable, [this.arguments, this.workingDirectory, this.environment]);
String get executable();
List get arguments(); // toString() will get called on each argument
String get workingDirectory();
Map<String, String> get environment();
Future<CommandResult> run([
Encoding stdoutEncoding,
interface FileNode {
String get path();
Future<Path> get fullPath();
Future<Directory> get parent(); // renames File#directory
Future<void> set parent(Directory d);
Future<void> create();
Future<void> delete();
@seaneagan
seaneagan / num.dart
Created March 13, 2012 18:51
Experiment to merge Dart's Math class into its num, int, and double interfaces
#library("num")
#import("dart:core", prefix: "c");
class num implements c.num {
num.wrap(c.num this._wrapped);
num operator +(c.num other) => _wrapped + other;
num operator -(c.num other) => _wrapped - other;
num operator *(c.num other) => _wrapped * other;
num operator %(c.num other) => _wrapped % other;
#library("time");
// "Date" implies only the year, month, and day, use "Time" instead
class Time implements Comparable {
// make all arguments except year optional, default to smallest possible
Time(
int year, [
int month = 1,
int day = 1,