Skip to content

Instantly share code, notes, and snippets.

View trevmex's full-sized avatar
👨‍👩‍👧‍👦

Trevor Menagh trevmex

👨‍👩‍👧‍👦
View GitHub Profile
# In all comments :stage represents the stage you want to use (i.e. production, staging, etc.)
# Follow these steps AFTER modifying your /etc/apache2/httpd.conf file to add a new rails instance and running `sudo apachectl restart`
# Steps to setup capistrano for the first time:
# - cap :stage deploy:setup # this creates the correct directory tree
# - cap :stage deploy:check # this checks to make sure setup ran
# - cap :stage deploy:update # this updates the server with the app code
# - ssh :user@:main_server # fill in the correct user and server here
# - cd :deploy_to/current # again fill in the correct deploy to dir
# - RAILS_ENV=:stage sudo rake gems:install # this installs gems that need native compiling
class ActiveDirectoryUser
require 'restclient'
@authentication_site = 'https://your_server'
@find_site = 'http://your_server'
@authentication_prefix = '/your_auth_page'
@find_prefix = '/cgi-bin/dscl_search.sh?'
# Returns true if the user has the correct password, false otherwise.
def self.authenticate(login, password)
Factory.define :user , :class => User do |u|
u.add_attribute 'id', 1 # u.id calls the id method of the class instead of assigning an attribute 'id'
u.login "trevor"
end
Factory.define :user , :class => User do |u|
u.sequence(:login) {|l| "user#{l}"}
u.sequence(:persistence_token) {|l| "#{Authlogic::Random.hex_token}"}
end
OK, I figured it out. Dumb mistake: to create an optional format like
you see in `rake routes` as:
classify_user_asset GET /users/:user_id/assets/:id/edit/
class(.:format) {:action=>"classify", :controller=>"assets"}
you would write:
map.with_options :controller => 'assets', :conditions => {:method
=> :get} do |assets|
assets.classify_user_asset '/users/:user_id/assets/:id/edit/
class.:format', :action => 'classify'
module ActiveResource
class Base
# Returns the raw data to display the thumbnail of an Alfresco document
def thumbnail
if self.doclib
begin
Net::HTTP.start(self.class.site.host, self.class.site.port) do |http|
req = Net::HTTP::Get.new(self.doclib, {'Content-Type' => 'image/png'})
req.basic_auth self.class.user, self.class.password
http.request(req).body
@trevmex
trevmex / install_homebrew.rb
Created May 24, 2010 13:02 — forked from mxcl/install_homebrew.markdown
Install in any directory via command line arguments. The default behavior is still intact.
#!/usr/bin/ruby
#
# Download and execute this script in one-line with no temporary files:
#
# ruby -e "$(curl http://gist.github.com/raw/411826/install_homebrew.rb)"
#
#
# 24th May 2010 (trevmex):
# Adapted mxcl's fork: http://gist.github.com/323731
# Changed mxcl's code to include a prefix command line variable to allow
describe "route" do
# explicit listing
specify "days#index" do
route get('/days').should generate 'days#index' # wraps assert_generates
route 'days#index'.should recognize get('/days') # wraps assert_recognizes
end
# combined listing
specify "days#index" do
route get('/days').should be 'days#index' # This is generate and recognize (wraps assert_routing)
describe "routing" do
it "recognizes and generates #index" do
get("/days").should have_routing('days#index')
end
it "generates #index" do
get("/days").should generate('days#index')
end
it "recognizes #index" do
# options_for_select_tag: Create an options string for the Rails select_tag method.
# This is a wrapper for Rails' options_for_select method.
# The options are the same as the Rails select method, but this allows us to use it with the select_tag method.
#
# @param {String[]} container An array of strings representing the list of options.
# @param {String|String[]|Hash} selected_or_options A single value or an array of values that will be selected options in the final output, or a hash of options as follows:<br />
# - :selected - can be a single value or an array of values that will be selected options in the final output.
# - :include_blank - set to true or a prompt string if the first option element of the select element is a blank. Useful if there is not a default value required for the select element.<br />
# - :prompt - set to true or a prompt string. When the select element doesn‘t have a value yet, this prepends an option with a generic prompt — "Please select" — or the given prompt string.<br />
# - :d