Skip to content

Instantly share code, notes, and snippets.

@charlesdaniel
charlesdaniel / basic_auth_nodejs_test.js
Created January 27, 2012 02:53
Example of HTTP Basic Auth in NodeJS
var http = require('http');
var server = http.createServer(function(req, res) {
// console.log(req); // debug dump the request
// If they pass in a basic auth credential it'll be in a header called "Authorization" (note NodeJS lowercases the names of headers in its request object)
var auth = req.headers['authorization']; // auth is in base64(username:password) so we need to decode the base64
console.log("Authorization Header is: ", auth);
@neilk
neilk / nonBlockingForEach.js
Last active November 25, 2021 11:06
Works a little bit like `Array.prototype.forEach()`, but uses `process.nextTick` to allow other processes to execute. NOTE. This isn't meant to be practical; if you use this in production code you're probably doing it wrong.
/**
* Allow other processes to execute while iterating over
* an array. Useful for large arrays, or long-running processing
*
* @param {Function} fn iterator fed each element of the array.
* @param {Function} next executed when done
*/
Array.prototype.nonBlockingForEach = function(fn, next) {
var arr = this;
var i = 0;

UNINCORPORATED FACTS

  • _tickCallback processes the process.nextCallback queue
  • setTimeout cannot have a timeout smaller than 1
  • domains make changes

Understanding the Node event loop

There are two important things to remember about the Node event loop. The

@tobilg
tobilg / run_multiple_phantomjs_instances.js
Last active December 22, 2015 15:39
Async usage of multiple PhantomJS instances with NodeJS
var phantom = require('phantom');
var async = require('async');
var pagesToCall = [
['http://www.google.com', 8000],
['http://www.allthingsd.com', 8001],
['http://www.wired.com', 8002],
['http://www.mashable.com', 8003],
['http://www.stackoverflow.com', 8004]
];
{
"title": "Apache and Tomcat Logs",
"services": {
"query": {
"list": {
"0": {
"query": "apache !tomcat !static",
"alias": "",
"color": "#7EB26D",
"id": 0,
@Anye
Anye / tengine
Created August 10, 2014 12:01
tengine 启动脚本
#!/bin/bash
#
# Startup script for Nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Tengine is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/tengine/conf/nginx.conf
# pidfile: /usr/local/tengine/logs/nginx.pid
@petitviolet
petitviolet / nginx_deployment.yaml
Created March 11, 2018 11:04
sample Nginx configuration on Kubernetes using ConfigMap to configure nginx.
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
data:
nginx.conf: |
user nginx;
worker_processes 3;
error_log /var/log/nginx/error.log;
events {
@taarimalta
taarimalta / lua_dynamic_module_installation_onto_nginx_centos_7.md
Created January 4, 2020 11:54
Lua dynamic module installation onto Nginx (CentOS 7)