Skip to content

Instantly share code, notes, and snippets.

@xli
xli / writing-great-tests-consistently.md
Last active August 27, 2015 02:43 — forked from searls/writing-great-tests-consistently.md
Talk abstract for fall 2015 (rewritten to fit Ruby conferences more clearly)

Title

How to Start Writing Great Tests—Consistently!

Abstract

Your app is a unique snowflake. Your tests are too… but they shouldn't be!

Years helping teams write better tests has taught me one thing: consistency is crucial. Inconsistent tests slow teams down, wasting time to understand how each test works. Deciding on conventions—even arbitrary ones—can prevent tremendous pain later.

This talk will introduce a ready-to-fork Test Style Guide of carefully-considered rules and templates for Rubyists. You can customize it to fit your preferred tools, too. Soon, you'll be on your way to having more consistent tests that are much more fun to maintain!

@xli
xli / gist:dc9b857be8814d598669
Created April 6, 2015 05:21
upload servercert for cloudfront
export PATH=$PATH:~/Downloads/IAMCli-1.5.0/bin
export AWS_IAM_HOME=~/Downloads/IAMCli-1.5.0
iam-servercertupload --aws-credential-file <credential.csv> -s <sname> -b <ssl.crt.txt> -k <ssl.key.txt> -c intermediate.crt.txt -p /cloudfront/<sname>/
# aws-ruby-sdk v1 API
def s3_multipart_upload_credentials(bucket, key, role_arn)
sts = AWS::STS.new
policy = AWS::STS::Policy.new
policy.allow(:actions => ["s3:PutObject",
"s3:GetObject",
"s3:AbortMultipartUpload",
"s3:ListMultipartUploadParts",
"s3:ListBucketMultipartUploads"],
:resources => "arn:aws:s3:::#{[bucket,key].join('/')}")
@xli
xli / s3-multipart-upload-example-step3.rb
Last active August 29, 2015 14:20
initialize data attributes for EvaporateJS, should output as a HTML tag attributes for JS usage
bucket = <s3 bucket name>
s3key = <s3 file key> # use a random uniq key
{
"data-aws-id" => ENV["S3_MULTIPART_UPLOAD_ACCESS_KEY_ID"],
"data-bucket" => bucket,
"data-key" => s3key,
"data-signer-url" => <your-data-signer-url>
}
@xli
xli / s3-multipart-upload-example-step4.js
Last active August 29, 2015 14:20
setup Evaporate with temp credentials from HTML tag data attributes
// need jQuery and EvaporateJS
var config = $("[data-signer-url]");
var _e_ = new Evaporate({
signerUrl: config.data("signer-url"),
bucket: config.data("bucket"),
aws_key: config.data("aws-id")
});
var configuration = {
name: config.data("key"),
// see EvaporateJS document for other configurations need setup here
@xli
xli / s3-multipart-upload-example-step5.rb
Last active August 29, 2015 14:20
Sign multipart upload request headers string sent by EvaporateJS with s3 multipart upload secret access key generated early
# in a Rails controller action
string_to_sign = params["to_sign"]
encoded = Base64.encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new("sha1"),
ENV["S3_MULTIPART_UPLOAD_SECRET_ACCESS_KEY"],
string_to_sign)).gsub("\n","")
render :text => encoded, :status => 200
@xli
xli / s3-multipart-upload-example-step1.json
Last active August 29, 2015 14:20
Create user and credentials for S3 multipart upload, output credentials for later configuration
"S3UploadUser" : {
"Type" : "AWS::IAM::User",
"Properties" : {
"Path" : "/",
"Policies" : [ {
"PolicyName" : "S3MultipartUpload",
"PolicyDocument" : {
"Version": "2012-10-17",
"Statement" : [ {
"Effect" : "Allow",
@xli
xli / s3-multipart-upload-example-step2.yaml
Last active August 29, 2015 14:21
eb_deployer config, passing s3 upload credentials created in the CloudFormation template to elasticbeanstalk application environment
resources:
template: config/aws_resources.json
capabilities:
- CAPABILITY_IAM
inputs:
DBPassword: <%= ENV.fetch('AWSRESOURCES_DBPassword') %>
outputs:
S3UploadAccessKeyId:
namespace: aws:elasticbeanstalk:application:environment
option_name: S3_MULTIPART_UPLOAD_ACCESS_KEY_ID
@xli
xli / gist:a930b41e5058b9076837
Last active August 29, 2015 14:22
eb_deployer-components-example.yml
components:
- name: bg
strategy: inplace-update
option_settings:
- namespace: aws:autoscaling:asg
option_name: MinSize
value: "1"
- namespace: aws:autoscaling:asg
option_name: MaxSize
value: "1"
@xli
xli / gist:65352c95199e5b51c94f
Last active August 29, 2015 14:22
eb_deployer-environments-config-example.yml
common:
phoenix_mode: true #default to false
environments:
dev:
phoenix_mode: false # turn off for dev env for faster deployment
strategy: inplace-update # default strategy: blue-green
option_settings:
- namespace: aws:elb:loadbalancer
option_name: SSLCertificateId