Skip to content

Instantly share code, notes, and snippets.

View JamesHarker's full-sized avatar

James Harker JamesHarker

View GitHub Profile
@JamesHarker
JamesHarker / chef_solo_bootstrap.sh
Last active December 14, 2015 16:39 — forked from ryanb/chef_solo_bootstrap.sh
Install Ruby 2.0 & Chef Solo on Ubuntu Server
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz
tar -xvzf ruby-2.0.0-p0.tar.gz
cd ruby-2.0.0-p0/
./configure --prefix=/usr/local
make
make install

WAL-E needs to be installed on all machines, masters and slaves.

How to install WAL-E

Only one machine, the master, writes WAL segments via continuous archiving. The configuration for the master postgresql.conf is:

archive_mode = on
archive_command = 'envdir /etc/wal-e.d/env wal-e wal-push %p'
archive_timeout = 60
@JamesHarker
JamesHarker / gist:6697403
Created September 25, 2013 09:47
CircleCI tweaks for Postgres 9.3
sudo -u postgres sed "$id s/$5433/$5432/" -i /etc/postgresql/9.3/main/postgresql.conf
sudo -u postgres /etc/init.d/postgresql restart
sudo -u postgres createuser ubuntu -s
sudo -u postgres createdb circle_test -O ubuntu
@JamesHarker
JamesHarker / Rakefile
Created February 15, 2014 17:18
Using Postgres Schemas with Rails
tasks = Rake.application.instance_variable_get '@tasks'
tasks.delete 'db:structure:dump'
namespace 'db' do
namespace 'structure' do
task :dump => [:environment, :load_config] do
configuration = ActiveRecord::Tasks::DatabaseTasks.current_config
filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
ENV['PGHOST'] = configuration['host'] if configuration['host']
ENV['PGPORT'] = configuration['port'].to_s if configuration['port']
ENV['PGPASSWORD'] = configuration['password'].to_s if configuration['password']
@JamesHarker
JamesHarker / sidekiq.rb
Created May 1, 2014 18:24
Sidekiq initalizer
Sidekiq.configure_server do |config|
if defined?(ActiveRecord::Base)
config = ActiveRecord::Base.configurations[Rails.env]
config["reaping_frequency"] = ENV["DB_REAP_FREQ"] || 10 # seconds
config["pool"] = ENV["SIDEKIQ_DB_POOL"] || 20
ActiveRecord::Base.establish_connection(config)
end
end
@JamesHarker
JamesHarker / timeslots.sql
Created May 2, 2014 09:45
Calculate Resource Availability by Time Period in Postgres
CREATE TABLE reservations (
start_time timestamp not null,
finish_time timestamp not null,
id serial primary key
);
INSERT INTO reservations (start_time, finish_time)
VALUES ('2014-05-01 09:30:00', '2014-05-01 10:00:00'),
('2014-05-01 10:15:00', '2014-05-01 11:00:00'),
('2014-05-01 11:30:00', '2014-05-01 11:45:00');
@JamesHarker
JamesHarker / Ethnicity-codes.md
Created September 11, 2014 14:07
A list of ethnicity codes used in Dentally
Code Description
01 White British
02 White Irish
03 White Other
04 White and Black Caribbean
05 White and Black African
06 White and Asian
07 Other Mixed Background
08 Asian or Asian British Indian
@JamesHarker
JamesHarker / webhook-signature.rb
Last active November 14, 2024 05:29
Check a Dentally Webhook Signature
# request_signature - the signature from the X-Dentally-Signature header
# request_body - the JSON body of the webhook request
# secret - the secret for the webhook
require "openssl"
digest = OpenSSL::Digest.new("sha256")
calculated_signature = OpenSSL::HMAC.hexdigest(digest, secret, request_body)
if calculated_signature == request_signature
@JamesHarker
JamesHarker / colpik.js
Created March 17, 2020 06:42
colpick Color Picker
/*
colpick Color Picker
Copyright 2013 Jose Vargas. Licensed under GPL license. Based on Stefan Petre's Color Picker www.eyecon.ro, dual licensed under the MIT and GPL licenses
For usage and examples: colpick.com/plugin
*/
(function ($) {
var colpick = function () {
@JamesHarker
JamesHarker / Context.js
Created March 17, 2020 06:44
Javascript context menu
/*
* Context.js
* Copyright Jacob Kelley
* MIT License
*
*/
contextMenu = (function () {
var options = {