Skip to content

Instantly share code, notes, and snippets.

@clarkdave
clarkdave / zombie-post-request.js
Last active August 1, 2019 14:44
How to make arbitrary POST requests using Zombie
var browser = new Browser();
browser.visit('/hello', function() {
// do some checks
// I'm not sure if browser.resources is an official part of the Zombie API (I found it by searching the src)
// so be wary in case it changes
browser.resources.post(
'/authenticate?email=hello@example.com&password=' + auth_token,
@clarkdave
clarkdave / pg_enum.rb
Last active July 18, 2019 15:37
basic support for PostgreSQL Enums in ActiveRecord - to be placed in an initializer
##
# This provides `create_enum` and `drop_enum` methods for migrations, which creates
# a Postgres ENUM type with the provided values.
#
# It'll also dump these into the schema.rb to be loaded into another DB (e.g. rake db:test:load)
#
# In order to reference the new enums as actual types, ActiveRecord needs to know about them, so
# make sure they are all represented in the `types` array below
#
# Then you can reference them in your migrations, e.g.
@clarkdave
clarkdave / pg_interval.rb
Last active July 9, 2019 00:57
Support for PostgreSQL `interval` type in Rails 4. Although ActiveRecord supports `interval` by default, it turns it into a string (and tells Postgres the column is type string, too). This means you don't get any proper interval goodness. By sticking this code into an initialiser, ActiveRecord will create proper `interval` column types in Postgr…
#
# This will force ActiveRecord to create proper `interval` column types in PostgreSQL
#
# def change
# add_column :leases, :period, :interval
# end
#
# This applies to a generated `schema.rb` file too.
#
# No special OID type is applied to an `interval` type. Rails will treat it as a string, although
@clarkdave
clarkdave / ecs-task-events-to-cloudwatch-logs.py
Created June 29, 2017 22:27
(AWS Lambda) Send ECS Task events to CloudWatch Logs
# This lambda function can be linked with CloudWatch events to send Task state changes to
# a CloudWatch Logs stream
#
# This is highly recommended as, in my experience, the API does *NOT* return all state change
# events; this is the only way to reliably see them all
import os
import time
import json
import boto3
@clarkdave
clarkdave / ansible-prestashop.yml
Created April 25, 2014 10:17
(Ansible) Playbook to provision a Ubuntu VM for Prestashop, designed for vagrant
# this will provision a Ubuntu box with a basic lamp stack including a db/user for Prestashop
# it downloads Prestashop 1.5 into /tmp but doesn't install it, although you could quite easily
# extend this playbook to do that as you can run the prestashop installer via the shell
---
- hosts: all
sudo: True
tasks:
- name: apt-get update
command: apt-get update
@clarkdave
clarkdave / multi-line-regex-grep.md
Created April 5, 2018 22:33
multi line regex grep
brew install pcre2

find . -type f | xargs pcregrep -M 'pattern'
@clarkdave
clarkdave / database.rb
Last active March 12, 2018 04:21
A Chef recipe for creating EBS volumes. See: http://clarkdave.net/2013/04/managing-ebs-volumes-with-chef/
# The database recipe should be included by any server running a DB. It creates
# a /data directory and, if on EC2, will mount an EBS volume here
directory '/data' do
mode '0755'
end
if node[:app][:ec2] || node[:cloud][:provider] == 'ec2'
aws = data_bag_item('aws', 'main')
include_recipe 'aws'
@clarkdave
clarkdave / link.md
Last active November 14, 2017 14:01
macOS British PC keyboard layouts
@clarkdave
clarkdave / bootstrap-chef-server-12.sh
Last active June 29, 2017 20:07
[CHEF] Bootstrap a Chef Server 12
#!/bin/bash -ex
# Use this script template to bootstrap a Chef Server (version 12)
#
# - bootstraps the Chef server using chef-solo and the official chef-server cookbook
# (https://github.com/chef-cookbooks/chef-server)
# - uses Lego (acme client) to generate and renew an SSL certificate for the server
# - installs the manage (web ui), push jobs and reporting addons (free for < 25 nodes)
# - configures a few sane defaults (no sign ups from web ui)
#
@clarkdave
clarkdave / keybase.md
Created February 12, 2017 23:28
keybase.md

Keybase proof

I hereby claim:

  • I am clarkdave on github.
  • I am clarkdave (https://keybase.io/clarkdave) on keybase.
  • I have a public key ASAAW7KQ7BqcEQjDD--DhGxAF_Ufz_IT71BmARZuxJotRwo

To claim this, I am signing this object: