Skip to content

Instantly share code, notes, and snippets.

View johncblandii's full-sized avatar
🚢
Ready to ship.

John C. Bland II johncblandii

🚢
Ready to ship.
View GitHub Profile
@johncblandii
johncblandii / gist:1947754
Created March 1, 2012 06:22
form_for failing
This fails to output the <form>.
<div>
<h2>Sign Up</h2> Already a user? <%= link_to "Sign In Here", signin_path %>
</div
<%= form_for @u do |f| %>
...form fields here...
<% end %>
@johncblandii
johncblandii / gist:1962769
Created March 3, 2012 00:14
Acceptance issues
//Model - acknowledges validation but never approves it
validates :agreed_to_terms, :acceptance => true, :allow_nil => false
//Model - completely ignores validation
validates :agreed_to_terms, :acceptance => true
//Full Model
class User < ActiveRecord::Base
self.table_name = 'users'
@johncblandii
johncblandii / gist:2152420
Created March 21, 2012 20:16
Need factory to auto-create an invitation
#USER MODEL [just the relevant parts]
has_many :sent_invitations, :class_name=>"Invitation", :foreign_key=>:sender_id
validate :check_for_invitation, :on=>:create
private
def check_for_invitation
errors.add :email, 'has not been invited' unless Gxtended::Invitation.where(:recipient_email=>email).exists?
end
#INVITATION MODEL
@johncblandii
johncblandii / leaderboard.rb
Created April 27, 2012 18:18
Leaderboard initializer
begin
rails_env = Rails.env
# Load the redis.yml configuration file
redis_config = YAML.load_file(Rails.root + 'config/leaderboard_redis.yml')[rails_env]
# Connect to Redis using the redis_config host and port
if redis_config
redis = Redis.new(host: redis_config['host'], port: redis_config['port'])
redis_options = {:redis_connection => redis}
HIGHSCORE_LB = Leaderboard.new('highscores', Leaderboard::DEFAULT_OPTIONS, redis_options)
@johncblandii
johncblandii / gist:4728284
Created February 7, 2013 03:48
Account Model Rspec Validations
require 'spec_helper'
describe Account do
context "#validations" do
it{ FactoryGirl.build(:account).should be_valid }
it{ FactoryGirl.build(:account, name: "").should be_invalid }
it{
FactoryGirl.build(:account, contact_email: "[email protected]").should be_valid
@johncblandii
johncblandii / add_ssh_key.sh
Last active December 12, 2015 07:28
Add SSH key to server
cat ~/.ssh/id_rsa.pub | ssh [email protected] 'cat >> ~/.ssh/authorized_keys'
@johncblandii
johncblandii / gist:4742767
Created February 8, 2013 23:19
Getting a list of available user types by a users type
class User
def user_type
"system_admin"
end
def self.user_types_for user
types = []
case user.user_type
when "system_admin"
types << "system_admin"
@johncblandii
johncblandii / unicorn_init.erb
Last active December 12, 2015 10:09
Unicorn shell script template used in Capistrano: https://gist.github.com/johncblandii/4757771.
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
### END INIT INFO
@johncblandii
johncblandii / unicorn.rb
Created February 11, 2013 21:26
Unicorn deployment file for Capistrano
set_default(:unicorn_user) { user }
set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
set_default(:unicorn_config) { "#{shared_path}/config/unicorn.rb" }
set_default(:unicorn_log) { "#{shared_path}/log/unicorn.log" }
set_default(:unicorn_workers, 2)
namespace :unicorn do
desc "Setup Unicorn initializer and app configuration"
task :setup, roles: :app do
run "mkdir -p #{shared_path}/config"
@johncblandii
johncblandii / unicorn.rb.erb
Created February 11, 2013 21:27
Unicorn config file used by an init script: https://gist.github.com/johncblandii/4757034.
working_directory "<%= current_path %>"
pid "<%= unicorn_pid %>"
stderr_path "<%= unicorn_log %>"
stdout_path "<%= unicorn_log %>"
listen "/tmp/unicorn.<%= application %>.sock"
worker_processes <%= unicorn_workers %>
timeout 30
preload_app true