Skip to content

Instantly share code, notes, and snippets.

View liroyleshed's full-sized avatar

Liroy Leshed liroyleshed

View GitHub Profile
@liroyleshed
liroyleshed / puma.service
Created March 19, 2024 23:19 — forked from arteezy/puma.service
Manage Puma with systemd and rbenv
[Unit]
Description=Puma Rails Server
After=network.target
[Service]
Type=simple
User=deploy
WorkingDirectory=/home/deploy/app/current
ExecStart=/home/deploy/.rbenv/bin/rbenv exec bundle exec puma -C /home/deploy/app/shared/config/puma.rb
ExecStop=/home/deploy/.rbenv/bin/rbenv exec bundle exec pumactl -S /home/deploy/app/shared/tmp/pids/puma.state stop
@liroyleshed
liroyleshed / Rails, Puma & Nginx.md
Created January 27, 2024 02:22 — forked from davidteren/Rails, Puma & Nginx.md
Example setup for Puma with Nginx in a Rails app

In the apps config/puma.rb file:

Change to match your CPU core count
# Check using this on the server => grep -c processor /proc/cpuinfo
workers 4

# Min and Max threads per worker
threads 1, 6

app_dir = File.expand_path('../..', FILE)

# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
class UserAuthenticationsController < AuthenticatedController
def create
if authenticate
enroll_promotions
redirect_to return_path
else
redirect_to back_path, error: authentication_error_message
end
end
@liroyleshed
liroyleshed / comments_channel.rb
Created September 26, 2020 17:33 — forked from dhh/comments_channel.rb
On-boarding a specialized broadcast method in the channel itself
# Channel
class CommentsChannel < ApplicationCable::Channel
def self.broadcast_comment(comment)
broadcast_to comment.message, comment: CommentsController.render(
partial: 'comments/comment', locals: { comment: comment }
)
end
def follow(data)
stop_all_streams
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session