Skip to content

Instantly share code, notes, and snippets.

View tcocca's full-sized avatar

Tom Cocca tcocca

  • Boston Logic Technology Partners, Inc.
  • Boston, MA
View GitHub Profile
require 'spec_helper'
inputs = [:path, :hash, :file, :tempfile, :stringio]
outputs = [:path, :file, :tempfile, :stringio, :nil]
def get_input(input_type, file_name = 'fields.pdf')
case input_type
when :path
path_to_pdf(file_name)
when :hash
class FollowsController < ApplicationController
def create
@followable = find_followable
@follower = find_follower
@follower.follow(@followable)
redirect_to (@followable)
end
def destroy
@tcocca
tcocca / tomcat6
Created February 12, 2011 21:24
/etc/init.d/tomcat6
#!/bin/sh -e
# chkconfig: 345 99 1
# description: Tomcat6 service
# processname: java
# Get LSB functions
. /lib/lsb/init-functions
export JAVA_HOME=/usr
export TOMCAT_USER=solr
SELECT leads.id,
(SELECT COUNT(*) FROM searches WHERE lead_id = leads.id) AS searches_count,
(SELECT COUNT(*) FROM rental_searches WHERE lead_id = leads.id) AS rental_searches_count,
COALESCE((searches_count + rental_searches_count), 0) as total
FROM leads
WHERE leads.id = 35
# Unknown column 'searches_count' in 'field list'
class SearchReport < ActiveRecord::Base
belongs_to :user
belongs_to :report, :polymorphic => true
end
class User < ActiveRecord::Base
...
has_many :search_reports
class SearchDateRange < ActiveRecord::Base
validates_presence_of :name
validates_presence_of :sort_order
def range_start_end
time = Time.zone.now
case self.name
when 'Today'
[time.beginning_of_day, time.end_of_day]
module ThemeMixin
=begin
# Rails only w/ alias_method_chain
def self.included(base)
base.alias_method_chain(:base_method, :override)
end
def base_method_with_override
"theme index"
#file: app/themes/blue/mixins/blue_users_controller_mixin.rb
module BlueUsersControllerMixin
def blue_show
#themed_show method here
end
end
# app/controllers/users_controller.rb
attr_accessor :features_as_hash
def method_missing(method_name, *args, &block)
name = method_name.to_s
if self.respond_to?(name)
super
elsif features_hash.has_key?(name)
return features_hash[name]
else
logger.debug("Attribute #{name} on property #{self.id} does not exist")
map.resources :users do |user|
user.resources :daily_searches
end
map.namespace :admin do |admin|
admin.resources :leads do |lead|
lead.resources :daily_searches
end
end