Skip to content

Instantly share code, notes, and snippets.

View roycrxtw's full-sized avatar

Roy Cooper roycrxtw

  • ViewSonic
  • Taiwan
View GitHub Profile
@lancejpollard
lancejpollard / node-folder-structure-options.md
Created November 28, 2011 01:50
What is your folder-structure preference for a large-scale Node.js project?

What is your folder-structure preference for a large-scale Node.js project?

0: Starting from Rails

This is the reference point. All the other options are based off this.

|-- app
|   |-- controllers
|   |   |-- admin
@DukeyToo
DukeyToo / benchmark.md
Created March 19, 2012 16:42
Benchmarks exploring different patterns of Node.js worker processes on an HTTP server

This set of benchmarks explores the impact on a Node.js HTTP API server when some responses take more cpu than others. The requests are to a JSON page that calculates a random fibonacci sequence between 1 and 30. The server is using node-perfectapi with a feature that scales the http server across available cpus, while leaving the user's API code in the main Node.js process.

In the red series, the http server is running in the same process as the Fibonacci calculations. In the green series, the handling of all of the http web server stuff has been moved to separate node workers. In both cases, the Fibonacci calculations occur in a single thread in the main (master) Node process.

Benchmark showing response time hit

Now obviously the red series is going to be slower than the green series (because it is restricted to a single cpu for both http requests/responses and the calculati

@hectorcorrea
hectorcorrea / webserver.js
Last active November 17, 2022 19:54
web server in node.js
// A very basic web server in node.js
// Stolen from: Node.js for Front-End Developers by Garann Means (p. 9-10)
var port = 8000;
var serverUrl = "127.0.0.1";
var http = require("http");
var path = require("path");
var fs = require("fs");
var checkMimeType = true;
@othiym23
othiym23 / excerpt.js
Created December 1, 2012 00:01
mocha is not your friend if you want to test uncaughtException handlers
before(function (done) {
/**
* Mocha is extremely zealous about trapping errors, and runs each test
* in a try / catch block. To get the exception to propagate out to the
* domain's uncaughtException handler, we need to put the test in an
* asynchronous context and break out of the mocha jail.
*/
process.nextTick(function () {
// disable mocha's error handler
mochaHandler = process.listeners('uncaughtException').pop();
@webdesserts
webdesserts / Gulpfile.js
Last active April 3, 2023 08:16
Automatically reload your node.js app on file change with Gulp (https://github.com/wearefractal/gulp).
// NOTE: I previously suggested doing this through Grunt, but had plenty of problems with
// my set up. Grunt did some weird things with scope, and I ended up using nodemon. This
// setup is now using Gulp. It works exactly how I expect it to and is WAY more concise.
var gulp = require('gulp'),
spawn = require('child_process').spawn,
node;
/**
* $ gulp server
* description: launch the server. If there's a server already running, kill it.
@yorkxin
yorkxin / rfc6750.md
Created September 17, 2013 07:54
RFC 6750 in Markdown - Edited from http://tools.ietf.org/rfc/rfc6750.txt
Internet Engineering Task Force (IETF)                          M. Jones
Request for Comments: 6750                                     Microsoft
Category: Standards Track                                       D. Hardt
ISSN: 2070-1721                                              Independent
                                                            October 2012

The OAuth 2.0 Authorization Framework: Bearer Token Usage

Abstract

@flesch
flesch / basic-auth.js
Last active July 27, 2022 12:39
HTTP Basic Authentication with Express, without express.basicAuth.
var express = require("express");
var app = express();
app.get("/restricted", function(req, res, next){
// Grab the "Authorization" header.
var auth = req.get("authorization");
// On the first request, the "Authorization" header won't exist, so we'll set a Response
// header that prompts the browser to ask for a username and password.
@denji
denji / http-benchmark.md
Last active June 20, 2024 14:22
HTTP(S) Benchmark Tools / Toolkit for testing/debugging HTTP(S) and restAPI (RESTful)
@scari
scari / aws_latency.md
Last active November 25, 2020 04:02
AWS Latency

Disclaimer

This is not an official report nor reliable benchmark. The testing environments are vary. These EC2 latencies are measured by http://aws-latency.altaircp.com/ Thanks to my friends!

If you want to add a result from your location, feel free to comment on this gist. Please note that you need to try it several times to get an accurate result.

Seoul, Korea

Asia Pacific (Seoul)	ap-northeast-2	19ms
Asia Pacific (Tokyo)	ap-northeast-1	92ms
@subfuzion
subfuzion / curl.md
Last active June 22, 2024 13:47
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.