Skip to content

Instantly share code, notes, and snippets.

View adam-singer's full-sized avatar
👾

Adam Singer adam-singer

👾
View GitHub Profile
@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',
#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.
# 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!
@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>
@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);
}
@greenido
greenido / DartCrawlerExample.dart
Created April 28, 2012 08:00
Dart Crawler (server side example)
#import('dart:io');
#import('dart:uri');
#import('dart:json');
// Dart Hackathon TLV 2012
//
// A simple example to fetch JSON and parse it on the server side
// This is a good start for a crawler and/or any other web service
// we wish to create using dart on the server side.
//
@atebitftw
atebitftw / Dart_Singleton_Maybe
Created April 26, 2012 20:54
Dart Singleton?
class MyClass{
static MyClass _ref;
static MyClass get context() => _ref == null ? new MyClass() : _ref;
factory MyClass(){
if (_ref != null) return _ref;
_ref = new MyClass._internal();
@pjako
pjako / docsGen.dart
Created April 3, 2012 13:05
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";
@d2m
d2m / gist:1935339
Created February 28, 2012 21:42
dart document.cookie lib
/*
* dart document.cookie lib
*
* ported from
* http://www.quirksmode.org/js/cookies.html
*
*/
void createCookie(String name, String value, int days) {
String expires;
@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) {