batman-rails-flo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/batman-rails-flo.rb +5 -0
- data/lib/batman_rails_flo/railtie.rb +9 -0
- data/lib/batman_rails_flo/tasks.rake +14 -0
- data/lib/batman_rails_flo/version.rb +3 -0
- data/vendor/assets/javascripts/batman_rails_flo/flo_server.js +67 -0
- data/vendor/assets/javascripts/batman_rails_flo/live_reload.js.coffee +129 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/CNAME +1 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/CONTRIBUTING.md +9 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/LICENSE +22 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/README +50 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/bin/cake +7 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/bin/coffee +7 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/browser.js +134 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/cake.js +112 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/coffee-script.js +335 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/command.js +569 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/grammar.js +631 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/helpers.js +252 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/index.js +11 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/lexer.js +926 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/nodes.js +3158 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/optparse.js +139 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/parser.js +724 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/register.js +66 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/repl.js +163 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/rewriter.js +475 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/scope.js +146 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/sourcemap.js +161 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/LICENSE +21 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/examples/pow.js +6 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/index.js +82 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/package.json +34 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/readme.markdown +63 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/chmod.js +38 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/clobber.js +37 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/mkdirp.js +28 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/perm.js +32 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/perm_sync.js +39 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/race.js +41 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/rel.js +32 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/return.js +25 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/return_sync.js +24 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/root.js +18 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/sync.js +32 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/umask.js +28 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/umask_sync.js +32 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/package.json +50 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/register.js +1 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/LICENSE +30 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/PATENTS +23 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/README.md +124 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/bin/flo +26 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/configure.html +57 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/configure.js +205 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/style.css +334 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/connection.js +235 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/devtools.html +12 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/index.js +323 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/logger.js +42 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/logo.png +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/manifest.json +13 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/session.js +305 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/index.js +10 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/lib/flo.js +226 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/lib/server.js +94 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/README.md +66 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/index.js +437 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/LICENSE +23 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/README.md +218 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/minimatch.js +1055 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/CONTRIBUTORS +14 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/LICENSE +23 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/README.md +97 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/lib/lru-cache.js +252 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/package.json +33 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/basic.js +369 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/foreach.js +52 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/memory-leak.js +50 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/LICENSE +27 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/README.md +53 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/bench.js +283 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/package.json +42 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/sigmund.js +39 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/test/basic.js +24 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/package.json +40 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/basic.js +399 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/brace-expand.js +33 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/caching.js +14 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/defaults.js +274 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/extglob-ending-with-state-char.js +8 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/lib/walker.js +111 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/license +13 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/lib/makeerror.js +87 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/lib/tmpl.js +17 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/package.json +31 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/readme.md +10 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/package.json +34 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/readme.md +77 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/package.json +36 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/readme.md +52 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/LICENSE +55 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/main.js +128 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/package.json +34 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/readme.mkd +72 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/d/d/t +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/d/t +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_monitor.js +31 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_monitorRootDirectory.js +28 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_watchTree.js +20 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/package.json +45 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/test/test.js +243 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/CHANGELOG.md +81 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/LICENSE +177 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/Makefile +11 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/README.md +245 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/binding.gyp +14 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Makefile +355 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/linker.lock +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/obj.target/validation/src/validation.o +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/obj.target/xor/src/xor.o +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/validation.node +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/xor.node +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/binding.Makefile +6 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/config.gypi +115 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/gyp-mac-tool +512 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/validation.target.mk +154 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/xor.target.mk +154 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/index.js +1 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/install.js +31 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Constants.js +23 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Deprecation.js +38 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Validation.fallback.js +12 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Validation.js +18 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketClient.js +359 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketConnection.js +717 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketFrame.js +282 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRequest.js +478 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRouter.js +154 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRouterRequest.js +59 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketServer.js +216 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/utils.js +7 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/websocket.js +11 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/xor.fallback.js +13 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/xor.js +18 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/package.json +43 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/src/validation.cc +144 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/src/xor.cpp +86 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/FastBufferList.js +192 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/node-ctype/LICENSE +18 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/node-ctype/ctio-faster.js +1126 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/package.json +25 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/browser_websocket.js +63 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/connection_test.js +57 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/logger_mock.js +15 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/session_test.js +194 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/server/flo_test.js +211 -0
- data/vendor/assets/javascripts/batman_rails_flo/package.json +15 -0
- data/vendor/assets/javascripts/batman_rails_flo/reload_event_handler.js.coffee +56 -0
- metadata +232 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
var test = require('tap').test
|
2
|
+
var LRU = require('../')
|
3
|
+
|
4
|
+
test('forEach', function (t) {
|
5
|
+
var l = new LRU(5)
|
6
|
+
for (var i = 0; i < 10; i ++) {
|
7
|
+
l.set(i.toString(), i.toString(2))
|
8
|
+
}
|
9
|
+
|
10
|
+
var i = 9
|
11
|
+
l.forEach(function (val, key, cache) {
|
12
|
+
t.equal(cache, l)
|
13
|
+
t.equal(key, i.toString())
|
14
|
+
t.equal(val, i.toString(2))
|
15
|
+
i -= 1
|
16
|
+
})
|
17
|
+
|
18
|
+
// get in order of most recently used
|
19
|
+
l.get(6)
|
20
|
+
l.get(8)
|
21
|
+
|
22
|
+
var order = [ 8, 6, 9, 7, 5 ]
|
23
|
+
var i = 0
|
24
|
+
|
25
|
+
l.forEach(function (val, key, cache) {
|
26
|
+
var j = order[i ++]
|
27
|
+
t.equal(cache, l)
|
28
|
+
t.equal(key, j.toString())
|
29
|
+
t.equal(val, j.toString(2))
|
30
|
+
})
|
31
|
+
|
32
|
+
t.end()
|
33
|
+
})
|
34
|
+
|
35
|
+
test('keys() and values()', function (t) {
|
36
|
+
var l = new LRU(5)
|
37
|
+
for (var i = 0; i < 10; i ++) {
|
38
|
+
l.set(i.toString(), i.toString(2))
|
39
|
+
}
|
40
|
+
|
41
|
+
t.similar(l.keys(), ['9', '8', '7', '6', '5'])
|
42
|
+
t.similar(l.values(), ['1001', '1000', '111', '110', '101'])
|
43
|
+
|
44
|
+
// get in order of most recently used
|
45
|
+
l.get(6)
|
46
|
+
l.get(8)
|
47
|
+
|
48
|
+
t.similar(l.keys(), ['8', '6', '9', '7', '5'])
|
49
|
+
t.similar(l.values(), ['1000', '110', '1001', '111', '101'])
|
50
|
+
|
51
|
+
t.end()
|
52
|
+
})
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env node --expose_gc
|
2
|
+
|
3
|
+
var weak = require('weak');
|
4
|
+
var test = require('tap').test
|
5
|
+
var LRU = require('../')
|
6
|
+
var l = new LRU({ max: 10 })
|
7
|
+
var refs = 0
|
8
|
+
function X() {
|
9
|
+
refs ++
|
10
|
+
weak(this, deref)
|
11
|
+
}
|
12
|
+
|
13
|
+
function deref() {
|
14
|
+
refs --
|
15
|
+
}
|
16
|
+
|
17
|
+
test('no leaks', function (t) {
|
18
|
+
// fill up the cache
|
19
|
+
for (var i = 0; i < 100; i++) {
|
20
|
+
l.set(i, new X);
|
21
|
+
// throw some gets in there, too.
|
22
|
+
if (i % 2 === 0)
|
23
|
+
l.get(i / 2)
|
24
|
+
}
|
25
|
+
|
26
|
+
gc()
|
27
|
+
|
28
|
+
var start = process.memoryUsage()
|
29
|
+
|
30
|
+
// capture the memory
|
31
|
+
var startRefs = refs
|
32
|
+
|
33
|
+
// do it again, but more
|
34
|
+
for (var i = 0; i < 10000; i++) {
|
35
|
+
l.set(i, new X);
|
36
|
+
// throw some gets in there, too.
|
37
|
+
if (i % 2 === 0)
|
38
|
+
l.get(i / 2)
|
39
|
+
}
|
40
|
+
|
41
|
+
gc()
|
42
|
+
|
43
|
+
var end = process.memoryUsage()
|
44
|
+
t.equal(refs, startRefs, 'no leaky refs')
|
45
|
+
|
46
|
+
console.error('start: %j\n' +
|
47
|
+
'end: %j', start, end);
|
48
|
+
t.pass();
|
49
|
+
t.end();
|
50
|
+
})
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Copyright (c) Isaac Z. Schlueter ("Author")
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
The BSD License
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions
|
8
|
+
are met:
|
9
|
+
|
10
|
+
1. Redistributions of source code must retain the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer.
|
12
|
+
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer in the
|
15
|
+
documentation and/or other materials provided with the distribution.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
18
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20
|
+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
|
21
|
+
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
22
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
24
|
+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
25
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
26
|
+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
27
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# sigmund
|
2
|
+
|
3
|
+
Quick and dirty signatures for Objects.
|
4
|
+
|
5
|
+
This is like a much faster `deepEquals` comparison, which returns a
|
6
|
+
string key suitable for caches and the like.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
```javascript
|
11
|
+
function doSomething (someObj) {
|
12
|
+
var key = sigmund(someObj, maxDepth) // max depth defaults to 10
|
13
|
+
var cached = cache.get(key)
|
14
|
+
if (cached) return cached)
|
15
|
+
|
16
|
+
var result = expensiveCalculation(someObj)
|
17
|
+
cache.set(key, result)
|
18
|
+
return result
|
19
|
+
}
|
20
|
+
```
|
21
|
+
|
22
|
+
The resulting key will be as unique and reproducible as calling
|
23
|
+
`JSON.stringify` or `util.inspect` on the object, but is much faster.
|
24
|
+
In order to achieve this speed, some differences are glossed over.
|
25
|
+
For example, the object `{0:'foo'}` will be treated identically to the
|
26
|
+
array `['foo']`.
|
27
|
+
|
28
|
+
Also, just as there is no way to summon the soul from the scribblings
|
29
|
+
of a cocain-addled psychoanalyst, there is no way to revive the object
|
30
|
+
from the signature string that sigmund gives you. In fact, it's
|
31
|
+
barely even readable.
|
32
|
+
|
33
|
+
As with `sys.inspect` and `JSON.stringify`, larger objects will
|
34
|
+
produce larger signature strings.
|
35
|
+
|
36
|
+
Because sigmund is a bit less strict than the more thorough
|
37
|
+
alternatives, the strings will be shorter, and also there is a
|
38
|
+
slightly higher chance for collisions. For example, these objects
|
39
|
+
have the same signature:
|
40
|
+
|
41
|
+
var obj1 = {a:'b',c:/def/,g:['h','i',{j:'',k:'l'}]}
|
42
|
+
var obj2 = {a:'b',c:'/def/',g:['h','i','{jkl']}
|
43
|
+
|
44
|
+
Like a good Freudian, sigmund is most effective when you already have
|
45
|
+
some understanding of what you're looking for. It can help you help
|
46
|
+
yourself, but you must be willing to do some work as well.
|
47
|
+
|
48
|
+
Cycles are handled, and cyclical objects are silently omitted (though
|
49
|
+
the key is included in the signature output.)
|
50
|
+
|
51
|
+
The second argument is the maximum depth, which defaults to 10,
|
52
|
+
because that is the maximum object traversal depth covered by most
|
53
|
+
insurance carriers.
|
@@ -0,0 +1,283 @@
|
|
1
|
+
// different ways to id objects
|
2
|
+
// use a req/res pair, since it's crazy deep and cyclical
|
3
|
+
|
4
|
+
// sparseFE10 and sigmund are usually pretty close, which is to be expected,
|
5
|
+
// since they are essentially the same algorithm, except that sigmund handles
|
6
|
+
// regular expression objects properly.
|
7
|
+
|
8
|
+
|
9
|
+
var http = require('http')
|
10
|
+
var util = require('util')
|
11
|
+
var sigmund = require('./sigmund.js')
|
12
|
+
var sreq, sres, creq, cres, test
|
13
|
+
|
14
|
+
http.createServer(function (q, s) {
|
15
|
+
sreq = q
|
16
|
+
sres = s
|
17
|
+
sres.end('ok')
|
18
|
+
this.close(function () { setTimeout(function () {
|
19
|
+
start()
|
20
|
+
}, 200) })
|
21
|
+
}).listen(1337, function () {
|
22
|
+
creq = http.get({ port: 1337 })
|
23
|
+
creq.on('response', function (s) { cres = s })
|
24
|
+
})
|
25
|
+
|
26
|
+
function start () {
|
27
|
+
test = [sreq, sres, creq, cres]
|
28
|
+
// test = sreq
|
29
|
+
// sreq.sres = sres
|
30
|
+
// sreq.creq = creq
|
31
|
+
// sreq.cres = cres
|
32
|
+
|
33
|
+
for (var i in exports.compare) {
|
34
|
+
console.log(i)
|
35
|
+
var hash = exports.compare[i]()
|
36
|
+
console.log(hash)
|
37
|
+
console.log(hash.length)
|
38
|
+
console.log('')
|
39
|
+
}
|
40
|
+
|
41
|
+
require('bench').runMain()
|
42
|
+
}
|
43
|
+
|
44
|
+
function customWs (obj, md, d) {
|
45
|
+
d = d || 0
|
46
|
+
var to = typeof obj
|
47
|
+
if (to === 'undefined' || to === 'function' || to === null) return ''
|
48
|
+
if (d > md || !obj || to !== 'object') return ('' + obj).replace(/[\n ]+/g, '')
|
49
|
+
|
50
|
+
if (Array.isArray(obj)) {
|
51
|
+
return obj.map(function (i, _, __) {
|
52
|
+
return customWs(i, md, d + 1)
|
53
|
+
}).reduce(function (a, b) { return a + b }, '')
|
54
|
+
}
|
55
|
+
|
56
|
+
var keys = Object.keys(obj)
|
57
|
+
return keys.map(function (k, _, __) {
|
58
|
+
return k + ':' + customWs(obj[k], md, d + 1)
|
59
|
+
}).reduce(function (a, b) { return a + b }, '')
|
60
|
+
}
|
61
|
+
|
62
|
+
function custom (obj, md, d) {
|
63
|
+
d = d || 0
|
64
|
+
var to = typeof obj
|
65
|
+
if (to === 'undefined' || to === 'function' || to === null) return ''
|
66
|
+
if (d > md || !obj || to !== 'object') return '' + obj
|
67
|
+
|
68
|
+
if (Array.isArray(obj)) {
|
69
|
+
return obj.map(function (i, _, __) {
|
70
|
+
return custom(i, md, d + 1)
|
71
|
+
}).reduce(function (a, b) { return a + b }, '')
|
72
|
+
}
|
73
|
+
|
74
|
+
var keys = Object.keys(obj)
|
75
|
+
return keys.map(function (k, _, __) {
|
76
|
+
return k + ':' + custom(obj[k], md, d + 1)
|
77
|
+
}).reduce(function (a, b) { return a + b }, '')
|
78
|
+
}
|
79
|
+
|
80
|
+
function sparseFE2 (obj, maxDepth) {
|
81
|
+
var seen = []
|
82
|
+
var soFar = ''
|
83
|
+
function ch (v, depth) {
|
84
|
+
if (depth > maxDepth) return
|
85
|
+
if (typeof v === 'function' || typeof v === 'undefined') return
|
86
|
+
if (typeof v !== 'object' || !v) {
|
87
|
+
soFar += v
|
88
|
+
return
|
89
|
+
}
|
90
|
+
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
91
|
+
seen.push(v)
|
92
|
+
soFar += '{'
|
93
|
+
Object.keys(v).forEach(function (k, _, __) {
|
94
|
+
// pseudo-private values. skip those.
|
95
|
+
if (k.charAt(0) === '_') return
|
96
|
+
var to = typeof v[k]
|
97
|
+
if (to === 'function' || to === 'undefined') return
|
98
|
+
soFar += k + ':'
|
99
|
+
ch(v[k], depth + 1)
|
100
|
+
})
|
101
|
+
soFar += '}'
|
102
|
+
}
|
103
|
+
ch(obj, 0)
|
104
|
+
return soFar
|
105
|
+
}
|
106
|
+
|
107
|
+
function sparseFE (obj, maxDepth) {
|
108
|
+
var seen = []
|
109
|
+
var soFar = ''
|
110
|
+
function ch (v, depth) {
|
111
|
+
if (depth > maxDepth) return
|
112
|
+
if (typeof v === 'function' || typeof v === 'undefined') return
|
113
|
+
if (typeof v !== 'object' || !v) {
|
114
|
+
soFar += v
|
115
|
+
return
|
116
|
+
}
|
117
|
+
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
118
|
+
seen.push(v)
|
119
|
+
soFar += '{'
|
120
|
+
Object.keys(v).forEach(function (k, _, __) {
|
121
|
+
// pseudo-private values. skip those.
|
122
|
+
if (k.charAt(0) === '_') return
|
123
|
+
var to = typeof v[k]
|
124
|
+
if (to === 'function' || to === 'undefined') return
|
125
|
+
soFar += k
|
126
|
+
ch(v[k], depth + 1)
|
127
|
+
})
|
128
|
+
}
|
129
|
+
ch(obj, 0)
|
130
|
+
return soFar
|
131
|
+
}
|
132
|
+
|
133
|
+
function sparse (obj, maxDepth) {
|
134
|
+
var seen = []
|
135
|
+
var soFar = ''
|
136
|
+
function ch (v, depth) {
|
137
|
+
if (depth > maxDepth) return
|
138
|
+
if (typeof v === 'function' || typeof v === 'undefined') return
|
139
|
+
if (typeof v !== 'object' || !v) {
|
140
|
+
soFar += v
|
141
|
+
return
|
142
|
+
}
|
143
|
+
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
144
|
+
seen.push(v)
|
145
|
+
soFar += '{'
|
146
|
+
for (var k in v) {
|
147
|
+
// pseudo-private values. skip those.
|
148
|
+
if (k.charAt(0) === '_') continue
|
149
|
+
var to = typeof v[k]
|
150
|
+
if (to === 'function' || to === 'undefined') continue
|
151
|
+
soFar += k
|
152
|
+
ch(v[k], depth + 1)
|
153
|
+
}
|
154
|
+
}
|
155
|
+
ch(obj, 0)
|
156
|
+
return soFar
|
157
|
+
}
|
158
|
+
|
159
|
+
function noCommas (obj, maxDepth) {
|
160
|
+
var seen = []
|
161
|
+
var soFar = ''
|
162
|
+
function ch (v, depth) {
|
163
|
+
if (depth > maxDepth) return
|
164
|
+
if (typeof v === 'function' || typeof v === 'undefined') return
|
165
|
+
if (typeof v !== 'object' || !v) {
|
166
|
+
soFar += v
|
167
|
+
return
|
168
|
+
}
|
169
|
+
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
170
|
+
seen.push(v)
|
171
|
+
soFar += '{'
|
172
|
+
for (var k in v) {
|
173
|
+
// pseudo-private values. skip those.
|
174
|
+
if (k.charAt(0) === '_') continue
|
175
|
+
var to = typeof v[k]
|
176
|
+
if (to === 'function' || to === 'undefined') continue
|
177
|
+
soFar += k + ':'
|
178
|
+
ch(v[k], depth + 1)
|
179
|
+
}
|
180
|
+
soFar += '}'
|
181
|
+
}
|
182
|
+
ch(obj, 0)
|
183
|
+
return soFar
|
184
|
+
}
|
185
|
+
|
186
|
+
|
187
|
+
function flatten (obj, maxDepth) {
|
188
|
+
var seen = []
|
189
|
+
var soFar = ''
|
190
|
+
function ch (v, depth) {
|
191
|
+
if (depth > maxDepth) return
|
192
|
+
if (typeof v === 'function' || typeof v === 'undefined') return
|
193
|
+
if (typeof v !== 'object' || !v) {
|
194
|
+
soFar += v
|
195
|
+
return
|
196
|
+
}
|
197
|
+
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
198
|
+
seen.push(v)
|
199
|
+
soFar += '{'
|
200
|
+
for (var k in v) {
|
201
|
+
// pseudo-private values. skip those.
|
202
|
+
if (k.charAt(0) === '_') continue
|
203
|
+
var to = typeof v[k]
|
204
|
+
if (to === 'function' || to === 'undefined') continue
|
205
|
+
soFar += k + ':'
|
206
|
+
ch(v[k], depth + 1)
|
207
|
+
soFar += ','
|
208
|
+
}
|
209
|
+
soFar += '}'
|
210
|
+
}
|
211
|
+
ch(obj, 0)
|
212
|
+
return soFar
|
213
|
+
}
|
214
|
+
|
215
|
+
exports.compare =
|
216
|
+
{
|
217
|
+
// 'custom 2': function () {
|
218
|
+
// return custom(test, 2, 0)
|
219
|
+
// },
|
220
|
+
// 'customWs 2': function () {
|
221
|
+
// return customWs(test, 2, 0)
|
222
|
+
// },
|
223
|
+
'JSON.stringify (guarded)': function () {
|
224
|
+
var seen = []
|
225
|
+
return JSON.stringify(test, function (k, v) {
|
226
|
+
if (typeof v !== 'object' || !v) return v
|
227
|
+
if (seen.indexOf(v) !== -1) return undefined
|
228
|
+
seen.push(v)
|
229
|
+
return v
|
230
|
+
})
|
231
|
+
},
|
232
|
+
|
233
|
+
'flatten 10': function () {
|
234
|
+
return flatten(test, 10)
|
235
|
+
},
|
236
|
+
|
237
|
+
// 'flattenFE 10': function () {
|
238
|
+
// return flattenFE(test, 10)
|
239
|
+
// },
|
240
|
+
|
241
|
+
'noCommas 10': function () {
|
242
|
+
return noCommas(test, 10)
|
243
|
+
},
|
244
|
+
|
245
|
+
'sparse 10': function () {
|
246
|
+
return sparse(test, 10)
|
247
|
+
},
|
248
|
+
|
249
|
+
'sparseFE 10': function () {
|
250
|
+
return sparseFE(test, 10)
|
251
|
+
},
|
252
|
+
|
253
|
+
'sparseFE2 10': function () {
|
254
|
+
return sparseFE2(test, 10)
|
255
|
+
},
|
256
|
+
|
257
|
+
sigmund: function() {
|
258
|
+
return sigmund(test, 10)
|
259
|
+
},
|
260
|
+
|
261
|
+
|
262
|
+
// 'util.inspect 1': function () {
|
263
|
+
// return util.inspect(test, false, 1, false)
|
264
|
+
// },
|
265
|
+
// 'util.inspect undefined': function () {
|
266
|
+
// util.inspect(test)
|
267
|
+
// },
|
268
|
+
// 'util.inspect 2': function () {
|
269
|
+
// util.inspect(test, false, 2, false)
|
270
|
+
// },
|
271
|
+
// 'util.inspect 3': function () {
|
272
|
+
// util.inspect(test, false, 3, false)
|
273
|
+
// },
|
274
|
+
// 'util.inspect 4': function () {
|
275
|
+
// util.inspect(test, false, 4, false)
|
276
|
+
// },
|
277
|
+
// 'util.inspect Infinity': function () {
|
278
|
+
// util.inspect(test, false, Infinity, false)
|
279
|
+
// }
|
280
|
+
}
|
281
|
+
|
282
|
+
/** results
|
283
|
+
**/
|