Skip to content

Instantly share code, notes, and snippets.

@savanr
savanr / sidekiq_monitoring
Created April 26, 2021 05:59 — forked from ngsmrk/sidekiq_monitoring
Sidekiq queue checking via rails console
stats = Sidekiq::Stats.new
stats.queues
stats.enqueued
stats.processed
stats.failed
@savanr
savanr / clear-sidekiq-jobs.sh
Created March 10, 2018 12:55 — forked from wbotelhos/clear-sidekiq-jobs.sh
Clear Sidekiq Jobs
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
# 3. Clear 'Processed' and 'Failed' jobs
@savanr
savanr / application.html.erb
Created February 27, 2018 05:36 — forked from collectiveidea/application.html.erb
How to get jQuery to work with Rail's Authenticity Token (protect_from_forgery)
<!DOCTYPE html>
<html>
<head>
<title>My Rails App</title>
<%- if protect_against_forgery? -%>
<meta name="authenticity-token" id="authenticity-token" content="<%= form_authenticity_token %>" />
<%- end -%>
<%= javascript_include_tag 'jquery', 'rails' %>
</head>
<body>
@savanr
savanr / send_data-send_file-remote-images-download
Created February 23, 2018 15:59 — forked from maxivak/send_data-send_file-remote-images-download
Rails. Download remote image as attachment in browser
# in controller
# for local files
send_file '/path/to/file', :type => 'image/jpeg', :disposition => 'attachment'
# for remote files
require 'open-uri'
url = 'http://someserver.com/path/../filename.jpg'
data = open(url).read
send_data data, :disposition => 'attachment', :filename=>"photo.jpg"
@savanr
savanr / coupon.rb
Created July 10, 2017 19:01
Code Snippets
ActiveAdmin.register Coupon do
permit_params :title, :c_body, :c_is_active, :c_redemption_limit,
:is_special_coupon, :c_valid_from,
:c_valid_until, :c_no_of_reservation, :coupon,
:c_coupon_image_url, :sponsor_id, :is_assured_coupon, :position, :branch_ids => []
controller do
def create
@coupon = Coupon.new(coupon_params)
@coupon.branches << Branch.where(:id => coupon_params[:branch_ids]).uniq
@savanr
savanr / Capistrano 3.md
Created May 20, 2017 10:31 — forked from stevenyap/Capistrano 3.md
Capistrano 3 Setup

This guide explains the way to setup a production server using Capistrano.

Setup Capistrano on LOCAL

  • Capistrano is a development gem which assist the developer to run commands on the production server (something like a Heroku toolbelt)
  • Hence, it is installed and configured on developer's computer
# Gemfile

# Use Capistrano for deployment
/* Content Flip Style */
.bb-bookblock {
width: 400px;
height: 300px;
position: relative;
background: #fff;
z-index: 100;
}
.bb-page {
@savanr
savanr / My account
Created September 1, 2016 20:03
My account
Username : savanr
Email : savan_raval@yahoo.com
@savanr
savanr / registrations_controller.rb
Created June 25, 2016 04:47 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@savanr
savanr / devise_authentication_api.rb
Last active January 19, 2017 12:00 — forked from skozz/devise_authentication_api.rb
Authenticate your API with Devise gem, token by header. Ruby on Rails 4. Read the comments.
#Session controller provides a token
#/controllers/api/sessions_controller.rb
class Api::SessionsController < Devise::SessionsController
before_filter :authenticate_user!, :except => [:create]
before_filter :ensure_params_exist, :except => [:destroy]
respond_to :json
def create
resource = User.find_for_database_authentication(:email => params[:user_login][:email])
return invalid_login_attempt unless resource