Skip to content

Instantly share code, notes, and snippets.

View shah743's full-sized avatar
🏠
Working from home

Shah Zaib shah743

🏠
Working from home
  • Islamabad, PK
View GitHub Profile
@shah743
shah743 / deploy-yml.md
Last active October 8, 2024 12:37
Deploying Rails 7+ Apps with Kamal Gem on Digital Ocean

Description: A comprehensive guide to deploying Rails 7.1+ applications using the Kamal gem and Digital Ocean. This guide covers installation, configuration, and deployment steps with detailed instructions and example configuration files.

Rails 7.1 and Docker

With Rails 7.1, Docker files come by default.

Kamal Configuration

Install Kamal Gem

@shah743
shah743 / ror-api.markdown
Created June 9, 2022 05:22 — forked from withoutwax/ror-api.markdown
Guide on how to create an API-Only Application with Ruby on Rails 5

Creating an API-Only Application with Ruby on Rails

01 - Create a new API-only Rails app

rails new ror-app-name --api

02 - Basic Scaffold

01 - Model

This step is for creating a very basic level of model for us to work in. If you know already, or wish to apply your own custom models with relationships you can skip this step.

@shah743
shah743 / 00_README.md
Created November 20, 2020 19:28 — forked from mikechau/00_README.md
Logging Rails 4 to Syslog, formatted w/ Logstash

Logging Rails 4 to Syslog, formatted w/ Logstash

Getting Started

Steps to get Rails 4 saving its output to Syslog via Rsyslog. This assumes you are on CentOS, but should be pretty adaptable to any other distribution. Ruby 2.0+ is also required.

  1. Add the gems lograge and logstash-event to your Gemfile. Feel free to remove from production if you'd like to test it in development as well or something.
  2. Update production.rb with the lograge settings and set the logger to Syslog::Logger.
  3. Add the conf files to /etc/rsyslog.d/. /etc/rsyslog.conf should have $IncludeConfig /etc/rsyslog.d/*.conf enabled, so it will load any additional configs from /etc/rsyslog.conf.
@shah743
shah743 / admin_mailer.rb
Created September 25, 2019 05:12
Protecting a Rails app from small scripted attacks
#app/mailers/admin_mailer.rb
class AdminMailer < ApplicationMailer
default from: "...", to: "..."
def rack_attack_notification(name, start, finish, request_id, remote_ip, path, request_headers)
@name = name
@start = start
@finish = finish
@request_id = request_id
@shah743
shah743 / export.rb
Created July 18, 2019 06:32
Export From Console to CSV
require 'csv'
file = "#{Rails.root}/public/user_data.csv"
products = Product.order(:first_name)
headers = ["Product ID", "Name", "Price", "Description"]
CSV.open(file, 'w', write_headers: true, headers: headers) do |writer|
products.each do |product|
@shah743
shah743 / rails_confirm_override.js.coffee
Created October 29, 2018 08:10
SweetAlert2 rails confirm
$.rails.allowAction = (link) ->
if link.data('confirm')
$.rails.showConfirmationDialog(link)
false
else
true
# User click confirm button
$.rails.confirmed = (link) ->
link.data('confirm', null)
@shah743
shah743 / deploy.rb
Created October 26, 2018 12:43 — forked from yanyingwang/deploy.rb
mina+puma+nginx
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
# require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
require 'mina/rvm' # for rvm support. (http://rvm.io)
require 'mina/puma'
require 'mina/nginx'
# Basic settings:
@shah743
shah743 / NoVNC_Paste.js
Created October 19, 2017 05:41 — forked from byjg/NoVNC_Paste.js
How to Paste code to NoVNC.
// This will open up a prompt for text to send to a console session on digital ocean
// Useful for long passwords
(function () {
window.sendString = function (str) {
f(str.split(""));
function f(t) {
var character = t.shift();
var i=[];
var code = character.charCodeAt();
var needs_shift = character.match(/[A-Z!@#$%^&*()_+{}:\"<>?~|]/);