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
var http = require("http") | |
, util = require("sys") // 0.3.x: require("util") | |
, fs = require("fs") | |
, client = http.createClient(80, "example.com") | |
, request = client.request("POST", "/", {"host":"example.com"}) | |
// send body chunks | |
request.write("hello, world") | |
// pump a file through |
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
// database.js | |
sys = require('sys'); | |
var mongo = require('./lib/node-mongodb-native/lib/mongodb'), | |
Connection = mongo.Connection, | |
Server = mongo.Server, | |
BSON = mongo.BSONNative; | |
var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost'; | |
var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? process.env['MONGO_NODE_DRIVER_PORT'] : Connection.DEFAULT_PORT; |
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
require 'benchmark' | |
n = 1_000_000 | |
Benchmark.bmbm do |x| | |
x.report("Double quotes") do | |
n.times do | |
str = "A simple string" | |
end | |
end | |
x.report("Single quotes") do |
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
var form = require('express-form'); | |
validate = form.validator; | |
filter = form.filter; | |
/* setup express server here */ | |
app.get('/', function(req,res){ | |
form( | |
validate('foo').required(); | |
validate('bar').required('a placeholder text for bar', 'a customize error message here'); |
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
// this allows culerity to wait until all ajax requests have finished | |
jQuery(function($) { | |
var original_ajax = $.ajax; | |
var count_down = function(callback) { | |
return function() { | |
try { | |
if(callback) { | |
callback.apply(this, arguments); | |
}; | |
} catch(e) { |
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
/** | |
* SocketManager - Singleton to manage multi-channel socket 'routing', need a way to merge with socket.io so client sessions aren't stored twice in memory, | |
* | |
* Requires Socket.IO-node and Socket.IO client libraries. | |
* | |
* Usage: | |
* in your main app.js file (or whereever you create the server) | |
* | |
* var io = require('socket.io'), | |
* sm = require('socketmanager'); |
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
support-for-ie = true | |
opacity(n) | |
opacity n | |
if support-for-ie | |
filter unquote('progid:DXImageTransform.Microsoft.Alpha(Opacity=' + round(n * 100) + ')') | |
#logo | |
&:hover | |
opacity 0.5 |
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
require 'net/http' | |
require 'uri' | |
# /api/v1/:format/new | |
# /api/v1/:format/gists/:user | |
# /api/v1/:format/:gist_id | |
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'), | |
{ 'files[file1.ab]' => 'CONTNETS', | |
'files[file2.ab]' => 'contents' }) |
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
// path/to/module/debug.js | |
var express = require('express'); | |
exports.diagnostics = function() { | |
var app1 = express.createServer(); | |
app1.configure(function() { | |
this.set('view engine', 'ejs'); | |
this.set('views', __dirname + '/views/app1'); |
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
/** | |
* Module dependencies. | |
*/ | |
var express = require('express'); | |
var app = express.createServer(); | |
function params(req, res, next) { |