Skip to content

Instantly share code, notes, and snippets.

View chuckbergeron's full-sized avatar
🎯
pooltogether.com

Chuck Bergeron chuckbergeron

🎯
pooltogether.com
View GitHub Profile
@chuckbergeron
chuckbergeron / announcements_controller.rb
Created January 19, 2012 20:58
Append to an array, create the array first if it doesn't already exist
class AnnouncementsController < ApplicationController
# Creates an array (if needed) and stores that array in the session so we know which
# announcements the current_user has seen
#
# @todo: Add test
#
def hide
( session[:announcement_ids] ||= [] ) << params[:id]
@chuckbergeron
chuckbergeron / .bash_profile
Created January 30, 2012 20:46
Add Git branch to terminal (CLI) output
# Customize Prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\[\033[01;30m\]\u@\h\[\033[m\] : \[\033[01;34m\]\w\[\033[m\] \[\033[31m\]\$(parse_git_branch) \[\033[00m\]\$ "
@chuckbergeron
chuckbergeron / ability.rb
Created February 9, 2012 04:04
CanCan is a gobbledigook.
# VERSION 1:
can [ :create, :read, :download ], Attachment do |attachment|
user.can? :read, attachment.attachable
end
can [ :update, :destroy ], Attachment do |attachment|
user.administrator? or attachment.try( :user_id ) == user.id
end
# VERSION 2:
can do |action, subject_class, subject|
@chuckbergeron
chuckbergeron / gist:3645718
Created September 5, 2012 21:57
Tricked Python Lesson. Hijinx!
#Assign `True` or `False` as appropriate on the lines below!
# 17 < 118 % 100
# They're asking for this:
bool_one = True
# I gave them this:
bool_one = 17 < 118 % 100
@chuckbergeron
chuckbergeron / import.rb
Created November 1, 2012 19:19
Simple Import w/ Exceptions
class Import
# Mixins
include ImportExceptions
# 0: is the Film Festival we want to relate to a Tab
# 1: the Regionalmovie ID
attr_accessor :attributes
attr_accessor :regionalmovie
attr_accessor :tab
#! /usr/local/bin/zsh
echo "You probably want to run this from your master branch..."
# Remove any existing LATEST_CHANGES.md files:
rm LATEST_CHANGES.md
# Get the latest tag from the git index
LATEST_TAG=`git describe --abbrev=0`
require 'rubygems'
require 'active_shipping'
include ActiveMerchant::Shipping
####### START: STORE THIS IN A CONFIG FILE
MyApp::Application.config.fedex_credentials = {
account: '1234567890',
password: '1234567890abcdefgh1234567890',
key: '1234567890abcde',
login: '12345678'
4..30.each do |x|
puts x * 2
end
1. Was receiving this strange error:
undefined method 'action_view' for #<Rails::Railtie::Configuration...
Had to add this to the top of `config/application.rb`:
require "action_view/railtie"
2. ActionMailer URL host config not being setup correctly:
config.action_mailer.default_url_options = {host: "s.caliper.io"}
Rails.application.config.action_mailer.default_url_options