Skip to content

Instantly share code, notes, and snippets.

View kfox's full-sized avatar

Kelly Fox kfox

  • Unity Technologies
  • Austin, TX, USA
View GitHub Profile
@kfox
kfox / https.js
Created February 28, 2012 20:42
Node 0.6.11 SSL Handshaking
var fs = require('fs'),
tls = require('tls');
var host = process.argv[2] || '3.0.0.2';
var port = process.argv[3] || 443;
var options = {
key: fs.readFileSync('./certs/serverA_512.key'),
cert: fs.readFileSync('./certs/serverA_512.crt'),
ca: [
@kfox
kfox / sysctl.conf
Created February 29, 2012 17:32
Linux kernel tuning settings for large number of concurrent clients
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
@kfox
kfox / http-cluster.js
Created April 5, 2012 19:48
A clustered HTTP server for HTTP connection testing
var http = require('http'),
cluster = require('cluster');
var numCPUs = require('os').cpus().length;
var host = process.argv[2] || '3.0.0.2';
var port = process.argv[3] || 80;
if (cluster.isMaster) {
// this is the master, so spawn workers
@kfox
kfox / tcpproxy.js
Created April 5, 2012 20:03
A basic TCP proxy written in node.js
var net = require("net");
process.on("uncaughtException", function(error) {
console.error(error);
});
if (process.argv.length != 5) {
console.log("usage: %s <localport> <remotehost> <remoteport>", process.argv[1]);
process.exit();
}
@kfox
kfox / syslogd.js
Last active August 27, 2020 09:49
Simple syslogd server
var dgram = require('dgram');
var host = process.argv[2] || '0.0.0.0';
var port = process.argv[3] || 514;
var server = dgram.createSocket('udp4');
server.on('message', function(msg, rinfo) {
console.log("received: %s from %s:%s", msg, rinfo.address, rinfo.port);
});
@kfox
kfox / kittenproxy.coffee
Last active August 27, 2020 11:08
Cat Attack! coffeescript and node.js
# to run:
# 1. npm install -g coffee-script
# 2. npm install http-proxy
# 3. coffee kittenproxy.coffee
# 4. change browser proxy settings to <thishost>:8080
httpProxy = require("http-proxy")
address = process.argv[2] or "0.0.0.0"
port = process.argv[3] or 8080
@kfox
kfox / forget.sh
Created February 8, 2013 15:45
An easy way to remove old SSH host keys from your ~/.ssh/known_hosts file. Useful if you often re-image systems.
# forget.sh: remove matching lines from ~/.ssh/known_hosts
# usage: forget <hostname|IP|substring> [...]
function forget {
known_hosts=~/.ssh/known_hosts
for host in $*
do
host=$(echo "${host}" | sed -e 's/^ssh:\/\///' -e 's/^.*@//')
line=$(awk '{ print $1 }' ${known_hosts} | grep -n "${host}" | sed 's/:.*$//g' | xargs)
while [ -n "${line}" ]
@kfox
kfox / httpproxy.js
Created July 18, 2013 21:43
Simple HTTP proxy for Node.js v0.10.x
var http = require('http');
var host = process.argv[2] || '127.0.0.1';
var port = process.argv[3] || 8080;
http.createServer( function (req, res) {
var proxy = http.request(req.url, function (proxy_res) {
proxy_res.on('data', function (chunk) {
@kfox
kfox / saveimages.rb
Created August 14, 2013 17:16
A quick Ruby script to download PNG, GIF, or JPEG images from a given URL
#!/usr/bin/env ruby
# usage: saveimages.rb <url>
# locally save all images from a web site
require 'nokogiri'
require 'open-uri'
exit if ARGV[0].nil?
@kfox
kfox / sum_exists.rb
Created March 5, 2014 04:07
Find all number pairs in a Ruby array that add up to a given number
#!/usr/bin/env ruby
numbers = [2, 6, 4, 8, 8, 9]
sum = ARGV.empty? ? 10 : ARGV.first.to_i
def sum_exists(numbers, sum)
Array(numbers).combination(2).find_all { |x, y| x + y == sum } || []
end
result = sum_exists(numbers, sum)