Skip to content

Instantly share code, notes, and snippets.

View sethladd's full-sized avatar

Seth Ladd sethladd

View GitHub Profile
@sethladd
sethladd / gist:4639048
Created January 26, 2013 00:10
Static file serving with App Engine. This handles /directoryname => /directoryname/
application: new-project-template
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: (.*/)
static_files: static_content\1index.html
upload: static_content
@sethladd
sethladd / streams_and_event_loop.dart
Created February 8, 2013 21:38
Streams, stream controller, and event loops in Dart.
import 'dart:async';
import 'dart:math';
/*
* Findings:
* streams can be single or broadcast, but not sure why the diff.
* can check if a stream is broadcast with isBroadcast
* StreamController make it easy to use a stream and send it events
*/
@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.
@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');
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 / 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) {
@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');
#!/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 / 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">
@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">