Skip to content

Instantly share code, notes, and snippets.

View sethladd's full-sized avatar

Seth Ladd sethladd

View GitHub Profile
@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.
@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 / 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 / Procfile
Created August 15, 2012 05:42
Dart server for Heroku
web: dart main.dart
@sethladd
sethladd / dartstagram.dart
Created April 27, 2012 16:07
Instagram API with Dart
#import('dart:html');
#import('dart:json');
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
dataReceived(MessageEvent e) {
var data = JSON.parse(e.data);
#library('lib2');
#source('lib2_helper.dart');
String lib2String = "hello from lib2";
@sethladd
sethladd / IndexedDBSample.dart
Created February 23, 2012 01:46
Dart IndexedDB sample
#import('dart:dom', prefix:'dom');
#import('dart:html');
String VERSION = "1";
String TODOS_STORE = 'todos';
initDb(db) {
if (VERSION != db.version) {
dom.IDBVersionChangeRequest versionChange = db.setVersion(VERSION);
versionChange.addEventListener('success', (e) {
@sethladd
sethladd / app.dart
Created February 2, 2012 05:39
Web Audio API and Dart
#import('dart:dom', prefix:'dom');
#import('dart:html');
main() {
dom.AudioContext audioContext = new dom.AudioContext();
dom.AudioBufferSourceNode source = audioContext.createBufferSource();
dom.AudioGainNode gainNode = audioContext.createGainNode();
source.connect(gainNode, 0, 0);
@sethladd
sethladd / post-secret-archive.rb
Created August 29, 2011 05:08
Pulling images from Post Secret
#!/usr/bin/ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'ftools'
doc = Hpricot(open("http://postsecret.blogspot.com/"))
images = []