Skip to content

Instantly share code, notes, and snippets.

View pjammer's full-sized avatar

Philip Ingram pjammer

View GitHub Profile
@pjammer
pjammer / eunic
Created February 9, 2012 15:18
i put this into /usr/local/bin/eunic and you can your server using eunic -s && eunic -N
#!/bin/bash
set -u
set -e
#change this below to your actual path. If you another environemnt like staging, fucking change N to -e staging instead.
APP_PATH=/youpath/to/app/root
PID=$APP_PATH/tmp/pids/unicorn.pid
OLD_PID=$APP_PATH/tmp/pids/unicorn.pid.oldbin
UNICORN_COMMAND="unicorn_rails -c $APP_PATH/config/unicorn.rb -D"
while getopts ":nsNr" opt; do
@pjammer
pjammer / partial_init.el
Created July 11, 2011 15:16
how i get el-get working
;; el-get sourcing
(add-to-list 'load-path "~/.emacs.d/el-get")
(require 'el-get)
(setq el-get-sources
'(el-get
package
yasnippet
color-theme
color-theme-ir-black
color-theme-chocolate-rain
@pjammer
pjammer / snippet.rb
Created February 11, 2010 00:33 — forked from seivan/snippet.rb
class Post
has_many :comments
has_many :tags, :as => :taggable
class Comment
belongs_to :post
has_many :tags, :as => :taggable
class Tag
belongs_to :taggable, :polymorphic => true
require 'test_helper'
class AuthenticationTest < ActionController::IntegrationTest
def log_and_say(user, arg)
login_on_admin(user.username, user.password)
assert_content arg
end
test "Login on admin with valid username, password and role" do
user = Factory.build(:user_admin)
log_and_say(user, "Welcome #{user.username}, logged in as #{user.role}")
@pjammer
pjammer / gist:184222
Created September 10, 2009 01:14
Trying to move controller code to model code
#Model Code
def self.calculate_state_revenue(state)
@affiliates = select_state(state) # gets all affiliates from the state
@orders_unpaginated = self.orders
#use inject to add up their order totals.
@state_total = @affiliates.inject {|result, affiilate|
result = @orders_unpaginated.calculate(:sum, "order_total", :conditions => ['affiliate_code = ?', affiliate.affiliate_code])
result
}
#controller method
@affiliates = @shop.affiliates.paginate(:page => params[:page], :order => "id desc", :include => :user)
#view trouble spot
<% for affiliate in @affiliates %>
<tr>
<td><%= link_to affiliate.user.email, admin_affiliate_path(affiliate) %></td>
</tr>
<% end %>