Skip to content

Instantly share code, notes, and snippets.

View adam-singer's full-sized avatar
👾

Adam Singer adam-singer

👾
View GitHub Profile
@iggymacd
iggymacd / FileHandler.dart
Created April 30, 2012 18:39
Sample FileHandler
class FileHandler {
FileHandler(){
}
void onRequest(HttpRequest request, HttpResponse response, [String fileName = null]){
final int BUFFER_SIZE = 4096;
if (fileName == null) {
fileName = request.path.substring(1);
}
@iggymacd
iggymacd / NotFoundHandler.dart
Created April 30, 2012 18:40
Sample NotFound Handler
class NotFoundHandler {
NotFoundHandler(){
}
List<int> _notFoundPage;
static final String notFoundPageHtml = """
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
# So this is completely gone now
# Moved to my own brew recipes collection at
# https://github.com/kevmoo/homebrew-kevmoo
# Run this:
# brew tap kevmoo/kevmoo
# and you'll be good to go!
#import("dart:io");
main(){
int sum = 0;
DirectoryLister lister = new Directory("c:\\dropbox").list(true);
var filesProcessed = new List<Future>();
lister.onError = (e) { throw e; };
lister.onFile = (String file) {
// print("File: $file");
// Please ignore the length() vs lengthSync(), because my
// actual use case is a longer IO operation, e.g. DB call.
@mitsuoka
mitsuoka / MIME.dart
Last active November 11, 2022 12:43
Dart WebSocket chat server and client samples
library MIME;
// get MIME type (returns null if there is no such extension)
String mimeType(String extension) => _mimeMaps[extension];
// default MIME type mappings
Map _mimeMaps = const {
'abs': 'audio/x-mpeg',
'ai': 'application/postscript',
'aif': 'audio/x-aiff',
// Sending futures across isolate boundaries.
#import('dart:isolate', prefix: 'isolate');
// FutureSendPort/FutureReceivePorts are ports for sending and receiving futures
// When connecting futures across isolates boundaries they do it by
// building the following structure:
//
// ISOLATE A
// [Future] --events--> [Completer SendPort]
anonymous
anonymous / sparseintvector2.dart
Created September 3, 2012 12:40
dart sparseintvector new (still 50x slower than java)
#import('dart:math');
class SparseIntVector {
static int collision = 0;
static final int INITIAL_SIZE = 8;
static final double DEFAULT_LOAD_FACTOR = 0.7;
int modulo = INITIAL_SIZE - 1;
List<int> keys;
List<int> values;
@thara
thara / DCI-sample.dart
Last active December 14, 2015 20:38
A simple DCI sample with Mix-in in Dart.
import 'package:unittest/unittest.dart';
import 'dart:async';
main () {
test("DCI sample in Dart", () {
var checking = new Account(balance : 50);
var saving = new Account(balance : 45);
@Swader
Swader / build.dart
Created March 14, 2013 18:25
Recursive folder copy in Dart: An updated Dart web_ui build script which recursively copies a folder and its contents to another location. Useful when building for a defined vhost (e.g. Apache with PHP back end for your Dart app) and don't want the build script to relativize your paths to go "one folder up" back from /out into /web to get CSS an…
import 'dart:io';
import 'package:web_ui/component_build.dart';
// Ref: http://www.dartlang.org/articles/dart-web-components/tools.html
main() {
build(new Options().arguments, ['web/index.html']);
//recursiveFolderCopySync('web/assets', 'web/out/assets');
}
bool isSymlink(String pathString) {
@thara
thara / operator_to_list_by_mixin.dart
Last active December 15, 2015 11:49
Mix-in sample in Dart. I want to make Seq looks like Seq in Scala...
import 'package:unittest/unittest.dart';
void main() {
print("intersect");
(new Seq([1, 2, 3]) & new Seq([2, 3, 4])).forEach(print);
print("union");
(new Seq([1, 2, 3]) | new Seq([2, 3, 4])).forEach(print);