Skip to content

Instantly share code, notes, and snippets.

View scottsbaldwin's full-sized avatar

Scott Baldwin scottsbaldwin

View GitHub Profile
@scottsbaldwin
scottsbaldwin / gist:4710300
Last active December 12, 2015 03:58
go-server-12.4.1 .deb install output
# dpkg -i installs Go server, then opens the HTTP/HTTPS ports and sits listening
# That means the install never finishes
$ sudo dpkg -i /usr/local/go/go-server-12.4.1-16091.deb
(Reading database ... 79681 files and directories currently installed.)
Preparing to replace go-server 12.4.1-16091 (using .../go/go-server-12.4.1-16091.deb) ...
Go is not running
Go is not running
Unpacking replacement go-server ...
Setting up go-server (12.4.1-16091) ...
Installation of Go Server completed.
@scottsbaldwin
scottsbaldwin / proxy.js
Last active December 11, 2015 22:09
Node.js proxy from https to http
var https = require('https')
, httpProxy = require('http-proxy')
, fs = require('fs');
// The IP for the proxy to listen on
var listenHost = '192.168.0.3';
// The port for the proxy to listen on
var listenPort = 8443;
var proxy = new httpProxy.RoutingProxy();
@scottsbaldwin
scottsbaldwin / PdfForm.java
Created January 8, 2013 22:38
Set form fields in a PDF document
package com.pfc.pdf;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
@scottsbaldwin
scottsbaldwin / ga_cookies.md
Last active December 10, 2015 15:59
Google Analytics Cookie Explanation

utma

Example: 229903965.679614079.1331659905.1357320260.1357323396.164

__utma = A.B.C.D.E.F, where:
    A: domain hash
    B: random unique ID
    C: time of initial visit (epoch)
    D: beginning of previous session (epoch)

E: beginning of current session (epoch)

@scottsbaldwin
scottsbaldwin / index.html
Created November 26, 2012 17:13 — forked from battlehorse/index.html
Demo script to convert Google Chart Tools charts into PNG images.
<html>
<head>
<script type="text/javascript" src="http://canvg.googlecode.com/svn/trunk/rgbcolor.js"></script>
<script type="text/javascript" src="http://canvg.googlecode.com/svn/trunk/canvg.js"></script>
<script>
function getImgData(chartContainer) {
var chartArea = chartContainer.getElementsByTagName('iframe')[0].
contentDocument.getElementById('chartArea');
var svg = chartArea.innerHTML;
var doc = chartContainer.ownerDocument;
@scottsbaldwin
scottsbaldwin / ubuntu12.04-gems-ruby1.9.1.erb
Created September 18, 2012 21:26
Chef bootstrap template for ruby 1.9.3 on ubuntu 12.04
bash -c '
<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
if [ ! -f /usr/bin/chef-client ]; then
aptitude update
aptitude install -y ruby1.9.1 ruby1.9.1-dev wget libruby1.9.1 rubygems \
irb1.9.1 ri1.9.1 rdoc1.9.1 \
build-essential libopenssl-ruby1.9.1 libssl-dev zlib1g-dev
update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 20 \
--slave /usr/share/man/man1/ruby.1.gz ruby.1.gz \
@scottsbaldwin
scottsbaldwin / keytool.rb
Created May 23, 2012 20:29 — forked from lusis/keytool.rb
recipe for adding certs to keytool
keystore = "/etc/java-6-sun/security/cacerts"
keystore_pass = "foobar"
# you'll need foo.cert et. al. in files/default
certs = %w{foo bar bang}
certs.each do |cert|
cookbook_file "#{Chef::Config[:file_cache_path]}/#{cert}.cert" do
source "#{cert}.cert"
end
@scottsbaldwin
scottsbaldwin / version_set.rb
Created March 12, 2012 21:41
knife plugin to set data bag attribute
# This knife plugin provides the capability to set an attribute
# value in a data bag item. By default the 'versions' data bag
# is used, but that can be overridden with the -b option.
# Copy this file to ~/.chef/plugins/knife to install the plugin.
module KnifePlugins
class DataBagVersionSet < Chef::Knife
deps do
require 'chef/data_bag'
end
@scottsbaldwin
scottsbaldwin / enumextensions.rb
Created February 8, 2012 22:41
Ruby enumerable module for stats
module Enumerable
# sum of an array of numbers
def sum
return self.reduce(:+)
end
# the mean/average of an array of numbers
def average
return self.sum / self.length.to_f
end
@scottsbaldwin
scottsbaldwin / pipelinecause-simple.rb
Created February 6, 2012 16:36
Go Pipeline Cause - Simplified (no materials check)
# Based on feedback from the Go development team:
# url = "#{ENV['GO_SERVER_URL']}pipelines/#{ENV['GO_PIPELINE_NAME']}/#{ENV['GO_PIPELINE_COUNTER']}/#{ENV['GO_STAGE_NAME']}/#{ENV['GO_STAGE_COUNTER']}.xml"
# and lookup //approvedBy/text()
require 'rexml/document'
require 'net/http'
require 'time'
include REXML