This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
encode(cmd, [List args=null]) { | |
StringBuffer sb = new StringBuffer(); | |
sb.add("*${args.length+1}\r\n\$${cmd.length}\r\n${cmd}\r\n"); | |
if (args is List) { | |
args.forEach((parameter) { | |
sb.add("\$${parameter.length}\r\n${parameter}\r\n"); | |
}); | |
} | |
Utils.getLogger().debug("encode = ${sb.toString()}"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import("../lib/redis.dart"); | |
#import("dart:utf"); | |
void main() { | |
String okStr = "+OK"; | |
String getStr = "\$16\r\nmy spaced string\r\n"; | |
String listStr = "*4\r\n\$5\r\nWorld\r\n\$5\r\nHello\r\n\$3\r\nbar\r\n\$3\r\nfoo\r\n"; | |
Utils.setVerboseState(); | |
Decoder decoder = new Decoder(listStr); | |
var i = decoder.decode(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import('dart:io'); | |
main() { | |
/* | |
Create a bad symlink and run 'dart symlinkbug.dart' | |
ln -s /usr/local/doesnotexist badlink | |
*/ | |
var files = []; | |
var dirs = []; | |
var d = new Directory("/tmp"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import("dart:isolate"); | |
#import('../../mongo-dart/lib/mongo.dart'); | |
/* | |
1) Clone the mongo dart project and reference the correct import location | |
2) dart test_isolate.dart | |
13:37:00-adam@Adams-MacBook-Air:~/dart/test | |
$ dart test_isolate.dart | |
enter find | |
Illegal instruction: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reference: http://en.wikipedia.org/wiki/Visitor_pattern | |
interface CarElementVisitor { | |
void visitWheel(Wheel wheel); | |
void visitEngine(Engine engine); | |
void visitBody(Body body); | |
void visitCar(Car car); | |
} | |
interface CarElement { | |
void accept(CarElementVisitor visitor); // CarElements have to provide accept(). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://goo.gl/xDA15 | |
I don't like nesting either, but I think trying to hide your flow control by writing a branching set of logic as a 'pipeline' is a mistake. | |
I would refactor into methods, like this (again, guessing at what you're trying to do): | |
main() => getEntries("wibble.txt"); | |
/// Reads the files listed in [filename] and returns their contents as strings | |
/// or null if [filename] doesn't exist | |
Future<List<String>> getEntries(String filename) { | |
final file = new File(filename); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import('dart:core'); | |
class FannkuchreduxTest { | |
static int fannkuchredux(int n) { | |
var perm = new List(n); | |
var perm1 = new List(n); | |
var count = new List(n); | |
int maxFlipsCount = 0; | |
int permCount = 0; |