Skip to content

Instantly share code, notes, and snippets.

View ahawkins's full-sized avatar
💭
🌈🏄🏼‍♂️🤙🏻

Adam Hawkins ahawkins

💭
🌈🏄🏼‍♂️🤙🏻
View GitHub Profile
@ahawkins
ahawkins / api_controller.rb
Created March 29, 2012 14:13
Basic API style controller for Rails
# A Basic API Controller for Rails
# Handles authentication via Headers, params, and HTTP Auth
# Automatically makes all requests JSON format
#
# Written for production code
# Made public for: http://broadcastingadam.com/2012/03/state_of_rails_apis
#
# Enjoy!
class ApiController < ApplicationController
@ahawkins
ahawkins / assert.sh
Last active March 19, 2021 04:15
stdlib.sh
assert::var() {
if [ -z "${1:-}" ]; then
log::error "Argument required"
return 1
fi
set +u
if [ -z "${!1}" ]; then
log::error "${1} required, nothing given"
return 1
@ahawkins
ahawkins / backpor-cycle-times.rb
Last active June 1, 2020 21:06
Backport Cycle Times
#!/usr/bin/env ruby
# vim: set expandtab sts=2 tw=2 sw=2:
$stdout.sync = true
$stderr.sync = true
require 'octokit'
require 'dalli'
require 'json'
require 'time'
@ahawkins
ahawkins / deploy.rb
Created March 29, 2012 13:59
Deploy script for Heroku apps
#!/usr/bin/env ruby
# This is a basic deploy script for Heroku apps.
# It provides a structure you can use to expand on
# and add your own prereqs and deploy tasks.
#
# It basically ensures that:
# 1. There are no uncommited files
# 2. You can ssh to github
# 3. You can connect to heroku
@ahawkins
ahawkins / create_alarms.sh
Last active January 1, 2019 17:22
Install cron job to report memory utilization to cloudwatch
#!/usr/bin/env bash
set -xeuo pipefail
main() {
# TODO: add all your desired regions here
local -a regions=(ap-south-1)
for region in "${regions[@]}"; do
aws --region "${region}" cloudwatch put-metric-alarm \
@ahawkins
ahawkins / Makefile
Created May 16, 2015 17:20
Example Makefile
RUBY_IMAGE:=$(shell grep FROM Dockerfile | cut -f2 -d' ')
DYNAMODB_IMAGE:=dynamodb:latest # original value ommitted
APP_IMAGE:=inventory_service/app
TAG:=$(shell git rev-parse --short HEAD)
REGISTRY:=example.registry.com # original value omitted
.DEFAULT_GOAL:= build
@ahawkins
ahawkins / config_map.yml
Last active September 4, 2018 06:34
SycllaDB Kubenetes Examples
apiVersion: v1
kind: ConfigMap
metadata:
name: scylla
data:
readiness-probe: |
#!/usr/bin/env bash
set -euo pipefail
@ahawkins
ahawkins / env.js
Last active August 22, 2018 05:29
let AWS = require('aws-sdk');
let DB = require('./db');
class Configuration {
constructor() {
this.bucket = process.env.S3_BUCKET;
}
get dynamoDBclient() {
return new AWS.DynamoDB({
@ahawkins
ahawkins / deployment.yaml
Created May 4, 2017 17:26
kviberg sample deployment template
{{- $stage := .Values.stage }}
{{- range $pod := .Values.topology.pods }}
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: '{{ template "fullname" $ }}-{{ $pod.name | replace "_" "-" }}-{{ $pod.tier }}'
labels:
release: "{{ $.Release.Name }}"
chart: '{{ $.Chart.Name }}-{{ $.Chart.Version | replace "+" "-" }}'
@ahawkins
ahawkins / await-release
Last active February 8, 2018 03:06
Run 7 log analysis and script
#!/usr/bin/env bash
# This script is a workaround for https://github.com/kubernetes/helm/issues/2288.
# helm install --wait should do everything this script does. It should be deleted
# when the bug is fixed.
set -euo pipefail
main() {
local counter=0 release timeout pods