Skip to content

Instantly share code, notes, and snippets.

View adam-singer's full-sized avatar
👾

Adam Singer adam-singer

👾
View GitHub Profile
@adam-singer
adam-singer / sumofsquares.dart
Created March 14, 2012 08:15
Sum of Squares in Dart using a fold function
removeOne(list) { var i = list[0]; list.removeRange(0,1); return i; }
fold(value, f(v, n), List ns){
if (ns.isEmpty()) return value;
return fold(f(value, removeOne(ns)), f, ns);
}
// sum of squares becomes
sumOfSquares(list) => fold(0, (v, n) => v + n * n, list);
@adam-singer
adam-singer / iso.dart
Created March 16, 2012 05:32
Isolate Hangs
#import("dart:isolate");
iso() {
port.receive((msg, reply) {
port.close();
});
}
void main() {
SendPort sp = spawnFunction(iso);
@adam-singer
adam-singer / FruitPage.dart
Created March 21, 2012 04:29
Dart templates now allow nesting
#import('dart:html');
#source('FruitView.dart');
void main() {
List fruits = ['apples', 'oranges', 'bananas'];
Hello hello = new Hello("Bob", fruits);
hello.p.on.click.add((e) => print('clicked on paragraph!'));
document.body.elements.add(hello.root);
}
@adam-singer
adam-singer / socketTest.dart
Created March 24, 2012 22:07
Socket broken in dart bleeding_edge?
#import('dart:io');
main() {
Socket s = new Socket("127.0.0.1", 8888);
print('s = ${s.available()}');
}
/*
From the folllowing build socketTest.dart had no problems running.
@adam-singer
adam-singer / frogTest.dart
Created March 26, 2012 07:33
Dartium reports error on try catch
#import('dart:html');
/*
Internal error: 'file:///Users/adam/Documents/DartEditor/dart/dart-sdk/lib/frog/file_system_dom.dart': Error: line 40 pos 15: type 'e' is not loaded
} catch(e) {
^
$ diff file_system_dom.dart file_system_dom.dart.original
40c40
< } catch(var e) {
---
> } catch(e) {
@adam-singer
adam-singer / CrimsonHttpImportPatch.diff
Created March 31, 2012 23:43
Quick Dart Starter Pack
diff --git a/core/crimson.dart b/core/crimson.dart
index 50c09e1..938c7a8 100644
--- a/core/crimson.dart
+++ b/core/crimson.dart
@@ -6,7 +6,7 @@
#library("crimson:core");
-#import('../../log4dart/LogLib.dart');
+#import('../../log4dart/Lib.dart');
@adam-singer
adam-singer / DartiumUriBug.dart
Created April 2, 2012 04:51
Dartium does not import properly dart:uri
#import('dart:html');
#import('dart:uri');
/*
Cannot load Dart script dart:uri FIXME:1
Failed to load resource dart:uri
*/
class DartiumUriBug {
DartiumUriBug() {
}
@adam-singer
adam-singer / docsGen.dart
Created April 3, 2012 22:50 — forked from pjako/docsGen.dart
Dart Docs generation Script
#import('dart:io');
final String PATH_TO_DARTSDK = "/Users/XYZ/dart-sdk";
final String SUBDIRECTORY = "";
final String LIBRARY_DARTFILE = "XYZ.dart";
@adam-singer
adam-singer / README
Created April 8, 2012 02:30
Local Swarm Patches
Run Patch
@adam-singer
adam-singer / dartIrcbot.dart
Created April 21, 2012 06:18
simple dart bot that joins irc.freenode.net/#dart
#import("dart:io");
#import("dart:utf");
#import('dart:json');
#import('dart:isolate', prefix:'isolate');
String API_KEY = "INSERT_KEY_HERE";
class Bot {
Socket socket;
bool sendNick = true;
String botName = "dartBot";