Skip to content

Instantly share code, notes, and snippets.

View RichardCochrane's full-sized avatar

Richard Cochrane RichardCochrane

  • Siyavula
  • Cape Town
View GitHub Profile
@RichardCochrane
RichardCochrane / gist:c536387757b2e92489ae
Created January 11, 2016 14:34
Git Prompt (Python coding) for Zsh
# Change this to reflect your installation directory
export __GIT_PROMPT_DIR=~/.oh-my-zsh/plugins/git-prompt
# Initialize colors.
autoload -U colors
colors
# Allow for functions in the prompt.
setopt PROMPT_SUBST
@RichardCochrane
RichardCochrane / gist:1a581e372710199bdbd1
Created January 11, 2016 14:30
Git Prompt (Python coding)
BLACK="\[\033[0;30m\]"
BLUE="\[\033[0;34m\]"
BROWN="\[\033[0;33m\]"
CYAN="\[\033[0;36m\]"
GREEN="\[\033[0;32m\]"
GRAY="\[\033[0;37m\]"
LIGHT_GREEN="\[\033[1;32m\]"
LIGHT_GRAY="\[\033[1;37m\]"
LIGHT_RED="\[\033[1;31m\]"
PURPLE="\[\033[0;35m\]"
@RichardCochrane
RichardCochrane / gist:438fefa6cbab3c35c28a
Created November 11, 2014 12:10
Mandrill Authentication
# provided_signature = request.headers['X-Mandrill-Signature']
provided_signature = '6jRJslRfT0Bx4N+X+6iQGEbpYp8='
# 6jRJslRfT0Bx4N+X+6iQGEbpYp8= (as can be seen in the request bin)
# Params from the request bin formatted for Ruby. I've made all numbers
# strings here, but this doesn't work whether or not they're strings or numbers.
post_params = {
'mandrill_events' => [{
"event" => "send",
"msg" => {
@RichardCochrane
RichardCochrane / gist:18b100c72246dbcd3541
Created October 2, 2014 05:45
Supplier Management System API Authentication (Python)
# Sample values
url = "/api/suppliers"
params = {"trading_name": "Joe's Widgets", "registration_number": 123}
api_key = '123' # Your private API key
required_folds = 3 # The number of times to re-encrypt the data
# The calculation itself
import hmac
import hashlib
import base64
@RichardCochrane
RichardCochrane / gist:10c93a88d1325eaec775
Last active August 29, 2015 14:07
Supplier Management System API Authentication (Ruby)
# Sample values
url = "/api/suppliers"
params = {"trading_name" => "Joe's Widgets", "registration_number" => 123}
api_key = '123' # Your private API key
required_folds = 3 # The number of times to re-encrypt the data
# The calculation itself
flattened_parameters = params.sort.map { |pair| "#{ pair[0] }=#{ pair[1] }" }
# ["registration_number=123", "trading_name=Joe's Widgets"]
@RichardCochrane
RichardCochrane / gist:f65ba3140a7d4b4bcb2a
Last active August 29, 2015 14:06
Ducky Duck (Version 2)
require 'time'
class QuackAnalysis
attr_reader :quacks
attr_accessor :distress_calls
def initialize(raw_quacks)
@quacks = sorted_quacks(raw_quacks)
@distress_calls = {}
identify_distress_calls
require 'time'
class QuackAnalysis
attr_reader :quacks
attr_accessor :distress_calls
def initialize(raw_quacks)
@quacks = sorted_quacks(raw_quacks)
@distress_calls = {}
identify_distress_calls