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 / alloy_view_helper.js
Last active December 14, 2015 10:49
Add a view at a specific position in a list. Original inspiration: https://gist.github.com/iskugor/1485751.
Alloy.Globals.insertViewAt = function(parent, element, index) {
var children = parent.children.slice(0);
for(var i = 0; i < children.length; ++i){
parent.remove(children[i]);
}
if(index >= 0) {
var tmp = children.slice(0, index);
tmp.push(element);
@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
@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_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 / 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 / add_ssh_key.sh
Last active December 12, 2015 07:28
Add SSH key to server
cat ~/.ssh/id_rsa.pub | ssh username@ip.ad.dr.ess 'cat >> ~/.ssh/authorized_keys'
@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: "jb@johnson.com").should be_valid
@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: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 / 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'