This file contains hidden or 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
# Really, really tiny message bus | |
# Yes, I know it leaks. | |
usig._bus = {} | |
usig.connect = (msg, cb) -> (usig._bus[msg] ?= []).push(cb) | |
usig.signal = (msg, args...) -> | |
cb args... for cb in usig._bus[msg] if usig._bus[msg] |
This file contains hidden or 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
# Edit 1, thx @satyr! | |
groupby = (iter, keyfn) -> | |
grouped = {} | |
(grouped[keyfn e] ?= []).push e for e in iter | |
grouped |
This file contains hidden or 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
repr = (o, depth=0, max=2) -> | |
if depth > max | |
'<..>' | |
else | |
switch typeof o | |
when 'string' then "\"#{o.replace /"/g, '\\"'}\"" | |
when 'function' then 'function' | |
when 'object' | |
if o is null then 'null' | |
if _.isArray o |
This file contains hidden or 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
/* Scaled-down Backbone.js demonstration | |
* By Jacob Oscarson (http://twitter.com/jacob414), 2010 | |
* MIT Licenced, see http://www.opensource.org/licenses/mit-license.php */ | |
$(function() { | |
window.ulog = function(msg) { $('#log').append($('<div>'+msg+'</div>')); } | |
// Faking a little bit of Backbone.sync functionallity | |
Backbone.sync = function(method, model, succeeded) { | |
ulog('<strong>'+method + ":</strong> " + model.get('label')); | |
if(typeof model.cid != 'undefined') { |
NewerOlder