Skip to content

Instantly share code, notes, and snippets.

View sethladd's full-sized avatar

Seth Ladd sethladd

View GitHub Profile
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()) {
@sethladd
sethladd / more_simple_multiple_http_server_handler.dart
Last active January 2, 2020 11:26
Registering multiple HTTP handlers for a Dart web server. Not sure if this is the best way or not.
HttpServer.bind('127.0.0.1', 8889)
.then((HttpServer server) {
var sc = new StreamController();
sc.stream.transform(new WebSocketTransformer()).listen(handleWebSocket);
server.listen((HttpRequest request) {
if (request.uri.path == '/ws') {
sc.add(request);
} else if (request.uri.path == '/foo') {
request.response.addString('foo');
@sethladd
sethladd / Output.txt
Last active December 13, 2015 22:18
Benchmark map implementations in Dart.
HashMap(RunTime): 17443.478260869564 us.
SplayTreeMap(RunTime): 31250.0 us.
LinkedHashMap(RunTime): 817000.0 us.
HashMap(RunTime): 0.7287397466317649 us.
SplayTreeMap(RunTime): 2.640243113585899 us.
LinkedHashMap(RunTime): 1.4227564198326554 us.
HashMap(RunTime): 0.7923399740667126 us.
SplayTreeMap(RunTime): 2.406854722248965 us.
LinkedHashMap(RunTime): 1.4545084306944913 us.