Some exercises from the Falsy Values workshops.
The good parts:
- HTTP server and client in same script
- Express cookies example
- Express routing example
- Express error handling
- Express middlewares example
- Simple HTTP proxy
#!/usr/bin/env node | |
var argv = require('optimist') | |
.usage('Usage: --key=[consumer key] -secret=[consumer secret]') | |
.demand(['key', 'secret']) | |
.argv | |
; | |
var OAuth = require('oauth').OAuth; | |
var Step = require('step'); |
#!/usr/bin/env node | |
var fs = require("fs") | |
, path = require("path") | |
, npm = require("npm") | |
, readJSON = require("npm/utils/read-json"); | |
npm.load(function(){ | |
readJSON(process.argv[2], function(err, data){ | |
if(err) throw err; |
/** | |
* Module dependencies | |
*/ | |
var Vector = require('../public/lib/vector'), | |
_floor = Math.floor; | |
// Target API: | |
// | |
// var s = require('net').createStream(25, 'smtp.example.com'); | |
// s.on('connect', function() { | |
// require('starttls')(s, options, function() { | |
// if (!s.authorized) { | |
// s.destroy(); | |
// return; | |
// } | |
// |
require.extensions[".json"] = function (module, filename) { | |
module.exports = JSON.parse(require("fs").readFileSync(filename, "utf8")) | |
} |
loadSpecs = (paths...) -> | |
# expand all spec paths to full cache busted file paths | |
paths = for path in paths | |
"spec/#{path}_spec.js?#{new Date().getTime()}" | |
# Load the specs with head.js, and start a spec run 1 second after they load. | |
head.js paths..., -> | |
setTimeout -> | |
jasmine.getEnv().addReporter(new jasmine.TrivialReporter()) | |
jasmine.getEnv().execute() |
$.fn.extend | |
myplugin: (options) -> | |
self = $.fn.myplugin | |
opts = $.extend {}, self.default_options, options | |
$(this).each (i, el) -> | |
self.init el, opts | |
self.log el if opts.log | |
$.extend $.fn.myplugin, | |
default_options: |
var fs = require('fs'); | |
var child_process = require('child_process'); | |
var spawn = child_process.spawn; | |
function openEditor(file) { | |
var cp = spawn(process.env.EDITOR, [file], { | |
customFds: [ | |
process.stdin, | |
process.stdout, | |
process.stderr |
namespace = (target, name, block) -> | |
[target, name, block] = [(if typeof exports isnt 'undefined' then exports else window), arguments...] if arguments.length < 3 | |
top = target | |
target = target[item] or= {} for item in name.split '.' | |
block target, top |
Some exercises from the Falsy Values workshops.
The good parts: