Skip to content

Instantly share code, notes, and snippets.

Avatar

Christian Nelson christiannelson

View GitHub Profile
@christiannelson
christiannelson / commands.sh
Created Mar 29, 2018
Upgrading a Heroku DB
View commands.sh
# The steps for upgrading a Heorku PostgreSQL database.
#
# https://devcenter.heroku.com/articles/upgrading-heroku-postgres-databases
# https://elements.heroku.com/addons/heroku-postgresql
heroku addons:create heroku-postgresql:hobby-basic -r production
heroku pg:info -r production
# Note the database names, we'll call them HEROKU_POSTGRESQL_NEW_URL and HEROKU_POSTGRESQL_OLD_URL
heroku maintenance:on -r production
@christiannelson
christiannelson / c5merge
Last active Mar 23, 2018
A shell script that merges (--no-ff) a feature branch after rebasing it.
View c5merge
#!/bin/sh
# This script captures a series of git commands that emcompass merging a feature into a target branch, like
# development or master. It updates the target branch and rebases the feature before merging with --no-ff.
# The end result is that there's always a merge commit and all of the commits are at the top of the timeline.
# This makes for easier to read git histories, especially with active teams.
# Is this a git repo?
if [[ ! -d .git ]]; then
echo "\nDirectory is not a git repo. Exiting...\n"
View bootstrap.sh
#!/bin/sh
echo "\nBootstrapping this machine...\n"
# Install HomeBrew
# HOMEBREW_PREFIX="/opt/homebrew"
if ! command -v brew >/dev/null; then
echo "- Installing Homebrew..."
@christiannelson
christiannelson / application.rb
Last active Sep 6, 2016
Using PostgreSQL enums with ActiveRecord enums
View application.rb
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module EnumTest
class Application < Rails::Application
@christiannelson
christiannelson / better.rb
Last active Sep 19, 2018
Rails Database Best Practices
View better.rb
class Client < ActiveRecord::Base
has_many :projects
scope :active, -> { where(active: true) }
end
class Project < ActiveRecord::Model
belongs_to :client
scope :active, -> {
View keybase.md

Keybase proof

I hereby claim:

  • I am christiannelson on github.
  • I am xianpants (https://keybase.io/xianpants) on keybase.
  • I have a public key ASDLBvmc60ul0izAzkjTOx1ttbTt3MZ4Nx6jC2q49WPx-Qo

To claim this, I am signing this object:

@christiannelson
christiannelson / steps.sh
Last active Sep 26, 2016
Opinionated instructions for setting up a laptop for development at Carbon Five. Not intended to be run wholesale; read, interpret, tweak (maybe), then run piece by piece.
View steps.sh
# Opinionated instructions for setting up a laptop for development at Carbon Five.
# Not intended to be run wholesale; read, interpret, tweak (maybe), then run piece by piece.
#
# Tested against Yosemite 10.10.
#--------------------------------------
# Install Homebrew.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
@christiannelson
christiannelson / benchmark.md
Last active Aug 29, 2015
Comparing "hello world" in node.js under dokku versus bare metal
View benchmark.md

Dokku vs. Bare Metal

Running on an Aleutia R50 Mini-server with an Intel i3 1.7 Ghz, 16 GB and SSD.

Dokku (docker fronted by nginx)

Running 10s test @ http://node-js-sample.kuju0.carbonfive.com/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
 Latency 6.57ms 2.04ms 26.01ms 81.91%
@christiannelson
christiannelson / new-project-setup.md
Last active Feb 15, 2016
From Nothing to Continuous Deployment in about 10 Minutes
View new-project-setup.md

These instructions walk you through using Raygun to generate a new app, pushing it to GitHub, deploying it to Heroku (two envs: production and acceptance), and setting up continuous integration and deployment using CircleCI. There's a preference for command-line operations when possible.

Prerequisties

  • Homebrew
  • Heroku toolbelt (brew install heroku-toolbelt)
  • Postgres installed (brew install postgres) and running
  • Postgres superuser called 'postgres' (createuser -s postgres)
  • PhantomJS installed (brew install phantomjs)
  • GitHub gem (gem install hub)
@christiannelson
christiannelson / application_controller.rb
Last active Jan 26, 2021
Code samples for a post on the Carbon Emitter (http://blog.carbonfive.com).
View application_controller.rb
class ApplicationController < ActionController::Base
include Pundit
# Verify that controller actions are authorized. Optional, but good.
after_filter :verify_authorized, except: :index
after_filter :verify_policy_scoped, only: :index
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
private