Skip to content

Instantly share code, notes, and snippets.

@mlconnor
mlconnor / frontmatter.js
Created January 23, 2015 20:29
A simple front matter (YAML) with Handlebars template. Pass the name of the file into the program.
yaml = require('js-yaml');
fs = require('fs');
Handlebars = require('hbs');
Handlebars.registerHelper("sep", function(options){
if(options.data.last) {
return options.inverse();
} else {
return options.fn();
}
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Updated: 2010/12/05
// License: MIT
//
// Copyright (c) 2010-2013 Diego Perini (http://www.iport.it)
//
// Permission is hereby granted, free of charge, to any person
@mlconnor
mlconnor / app.js
Last active August 29, 2015 14:09
Performance test with node.js
var request = require('request');
var async = require('async');
var url = "...";
var payload = "...";
var calls = [];
var clients = 100;
var callsPerClient = 20;
var thinkTime = 0;
@mlconnor
mlconnor / elastic_beanstalk_external_sessions.md
Created October 17, 2014 20:26
Analaysis and recommendation for externalizing session in Elastic Beanstalk using Tomcat and memcached.

Session Management in an Autoscaling Environment

Problem Statement

User sessions in J2EE and LAMP stacks have traditionally been handled in memory by the application server handling the user request. Because of that, load balancers have been configured to use sticky sessions. By sticky sessions we mean that once the user has visited the site, they will be assigned an app server and will return to that server for subsequent requests. The load balancers typically handle that by referencing the users session cookie.

Elastic cloud environments differ from traditional server configurations in that they have a variable number of servers based on traffic loads whereas traditional configurations had a fixed number of servers. When traffic volumes decline it is necessary to vaporize servers. In doing so, we would lose user sessions (essentially forcing a logout) unless we come up with a new strategy for session management.

A new approach

After much research, it is clear that the best

@mlconnor
mlconnor / self_signed_cert.sh
Created September 19, 2014 20:13
generate self signed cert
openssl genrsa -des3 -out server.key 2048
openssl req -new -key server.key -out server.csr
openssl rsa -in server.key -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
@mlconnor
mlconnor / tomcat_memory.md
Created September 17, 2014 13:57
Memory settings for Java JVM in Amazon Elastic Beanstalk

Elastic Beanstalk Java JVM Settings

Determining the right memory settings (MX & MS) for the JVM is not trivial. If you set memory too low then your machine will trash as it runs out and eventually crash. If you set it too high then other critical processes such as Apache or the OS itself may become memory starved and also cause crashes.

In general, I think it best to set the initial memory setting (MS) to be small, around 200M. The real variable we need to calculate is the limit we will place on JVM memory (MS).

In order to make this determination, we need to calculate a few things such as the memory that Apache and the Linux OS need to operate efficiently.

Apache Memory Needs

@mlconnor
mlconnor / py.txt
Last active August 29, 2015 14:05
Python notes
Good basic intro on types
https://docs.python.org/2/tutorial/introduction.html
https://docs.python.org/2/tutorial/controlflow.html
blocks use : and indent
while a < b:
print a
if x < 0:
@mlconnor
mlconnor / arr2csv.js
Created August 19, 2014 17:52
converts and array of objects into a csv string
function arr2csv(arr) {
var cols = [];
/* get a list of unique columns */
_.each(arr, function(item) {
cols = _.union(_.keys(item), cols);
});
var csvRows = [cols.join("\t")];
for ( var i = 0; i < arr.length; i++ ) {
var row = arr[i];
@mlconnor
mlconnor / depth_breadth.txt
Created August 14, 2014 20:24
depth first search vs breadth first search
list nodes_to_visit = {root};
while( nodes_to_visit isn't empty ) {
currentnode = nodes_to_visit.first();
nodes_to_visit.prepend( currentnode.children );
//do something
}
BFS:
list nodes_to_visit = {root};
@mlconnor
mlconnor / requestjs2curl.js
Last active August 29, 2015 14:05
A quick first pass at turning request.js options object into a curl command. Much work needed here for escaping and edge cases.
function request2Curl(options) {
var tokens = ['curl', '-v', '-k', '-ssl3'];
if ( _.has(options, 'auth') ) {
if ( _.has(options.auth, 'user') ) {
tokens.push('--user', "'" + options.auth.user + ":" + options.auth.pass + "'");
}
}
var isPost = _.has(options, 'method') && options.method.toLowerCase() == 'post';