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 / cardShuffle.dart
Created January 5, 2012 07:33
A simple card shuffle in Dart
// Example borrowed from http://algs4.cs.princeton.edu/
class cardShuffle {
String _cards;
cardShuffle() {
}
void run() {
_cards = "2C 3C 4C 5C 6C 7C 8C 9C 10C JC QC KC AC " +
@adam-singer
adam-singer / ListExtension.dart
Created January 10, 2012 02:08
Example of a possible extension of List to include a indexesOf method.
class ListExtension {
/**
* Returns a [List] of indexes of the given [element], starting
* the search at index [startIndex] to [endIndex] (exclusive).
* Returns an empty [List] if [element] is not found.
*/
static List<num> indexesOf(List list, Object element, int startIndex, int endIndex) {
List<num> n = new List<num>();
if (startIndex >= list.length) {
@adam-singer
adam-singer / get_and_unpack.sh
Created January 30, 2012 05:33
Get latest bundle of Dart with Dartium for MacOSX
rm -rf dart snapshots &&
mkdir snapshots &&
cd snapshots &&
wget http://gsdview.appspot.com/dart-editor-archive-continuous/latest/dart-editor-macosx.cocoa.x86_64.zip
cd ../ &&
tar -zxvf snapshots/dart-editor-macosx.cocoa.x86_64.zip &&
cd dart &&
echo "./DartEditor.app/Contents/MacOS/DartEditor" > runDartEditor.sh &&
chmod +x runDartEditor.sh &&
cd dart-sdk &&
@adam-singer
adam-singer / Test1.dart
Created February 14, 2012 05:38
minfrog error: field cannot override anything but property
#import('dart:html');
class A {
List _l;
}
class B extends A {
List _l;
}
@adam-singer
adam-singer / DartiumBug.dart
Created February 20, 2012 21:04
Dartium Math.pow not implemented
#import('dart:html');
class DartiumBug {
DartiumBug() {
}
void run() {
num n = Math.pow(10, 4);
write("n = ${n}");
@adam-singer
adam-singer / dartEventsExample.dart
Created February 27, 2012 03:04
Dispatch Event in Dart
#import('dart:html');
class dartEventsExample {
int counter = 0;
dartEventsExample() {
}
void run() {
document.query('#status').on.click.add((var event) {
@adam-singer
adam-singer / SVGSamples.dart
Created February 27, 2012 18:22 — forked from ltackmann/SVGSamples.dart
SVG in Dart
#import('dart:html');
class SVGSamples {
void run() {
drawlines();
}
void drawlines() {
final int maxY = 250;
@adam-singer
adam-singer / HelloIsolate.dart
Created March 14, 2012 03:48
Hello world using new dart:isolate
#!/usr/bin/env dart
#import('dart:isolate', prefix:'isolate');
isolateCode() {
isolate.port.receive((msg, reply) => reply.send("re: $msg"));
}
void main() {
isolate.SendPort sendPort = isolate.spawnFunction(isolateCode);
@adam-singer
adam-singer / ParallelIsolateExample.dart
Created March 14, 2012 06:00
Isolate Wait Then in Dart. Sometimes called Fork/Join
#import('dart:isolate', prefix:'isolate');
costlyQuery() {
isolate.port.receive((msg, reply) => reply.send("costly"));
}
expensiveWork() {
isolate.port.receive((msg, reply) => reply.send("expensive"));
}
@adam-singer
adam-singer / MergeSortIsolateExample.dart
Created March 14, 2012 06:08
Merge Sort Isolate Example
#import('dart:isolate', prefix:'isolate');
List split(List numbers) {
int size = numbers.length;
int middleIndex = (size/2).floor().toInt();
var list1 = numbers.getRange(0, middleIndex);
var list2 = numbers.getRange(middleIndex, size-middleIndex);
return [list1, list2];
}