Skip to content

Instantly share code, notes, and snippets.

View kentquirk's full-sized avatar

Kent Quirk kentquirk

View GitHub Profile
@kentquirk
kentquirk / decodejwt.go
Created November 6, 2015 22:26
Go demonstration of decoding jwt
package main
import (
"bytes"
"crypto"
"crypto/rsa"
"crypto/sha256"
"encoding/base64"
"encoding/binary"
"encoding/json"
@kentquirk
kentquirk / index.html
Last active October 24, 2015 02:07
test of bl.ocks.org
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.chart div {
font: 10px sans-serif;
background-color: green;
text-align: right;
padding: 3px;
margin: 1px;
@kentquirk
kentquirk / composehandlers.go
Created October 19, 2015 21:44
compose handlers in go
// CountRequests is middleware for standard handler functions
func (vc *VascoClient) CountRequests(handler http.HandlerFunc) http.HandlerFunc {
return func(rw http.ResponseWriter, req *http.Request) {
// we use a recorder as our response writer so we can inspect it
recorder := httptest.NewRecorder()
// now call the original handler with our recorder
handler(recorder, req)
// switch on the result
code := recorder.Code
@kentquirk
kentquirk / checktoken.go
Created October 9, 2015 23:03
Check token Golang middleware
// ChkTok is middleware that validates that the required
// security token is present.
func ChkTok(handler http.HandlerFunc) http.HandlerFunc {
return func(rw http.ResponseWriter, req *http.Request) {
sessionid := req.Header.Get(AUTHTOKEN)
if sessionid == "" {
util.WriteNewWebError(rw, http.StatusForbidden, "U-107", "x-anet-token is required.")
return
}
handler(rw, req)
@kentquirk
kentquirk / decodeToken.go
Last active October 9, 2015 20:45
decodeGoogleOAuthToken
// This file isn't really needed but I'm not ready to delete it yet.
package main
import (
"bytes"
"crypto"
"crypto/rsa"
"crypto/sha256"
"encoding/base64"
@kentquirk
kentquirk / sanitize.go
Created September 17, 2015 21:45
SanitizeHTML
// SanitizeHTML strips html tags, replace common entities
func SanitizeHTML(s string) string {
output := ""
// Shortcut strings with no tags in them
if !strings.ContainsAny(s, "<>") {
output = s
} else {
type Data struct {
Data []struct {
Data struct {
Stimulus string `json:"stimulus,omitempty"`
Template string `json:"template,omitempty"`
Type string `json:"type,omitempty"`
Validation struct {
ScoringType string `json:"scoring_type,omitempty"`
ValidResponse struct {
Score int `json:"score,omitempty"`
@kentquirk
kentquirk / addToYour.bash_profile
Last active August 29, 2015 14:21
Bash prompt for displaying git/svn revision info
#################################################################
# Here's a bunch of stuff to do prompts that are sensitive to git and svn
WHT='\e[22;37m'
TEAL='\e[22;36m'
BLK='\e[22;30m'
RED='\e[22;31m'
GRN='\e[22;32m'
YEL='\e[22;33m'
BLU='\e[22;34m'
@kentquirk
kentquirk / .bash_profile
Last active August 29, 2015 14:21
a starter version of .bash_profile for new machines
# this is extra bash stuff to make things easier to manage
shopt -s histappend
HISTFILESIZE=2000
HISTSIZE=1000
export TERM=xterm-256color
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
@kentquirk
kentquirk / Go14MongoVagrant-20150514-0330.sh
Last active August 29, 2015 14:21
Provisioning script for a mongo-backed go server on a vagrant box
#! /bin/bash
# Provisioning script for a mongo-backed go server on a vagrant box
echo "install basic requirements"
apt-get --quiet -y update
DEBIAN_FRONTEND=noninteractive apt-get --quiet -y upgrade
apt-get --quiet -y install build-essential mercurial git curl libssl-dev pkg-config tree mongodb bison make gcc binutils