Skip to content

Instantly share code, notes, and snippets.

View gregblake's full-sized avatar
👨‍💻

Greg Blake gregblake

👨‍💻
View GitHub Profile
@gregblake
gregblake / document.rb
Created October 16, 2017 14:44
has_attached_file configuration on a per-model basis
if Rails.env.training?
has_attached_file :thumbnail,
storage: :fog,
fog_credentials: {
aws_access_key_id: NitroConfig.get("s3/training_read_only_access_key"),
aws_secret_access_key: 'production_secret_acesss_key'
},
fog_directory: 'production_bucket_name'
else
has_attached_file :thumbnail, styles: { small: "75x75#", medium: '256x256#' }, default_url: ActionController::Base.helpers.image_path("/assets/logos/:style/power_logo_transparent.png")
@gregblake
gregblake / resque_pool_restart.rb
Created October 23, 2017 18:24
resque pool restart
14:22 $ bundle exec cap production resque:pool:restart
00:00 resque:pool:stop
01 kill -s INT `cat /data/apps/ror/pws/shared/tmp/pids/resque-pool.pid`
✔ 01 [email protected] 0.067s
✔ 01 [email protected] 0.063s
✔ 01 [email protected] 0.066s
00:00 resque:pool:start
01 bundle exec resque-pool --daemon --environment production RUN_AT_EXIT_HOOKS=1
✔ 01 [email protected] 1.400s
01 bundler: failed to load command: resque-pool (/data/apps/ror/pws/shared/bundle/ruby/2.3.0/bin/resque-pool)
@gregblake
gregblake / production_training_timeout.rb
Created October 24, 2017 15:58
production_training_timeout.rb
MYSQL_WAIT_TIMEOUT_MAX = 2147483
def test_connection(extra_conf = {})
conf = {
:host => "HOST_NAME",
:username => "USER_NAME",
:password => "PASSWORD",
:database => "DATABASE_NAME",
:adapter => "mysql2"
}
```bash
13:02 $ be cap production resque:pool:status
00:00 resque:pool:status
--> production-nitro-task1: 558
--> production-nitro-task5: 34795
--> production-nitro-task2: 43016
--> production-nitro-task7: 10935
--> production-nitro-task6: 19400
--> production-nitro-task3: 15424
00:01 resque:pool:training:status
13:02 $ be cap production resque:pool:status
00:00 resque:pool:status
--> production-nitro-task1: 558
--> production-nitro-task5: 34795
--> production-nitro-task2: 43016
--> production-nitro-task7: 10935
--> production-nitro-task6: 19400
--> production-nitro-task3: 15424
00:01 resque:pool:training:status
--> training-nitro-task1: 47102
@gregblake
gregblake / load_recent.sh
Created October 27, 2017 17:45
bundle exec rake dev:load_recent
bundle exec rake dev:load_recent
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <main> at /Users/greg/code/nitro-web/components/core_models/lib/core_models.rb:4)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <main> at /Users/greg/code/nitro-web/components/core_models/lib/core_models.rb:7)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <main> at /Users/greg/code/nitro-web/components/core_models/lib/core_models.rb:7)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from included at /Users/greg/code/nitro-web/components/nitro_search/lib/nitro_search/cachi
@gregblake
gregblake / document_version_migration.rb
Created December 6, 2017 15:12
Migration to support 2.5gb uploads
class ChangeAttachmentFileSizeIntegerLimitOnDocumentVersion < ActiveRecord::Migration[5.1]
def change
change_column :document_versions, :attachment_file_size, :integer, limit: 8
end
end
@gregblake
gregblake / device_locations.rb
Created January 11, 2018 17:10
device_locations
def some_name(device_locations:)
data = []
0.upto(12).each do |i|
data << device_locations.was_located_between(shift_right: i.hours, shift_left: (i+1).hours).count
end
data << device_locations.where(located_at:((Time.zone.parse('1970-01-01')).utc)..(13.hours.ago.utc)).count
data.join(",")
end
@gregblake
gregblake / paperclip.rb
Created February 21, 2018 19:17
Using Paperclip on the Rails Console
Loading development environment (Rails 5.1.4)
[1] pry(main)> document = Document.new
=> #<Document:0x007faaa2018e80
id: nil,
name: nil,
active: true,
created_by: nil,
roles_count: 0,
created_at: nil,
updated_at: nil,
@gregblake
gregblake / document_type_unique_validations_constraints.rb
Created February 21, 2018 19:39
document_type_unique_validation_constraints.rb
[10] pry(main)> document_type = DocumentType.new
=> #<DocumentType:0x007faaa05e92d0
id: nil,
code: nil,
name: nil,
description: nil,
owner_id: nil,
active: nil,
created_at: nil,
updated_at: nil,