Skip to content

Instantly share code, notes, and snippets.

View bethesque's full-sized avatar
💭
Intermittently coding

Beth Skurrie bethesque

💭
Intermittently coding
View GitHub Profile
@bethesque
bethesque / bethtest.rb
Last active January 9, 2018 00:28
Making a request to a server with a self signed certificate
require 'openssl'
require 'uri'
require 'net/http'
uri = URI('https://self-signed.badssl.com')
downloaded_cert_path = '/tmp/downloaded_cert.pem'
puts `openssl s_client -showcerts -servername #{uri.host} -connect #{uri.host}:#{uri.port} </dev/null 2>/dev/null|openssl x509 -text`
command = "openssl s_client -showcerts -servername #{uri.host} -connect #{uri.host}:#{uri.port} </dev/null 2>/dev/null|openssl x509 -outform PEM > #{downloaded_cert_path}"
puts command
@bethesque
bethesque / caveats.txt
Last active May 5, 2017 11:40
Moderately dirty hack to order pact versions by date instead of version in the pact broker
This will sort based on the date that the consumer application version resource is created.
If the pact for that version is updated, the sorting will not consider the date of the updated content.
@bethesque
bethesque / reverse_proxy.rb
Created July 8, 2015 02:47
Debug pact-provider-proxy
# pact-provider-proxy/vendor/rack-reverse-proxy/lib/rack/reverse_proxy.rb
require 'net/http'
require 'net/https'
require "rack-proxy"
require "rack/reverse_proxy_matcher"
require "rack/exception"
module Rack
class ReverseProxy
@bethesque
bethesque / hipster-batch-in-ruby.md
Last active May 2, 2016 07:02
A way to write a hipster batch microservice in Ruby
  1. Identify the steps in the high level process

    eg.

    • Step 1: Download CSV files from box
    • Step 2: Convert CSV to JSON
    • Step 3: Upload JSON and CSV files to S3
  2. Create modules for each of those steps. In our use case, the top level process matches a pattern called "ETL" or "Extract, Transform, Load", so we used those names.

@bethesque
bethesque / thoughts.md
Last active January 1, 2016 04:29
Thoughts on flexible matching for Pact

Assumptions based on experience with pacts so for:

  • The most common type of matching that is useful is asserting that:
    • The expected keys are present
    • The values at the actual keys are of the same class (string/number/nil) as the expected values
    • Occasionally we'll want a literal match
    • Occasionally we'll want a regular expresssion
    • Extra keys in a hash are OK for responses but not for requests (following the "be strict with what you send out, be lax with what you accept" principle)
    • Extra items in an array are debatable (extra keys in a hash are generally ignored, however, all items in an array are generally processed, so allowing "unverified" extras to sneak in could be a bad thing. Working out what to do with "extras" is not immediately obvious to me however.)
@bethesque
bethesque / flexible-matching.rb
Last active January 1, 2016 04:29
An idea of what a flexible matching fluent API might look like, and how it could be serialised.
# Notes:
# Headers and status would still be value based matching
# Default to type based matching???
# like(xxx) means xxx and all children would be matched using type based matching
# literal(xxx) means xxx and all children would be matched using exact value matching
# eg(generate, matcher) would be a regular expression match
# each_like([]) would indicate the each element in the array should be like the example given
# A like() could be nested inside a literal() which could be nested inside a like() - at each stage,
# it changes the matching type for all children until it gets switched back.
@bethesque
bethesque / a.md
Last active December 18, 2015 02:59
Ruby pact libraries

https://github.com/realestate-com-au/pact - rpsec specific stuff, top level, executables https://github.com/bethesque/pact-mock_service - standalone, used by javascript, starts up service, listens, writes pact, verification https://github.com/bethesque/pact-support - matching logic, domain objects https://github.com/bethesque/pact-support/blob/master/spec/pact_specification/compliance-2.0.rb - pact specification test, people might want version 3 soonish.

https://github.com/bethesque/pact-mock-service-npm - standalone package using travelling ruby https://github.com/bethesque/pact-mock_service/blob/master/tasks/package.rake - this is the task that builds the packages

https://github.com/DiUS/pact-consumer-js-dsl - the javascript DSL that wraps the ruby or standalone mock server.

@bethesque
bethesque / a.md
Last active November 30, 2015 00:07
DelegatedProperty - flattening model hierarchy - don't expose your model relationships in your form

This allows you do something like:

User = Struct.new(:address)
Address = Struct.new(:street, :suburb)

class UserForm < Reform::Form

  property :address do
 property :street
@bethesque
bethesque / authorise.rb
Created September 14, 2015 22:58
How we currently authorise our Trailblazer operations (pre policy support)
class Thing::Create < Trailblazer::Operation
def process(params)
validate(params[:referral]) do
authorize(params, model, :create?)
form.save
end
end
def setup_model!(params)
@bethesque
bethesque / Gemfile
Last active August 29, 2015 14:19
Write a pact without a consumer
source 'https://rubygems.org'
gem 'pact', '~>1.7.0'