Skip to content

Instantly share code, notes, and snippets.

View sethladd's full-sized avatar

Seth Ladd sethladd

View GitHub Profile
@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 = []
@sethladd
sethladd / addgoogleplusonecode.js
Created June 6, 2011 04:12
Tweets +1 Chrome Extension for Google +1 Button and twitter.com
var plusOneScript = document.createElement('script');
plusOneScript.setAttribute("src", "https://apis.google.com/js/plusone.js");
plusOneScript.textContent = '{"parsetags": "explicit"}';
plusOneScript.addEventListener("load", function() {
var script = document.createElement("script");
script.textContent = "var addPlusOne = function(){gapi.plusone.go();setTimeout(addPlusOne, 1000);};setTimeout(addPlusOne, 1000);";
document.body.appendChild(script);
}, false);
document.body.appendChild(plusOneScript);
function Timer() {
this.gameTime = 0;
this.lastTick = 0;
this.maxStep = 0.05;
this.lastTimestamp = 0;
}
Timer.prototype.step = function() {
var current = Date.now();