Skip to content

Instantly share code, notes, and snippets.

Christopher Sexton csexton

Block or report user

Report or block csexton

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@csexton
csexton / add_template_data_to_contents.rb
Last active Nov 17, 2016
Migrate url to template_data hstore
View add_template_data_to_contents.rb
class AddTemplateDataToContents < ActiveRecord::Migration[5.0]
def up
add_column :contents, :template_data, :hstore, default: '', null: false
execute <<~END
UPDATE contents
SET template_data = hstore('url', subquery.url)
FROM (SELECT id, url FROM contents) as subquery
WHERE contents.id=subquery.id;
END
remove_column :contents, :url, :string
@csexton
csexton / openssl.cnf
Created Nov 7, 2016
Multi-Domain CSR Config for OpenSSL with Wildcards
View openssl.cnf
#
# OpenSSL example configuration file.
# This is mostly being used for generation of certificate requests.
#
# This definition stops the following lines choking if HOME isn't
# defined.
HOME = .
RANDFILE = $ENV::HOME/.rnd
View deploy-to-chrome-webstore.rb
#!/usr/bin/env ruby
require "net/http"
require "net/https"
require "uri"
require "json"
require "optparse"
require "ostruct"
### What is going on here?
#
View request_spec.rb
require "rails_helper"
RSpec.describe "My Controller Requests", type: :request do
end
@csexton
csexton / wait-for-db
Created Aug 6, 2016
A ruby script that will wait for a port to be connectable on a host, normally used to check if another Docker container has booted up
View wait-for-db
#!/usr/bin/env ruby
require "socket"
require "uri"
if ENV["DATABASE_URL"]
url = URI.parse ENV["DATABASE_URL"]
puts "Waiting for DB on #{url}..."
30.times do
begin
@csexton
csexton / application_controller.rb
Created Jul 28, 2016
OAuth Provider User Cache Key
View application_controller.rb
class ApplicationController < ActionController::Base
before_action :set_radius_user_cache_key
# bunch-o-auth stuff goes here
private
def set_radius_user_cache_key
if current_user
cookies[:_radius_user_cache_key] = { value: current_user.cache_key, domain: :all, tld_length: 2 }
View database_check.rb
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
Script to install ruby on alpine linux, normally as part of a docker image.
View install-ruby-alpine
#!/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 Apr 28, 2016
Rough method used for testing if S3 credentials work
View S3Uploader.swift
// 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 Apr 27, 2016
Heroku Environment CLI Wrapper
View heroku-environments
#!/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:
You can’t perform that action at this time.