View clear_logs.rb
1 2 3 4 5 6 7 8 9 10
# config/initializers/clear_logs.rb
if Rails.env.development?
MAX_LOG_SIZE = 2.megabytes
 
logs = File.join(Rails.root, 'log', '*.log')
if Dir[logs].any? {|log| File.size?(log).to_i > MAX_LOG_SIZE }
$stdout.puts "Runing rake log:clear"
`rake log:clear`
end
end
View .gitignore_global
1 2 3 4 5 6 7 8 9 10
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
 
# Packages #
View 01_before
1 2 3 4 5 6 7 8 9
$ boom -n 100 -c 30 -h Authorization:"Bearer xxxxxxxxx" http://api.waggram.net/v1/me/feed
100 / 100 Boooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo! 100.00 %
 
Summary:
Total: 3.7877 secs.
Slowest: 2.0238 secs.
Fastest: 0.6192 secs.
Average: 1.0054 secs.
Requests/sec: 26.4014
View unicorn.rb
1 2 3 4 5 6 7 8 9 10
worker_processes 3 # amount of unicorn workers to spin up
timeout 30 # restarts workers that hang for 30 seconds
 
preload_app true
 
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
 
before_fork do |server,worker|
defined?(ActiveRecord::Base) and
View application_helper.rb
1 2 3 4 5 6 7 8
def json_for(target, options = {})
options[:root] = false
options[:scope] ||= current_user
options[:url_options] ||= url_options
serializer = options.delete(:serializer) || target.active_model_serializer
 
serializer.new(target, options).to_json
end
View .gitignore_global
1 2 3 4 5 6 7 8 9 10
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
 
# Packages #
View notifications_worker.rb
1 2 3 4 5 6 7 8 9 10
class NotificationsWorker
include Sidekiq::Worker
sidekiq_options queue: :notification, retry: false
 
def perform(actor_id, user_ids, action, target_type, target_id)
actor = User.find(actor_id)
target = target_type.constantize.find(target_id)
 
notifications = []
ActiveRecord::Base.transaction do
View api_controller.rb
1 2 3 4 5 6 7 8 9 10
# A Basic API Controller for Rails
# Handles authentication via Headers, params, and HTTP Auth
# Automatically makes all requests JSON format
#
# Written for production code
# Made public for: http://broadcastingadam.com/2012/03/state_of_rails_apis
#
# Enjoy!
 
class ApiController < ApplicationController
View reviews_index_query_spec.rb
1 2 3 4 5 6 7 8 9 10
require 'spec_helper'
 
describe ReviewsIndexQuery do
 
let(:user) { create(:user) }
let(:facility) { user.facility }
 
let(:p1) { create(:patient,
facility: facility,
mrn: '111',
View cases_datable.rb
1 2 3 4 5 6 7 8 9 10
def fetch_cases
cases = (admin? || csm?) ? Case : current_user.cases
cases = cases.order("#{sort_column} #{sort_direction}")
cases = cases.recent.pending_first.includes(:entries, :case_type, :user, :client)
cases = cases.page(page).per(per_page)
if search_term.present?
cases = cases.search_for(search_term)
end
 
cases
Something went wrong with that request. Please try again.