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
View = require 'express/lib/view' | |
View::lookup = do ({ lookup } = View) -> (path) -> | |
return lookup.call this, path unless Array.isArray @root | |
return abs for root in @root when (abs = lookup.call { root }, path)? | |
### | |
Usage: | |
require 'express-multi-view-directories' | |
app.set 'views', ['...', '...', '...'] |
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
sync = (fn) -> (a..., cb) -> | |
try cb null, fn a... | |
catch e then cb e |
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
Module = require 'module' | |
# native_module isn't public, mock the needed functionality | |
NativeModule = do (natives = Object.keys process.binding 'natives') -> | |
exists: (name) -> name in natives | |
require: require | |
mock = (request, parent, modules) -> | |
return modules[request] if request of modules | |
return NativeModule.require request if NativeModule.exists request |
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
{ "name": "timer-sugar", "version": "0.0.1", "main": "timers.coffee", "license": "BSD" } |
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
module.exports = (req, res, next) -> | |
return do next unless req.is 'text/plain' | |
req.body = '' | |
req.on 'data', (data) -> req.body += data | |
req.on 'end', next |
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
multi = (fn) -> (obj, name, a) -> | |
if a? then fn obj, name, a | |
else fn obj, name_, a_ for name_, a_ of name | |
def = (obj, name, prop) -> | |
prop.configurable ?= true | |
prop.enumerable ?= true | |
Object.defineProperty obj, name, prop | |
module.exports = exports = |
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
# Adds a function as an inline entry to browserify | |
# Useful for short "glue" code that just needs to require a | |
# bounch of things and initilize them. | |
get_proto = Object.getPrototypeOf or (o) -> o.__proto__ | |
count = 0 | |
addCode = (b, fn) -> b.addEntry 'main' + (if ++count > 1 then count else '') + '.js', body: addCode.body fn | |
addCode.body = (fn) -> '(' + fn + ')()' |
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
########## | |
### Moved to https://github.com/shesek/callable-klass | |
########## | |
"use strict" | |
# without strict mode, `this` defaults to window, so `(this?obj)` | |
# would always return window. | |
callable = (ctor) -> |
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
browserify = require 'browserify' | |
client = (mount, fn) -> (browserify { mount }).addEntry 'main.js', body: '(' + fn + ')()' | |
# Usage: | |
app = express() | |
app.use client '/client.js', -> | |
foo = require './foo' | |
bar = require 'bar' | |
foo 123, bar, 456 |
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
# With an helper function: | |
partial = (fn, a...) -> (b...) -> fn a..., b... | |
add_3 = partial add, 3 | |
# With an IIFE: | |
add_3 = do (fn=add, a=3) -> (b...) -> fn a, b... | |
# note: because we know the number of bound arguments at compile-time, the do() IIFE could be | |
# compiled with the exact number of arguments, rather than with a splat. | |
# the do thingy is the same as `add_3 = ( (fn, a) -> (b...) -> fn a, b... ) add, 3` |