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
#!/usr/bin/env python | |
""" | |
Very simple HTTP server in python. | |
Usage:: | |
./dummy-web-server.py [<port>] | |
Send a GET request:: | |
curl http://localhost |
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
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer | |
import SocketServer | |
import simplejson | |
import random | |
class S(BaseHTTPRequestHandler): | |
def _set_headers(self): | |
self.send_response(200) | |
self.send_header('Content-type', 'text/html') | |
self.end_headers() |
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
var fs = require('fs'); | |
var stream = require('stream'); | |
var util = require('util'); | |
function virtualStream() { | |
stream.Transform.call(this); | |
this._readableState.objectMode = false; | |
this._writableState.objectMode = true; | |
} |
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
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler | |
from SocketServer import ThreadingMixIn | |
import threading | |
class Handler(BaseHTTPRequestHandler): | |
def do_GET(self): | |
self.send_response(200) | |
self.end_headers() | |
message = threading.currentThread().getName() |
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
<?php | |
if (!isset($_SERVER['PHP_AUTH_USER']) || ($_SERVER['PHP_AUTH_USER'] != 'specialuser') || ($_SERVER['PHP_AUTH_PW'] != 'secretpassword')) { | |
header('WWW-Authenticate: Basic Realm="Secret Stash"'); | |
header('HTTP/1.0 401 Unauthorized'); | |
print('You must provide the proper credentials!'); | |
exit; | |
} else { | |
print('Authenticated!'); | |
} |
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
function ksort(obj){ | |
var keys = Object.keys(obj).sort() | |
, sortedObj = {}; | |
for(var i in keys) { | |
sortedObj[keys[i]] = obj[keys[i]]; | |
} | |
return sortedObj; | |
} |
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
var cluster = require('cluster'); | |
var numCPUs = require('os').cpus().length; | |
var express = require("express"); | |
var app = express(); | |
if (cluster.isMaster) { | |
// Fork workers. | |
for (var i = 0; i < numCPUs; i++) { | |
cluster.fork(); | |
} |
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
var source = '<a href="double-quote test">double-quote test</a>\n' + | |
'<a href=\'single-quote test\'>single-quote test</a>\n' + | |
'<a href=\'single-quote test\'>single-quote test</a>\n' + | |
'<a class="foo" href="leading prop test">\n' + | |
'<a href="trailing prop test" class="foo">\n' + | |
'<a style="bar" link="baz" ' + | |
'name="quux" ' + | |
'href="multiple prop test" class="foo">\n' + | |
'<a class="foo"\n href="inline newline test"\n style="bar"\n >inline newline test</a>' + | |
'<a href=3D"with 3d data double quote"\n style="bar"\n >with 3d data double quote</a>' + |
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
'use strict'; | |
//Reference: https://www.safaribooksonline.com/blog/2013/05/01/using-streams-in-node-js/ | |
var fs = require('fs'); | |
var stream = require('stream'); | |
//var Transform = require('stream').Transform; | |
var mx = {}; | |
mx.bind_helo = '--------sham-----'; | |
var source = fs.createReadStream('/home/sarv/node_modules/smail/s.txt'); |
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
$.extend({ | |
getUrlVars: function () { | |
var vars = {}, hash; | |
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); | |
for (var i = 0; i < hashes.length; i++) { | |
hash = hashes[i].split('='); | |
vars[hash[0]] = hash[1]; | |
} | |
return vars; | |
}, |
OlderNewer