Skip to content

Instantly share code, notes, and snippets.

View jmervine's full-sized avatar

Joshua Mervine jmervine

View GitHub Profile
type JSONContainer struct {
data []interface{}
}
func (j *JSONContainer) All() (objects []JSONObject) {
for _, v := range j.data {
objects = append(objects, JSONObject{data: v})
}
return
}
@jmervine
jmervine / app.js
Last active August 29, 2015 14:00
// ... app.js ...
//
// In the below examples replace 'development' (and 'production') with
// the actual NODE_ENV passed, for example we use 'dev' for development
// and 'prod' for production.
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
if (process.env.NODE_ENV === 'development') {
@jmervine
jmervine / 1results.md
Last active August 29, 2015 14:00
Pythagorean Triplet - run time of go vs. java vs. node vs. ruby vs. python vs. perl vs. php vs. c++

Pythagorean Triplet

Note: The method used below is very slow, with 1bb iterations when trying to find 1000. For a faster method see: https://gist.github.com/jmervine/b5d985398b3ca7ba16aa (~125k iterations)


A Pythagorean triplet is a set of three natural numbers, a b c, for which,

a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52.

#include <iostream>
#include <math.h>
int sqr(int x) {
return x * x;
}
int p_find_trip(int final_sum) {
int iterations = 0;
int stop = ((final_sum / 2) + 1);
#!/usr/bin/env ruby
require 'httperf'
require 'httperf/parser'
require 'yaml'
require 'pp'
#build test
def test(key)
rate = (@config['connections'] * (@config['tests'][key]['pct'] / 100.0)).round(2)
int = (((rate.to_i < 1) ? 1 : rate.to_i) * @config['duration']).to_i
@jmervine
jmervine / fairlyDeepClone.js
Created July 1, 2014 00:03
fairlyDeepClone ...
//b = JSON.parse(JSON.stringify(a));
function fairlyDeepClone(o) {
if (Array.isArray(o)) {
// handle array
return o.map(function(i) {
return fairlyDeepClone(i);
});
} else if (typeof o === 'object') {
// handle object
###
# Usage:
#
# Download this file and start by running 'make'. Then run
# each target listed, 'make lesson_one', 'make lesson_two',
# etc.
#
introduction:
# Introduction:
@jmervine
jmervine / Dockerfile
Last active August 29, 2015 14:07
Sample Docker Development Host (Ubuntu)
FROM ubuntu
MAINTAINER Joshua Mervine
# Networking
EXPOSE 22
EXPOSE 80
EXPOSE 8080
EXPOSE 3000
@jmervine
jmervine / foo.py
Created October 19, 2014 16:40
httperf.py example
#!/usr/bin/env python
from httperfpy import Httperf
perf = Httperf(server="93.184.216.119", num_conns=10)
perf.parser = True
results = perf.run()
print "connection_rate_per_sec: " + results["connection_rate_per_sec"]
@jmervine
jmervine / catchpoint.js
Created October 22, 2014 18:06
Work in progress, not currently working.
var configurator = require('configurator');
var Base64 = require('urlsafe-base64');
var request = require('request');
var host = 'https://io.catchpoint.com';
var prefix = '/ui/api';
var version = 1;
var config;