Skip to content

Instantly share code, notes, and snippets.

View mrajagopal's full-sized avatar
😀

Madhu Rajagopal mrajagopal

😀
  • Auckland, NZ
View GitHub Profile
@mrajagopal
mrajagopal / bundle.js
Created May 11, 2021 23:01 — forked from jackgill/bundle.js
A node.js script to create a bundle containing an npm package, and all of its dependencies.
/*
* This script will download a package (and all of its dependencies) from the
* online NPM registry, then create a gzip'd tarball containing that package
* and all of its dependencies. This archive can then be copied to a machine
* without internet access and installed using npm.
*
* The idea is pretty simple:
* - npm install [package]
* - rewrite [package]/package.json to copy dependencies to bundleDependencies
* - npm pack [package]
@mrajagopal
mrajagopal / http_request_generator.js
Created December 15, 2014 22:03
HTTP request generator
"use script";
var http = require(http);
var request_count = 10;
var options = {
hostname: '192.0.2.1'
port: 80,
method: 'GET',
path: '/'
@mrajagopal
mrajagopal / response_header_modifier.js
Last active August 23, 2016 02:48
LineRate's Node.js script to modify the HTTP response header
"use strict";
var vsm = require('lrs/virtualServerModule');
var requestHandler = function(servReq, servResp, next){
servReq.on('response', function responseHandler(cliResp){
cliResp.bindHeaders(servResp);
servResp.removeHeader("Server");
servResp.removeHeader("X-Powered-By");
@mrajagopal
mrajagopal / url-parser.js
Last active August 29, 2015 14:08
URL parsing
"use strict";
var vsm = require('lrs/VirtualServerModule');
var urlm = require('url');
var cookie = require('cookie');
function onClientReq(servReq, servResp, next) {
var url = urlm.parse(servReq.url);
if (url.hostname == 'example.com')
{
@mrajagopal
mrajagopal / bunyan-log.js
Created October 29, 2014 03:43
LineRate snippet: Request Logging with Bunyan
"use strict";
var vsm = require('lrs/virtualServerModule');
var bunyan = require('bunyan');
// Function to return required fields from the request object
function reqSerializer(req) {
return {
method: req.method,
url: req.url,
headers: req.headers.host
@mrajagopal
mrajagopal / parental-control.js
Created October 28, 2014 22:44
Node.js script utilizing Google's safe-browse API
"use strict";
safeBrowse = require('safe-browse');
var safeBrowseApi = new safeBrowse.Api(AIzaSyA0do0yx2CP786Ex31THcjNRkuuIdtL5wg, options);
safeBrowseApi.lookup('http://twitter.com')
.on('success', function (data) {
})
//********************************************************************************************************************************
// Description: HTTP redirection in a forward-proxy context. A forward-proxy is useful for filter connections
// particularly outbound to the internet for clients sitting behind a firewall for example.
// In this example below, any user HTTP request from clients results in a redirection
// to the specified site (in this case a bland example.com site). More sophistication can be added
// like a login page for authenticating outbound/internet access and other IT policy enforcement.
"use strict";
var fpm = require('lrs/forwardProxyModule');
@mrajagopal
mrajagopal / fproxy-redirect.js
Last active August 29, 2015 14:08
LineRate snippet: Forward Proxy HTTP redirect
/*************************************************************************************************
* Description:
* HTTP redirection in a forward-proxy context. A forward-proxy is useful for filter
* connections particularly outbound to the internet for clients sitting behind a
* firewall for example. In this example below, any user HTTP request from clients
* results in a redirection to the specified site (in this case a bland example.com site).
* More sophistication can be added like a login page for authenticating outbound/internet
* access and other enterprise policy enforcement.
*/