Skip to content

Instantly share code, notes, and snippets.

View sethladd's full-sized avatar

Seth Ladd sethladd

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Addtotable</title>
<link rel="stylesheet" href="addtotable.css">
<link rel="import" href="my_table.html">
<script type="application/dart">export 'package:polymer/init.dart';</script>
@sethladd
sethladd / secret_santas.dart
Created December 9, 2013 05:46
My humble entry for Dart Dare - Secret Santa. I'm sure there are smaller or faster ways to do this. However, I wanted to try to solve the problem with sorting and processing lists. The entire solution hinges on sorting the santas by last name and by family size. Features of Dart that I used: * Classes * String interpolation * Type annotations * …
class Person {
String firstName, lastName;
Person(List<String> raw) : firstName = raw[0], lastName = raw[1];
String toString() => '$firstName $lastName';
}
/**
* Expects one person per line, each line containing a first and last name
* separated by a single space.
*/
I am a null (ID: 177863854) and I am ready
I am a null (ID: 924578920) and I am ready
I am a null (ID: 394322034) and I am ready
I am a null (ID: 854832235) and I am ready
I am a null (ID: 587923908) and I am ready
I am a null (ID: 763736301) and I am ready
@sethladd
sethladd / google_sign_in.dart
Last active December 25, 2015 20:39
Testing an encapsulated gplus in polymer, both JS and Dart. Lots of caveats here. Make sure the plusone.js file is loaded before polymer (or, figure out all the async calls to wait until plusone is done loading). Note: normal gplus doesn't work because it scans the page looking for elements to upgrade. Of course, polymer puts everything into the…
import 'package:polymer/polymer.dart';
import "package:google_oauth2_client/google_oauth2_browser.dart";
import "package:js/js.dart" as js;
import 'dart:html';
import 'package:logging/logging.dart';
typedef OnSignInCallback(SimpleOAuth2 authenticationContext, [Map authResult]);
typedef OnSignOutCallback();
final Logger log = new Logger('google-sign-in-element');
@sethladd
sethladd / dart-leftview.html
Last active December 25, 2015 19:49
Lifecycle callback when an element leaves a view. The JavaScript version works (I see I leave you now in the console) but the Dart version doesn't display the 'I leave you now'. Note: the x-b and its children do disappear from the page. This code is about removed() in x-c not firing.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sample app</title>
<link rel="stylesheet" href="testme.css">
<!-- import the click-counter -->
<link rel="import" href="clickcounter.html">
@sethladd
sethladd / test_dart.html
Last active December 25, 2015 11:39
Potential bug in test_dart.html? You should see: A: [From A] B: [From A] C: [From A] Instead I see: A: [] B: [] C: [] To fix, remove the initialization of the published attributes. IOW don't set `@published String type = ''` to a blank string FWIW, looks like test_js.html works.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sample app</title>
<script src="packages/polymer/boot.js"></script>
</head>
<body>
<polymer-element name="x-c">
#!/bin/sh
DARTFILENAME=$1.dart
HTMLFILENAME=$1.html
ELEMENTNAME=$2
LIBNAME=`echo $2 | sed -e "s/-/_/g"`
CLASSNAME=$3
echo > $HTMLFILENAME
echo "<head>" >> $HTMLFILENAME
@sethladd
sethladd / opening_indexeddb_stores.dart
Last active December 19, 2015 02:19
How to open two indexeddb stores, one after another?
Database db;
window.indexedDB.deleteDatabase('justtesting')
.then((_) {
print('opening');
return window.indexedDB.open('justtesting', version: 1,
onUpgradeNeeded: (e) {
print('upgrading to v1');
Database d = e.target.result as Database;
d.createObjectStore('store1');
@sethladd
sethladd / persistable.dart
Created June 8, 2013 19:20
One attempt at a Persistable mixin in Dart.
import 'dart:mirrors';
import 'dart:async';
// TODO: inject the persistance storage driver
abstract class Persistable {
int _dbId;
static const constructor = const Symbol('fromPersistance');
static Future load(int id, Type type) {
import 'dart:io';
import 'dart:async';
import 'dart:math';
// The following function is part of a third-party package that you can't touch.
Future doCoolStuff() {
var completer = new Completer();
// Sometimes bad things happen.
if (new Random().nextBool()) {