Skip to content

Instantly share code, notes, and snippets.

View solutelabs-savan's full-sized avatar

Savan Raval solutelabs-savan

  • India
View GitHub Profile
@solutelabs-savan
solutelabs-savan / gist:d742e74718d8400edc942ba5441e3dca
Created June 1, 2016 12:18 — forked from mattconnolly/gist:4158961
RSpec basic authentication helper module for request and controller specs
module AuthHelper
def http_login
user = 'username'
pw = 'password'
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user,pw)
end
end
module AuthRequestHelper
#
@solutelabs-savan
solutelabs-savan / postgres.rake
Created May 23, 2016 12:37 — forked from owainlewis/postgres.rake
Backup task for Postgres
namespace :postgres do
desc 'Backup postgres database'
task :backup => :environment do
db_config = Rails.application.config.database_configuration[Rails.env]
backup_dir = '/home/deploy/backups'
outfile = "#{ backup_dir }/#{ Rails.env }_#{ DateTime.now.strftime("%Y%m%d_%H%M%S.sql.gz") }"
cmd = "pg_dump -h localhost -U #{ db_config['username'] } #{ db_config['database'] } | gzip -c > #{outfile}"
puts "Making database backup..."
@solutelabs-savan
solutelabs-savan / db.rake
Created May 23, 2016 11:59 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@solutelabs-savan
solutelabs-savan / README.rb
Last active May 11, 2016 09:15
Work with 2R combinations - Rails & Redis
Install Redis on ubuntu first
1) Add PPA
$ sudo add-apt-repository ppa:chris-lea/redis-server
Press ENTER to accept the repository.
2) Run the following command to update our packages:
$ sudo apt-get update
3) Install the Redis server:
$ sudo apt-get install redis-server
4) Check that Redis is up and running:
$ redis-benchmark -q -n 1000 -c 10 -P 5
@solutelabs-savan
solutelabs-savan / devise.rb
Last active September 5, 2019 11:20
Create Sign In / Sign Out API using Devise
# Find this line config.navigational_formats = ['*/*', :html] in devise.rb file and replace it with this line inorder to accept JSON request and give JSON response.
config.navigational_formats = ["*/*", :html, :json]
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: :created
return
else