Skip to content

Instantly share code, notes, and snippets.

class DatabaseCheck
def self.wait_for_connection
self.new.check(10)
end
def check(times)
times.times do
opts = Rails.configuration.database_configuration[Rails.env]
ActiveRecord::Base.establish_connection (opts)
connected = begin
ActiveRecord::Base.connection_pool.with_connection { |con| con.active? }
@csexton
csexton / install-ruby-alpine
Created May 3, 2016 20:20
Script to install ruby on alpine linux, normally as part of a docker image.
#!/bin/sh
RUBY_VERSION=$1
set -e
cd /tmp
wget -O ruby.tar.xz "https://cache.ruby-lang.org/pub/ruby/${RUBY_VERSION%.*}/ruby-$RUBY_VERSION.tar.xz"
tar -xJf ruby.tar.xz
rm ruby.tar.xz
cd "/tmp/ruby-$RUBY_VERSION"
./configure --disable-install-doc
make
@csexton
csexton / S3Uploader.swift
Created April 28, 2016 12:41
Rough method used for testing if S3 credentials work
// In reply to this comment:
// http://www.codeography.com/2016/03/20/signing-aws-api-requests-in-swift.html#comment-2647137142
func test() -> String {
let bodyDigest = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
let url = NSURL(string: "http://\(bucketName!).s3.amazonaws.com")!
let signer = S3V4Signer(accessKey: accessKey!, secretKey: secretKey!, regionName: regionName!)
let headers = signer.signedHeaders(url, bodyDigest: bodyDigest, httpMethod: "GET")
let request = NSMutableURLRequest(URL: url)
@csexton
csexton / heroku-environments
Created April 27, 2016 14:09
Heroku Environment CLI Wrapper
#!/usr/bin/env ruby
# Heroku enviroment helper script
#
# This is to streamline using differnt heroku enviroments from one repo.
# Symlink this file to an envroment name (as set by the git-remote name), then
# when running that symlink the script will look up the name in the git config
# and use that remote as the heroku name.
#
# Setup:
@csexton
csexton / spun-weasels.md
Created March 25, 2016 01:10
Removing ████ Order Num Validation

From: Brian C.

Sent: Friday, March 07, 2008 1:19 AM

To: Shawn B.

Cc: Pete S.; Wyn B.; Chris S.

Subject: Re: Removing ████ Order Num Validation

@csexton
csexton / schedule.md
Last active March 5, 2016 16:10
Ruby Retrocession Schedule March 2016
@csexton
csexton / retrocession.md
Last active February 29, 2016 01:17
Agenda and todos

Retrocession

Agenda

(Send email to Chris, Sean, Tien & Teresa with agenda)

  • Sign in
  • Opening comments
  • Submit topics
  • Vote for topics (should we have a noob track)
@csexton
csexton / AWS4SigningKey.h
Created February 20, 2016 04:24
AWS Version 4 Signing Key in Objective C
#import <Foundation/Foundation.h>
@interface AWS4SigningKey: NSObject
+ (NSString *)getSignatureKey:(NSString *)key
dateStamp:(NSString *)dateStamp
regionName:(NSString *)regionName
serviceName:(NSString *)serviceName;
@end
@csexton
csexton / Dockerfile
Created February 17, 2016 03:38
Minimal Dockerfile for Alpine Linux with configurable ruby helper script
FROM alpine:3.3
MAINTAINER Christopher Sexton <chris@radiusnetworks.com>
ENV RUBY_VERSION 2.3.0
ENV RUBY_DOWNLOAD_SHA1 96e620e38af351c8da63e40cfe217ec79f912ba1
ENV BASE_PACKAGES bash curl gmp git
ENV BUILD_PACKAGES build-base libc-dev linux-headers openssl-dev postgresql-dev libxml2-dev libxslt-dev
RUN apk update && \
@csexton
csexton / Dockerfile
Last active February 17, 2016 02:57
Minimal Dockerfile for Alpine Linux, configurable Ruby version, no build tools, final image size about 200 M.
FROM alpine:3.3
MAINTAINER Christopher Sexton <chris@radiusnetworks.com>
ENV RUBY_VERSION 2.3.0
ENV RUBY_DOWNLOAD_SHA1 96e620e38af351c8da63e40cfe217ec79f912ba1
ENV BASE_PACKAGES bash curl gmp
ENV BUILD_PACKAGES build-base libc-dev linux-headers openssl-dev postgresql-dev libxml2-dev libxslt-dev
# Update and install all of the required packages.