Skip to content

Instantly share code, notes, and snippets.

View ParthivPatel-BTC's full-sized avatar

ParthivPatel-BTC ParthivPatel-BTC

View GitHub Profile
@ParthivPatel-BTC
ParthivPatel-BTC / test.rb
Created September 12, 2015 11:18
Delete all database records
ActiveRecord::Base.connection.tables.map do |model|
unless ['schema_migrations', 'cic_user_profiles'].include?(model)
klass = model.capitalize.singularize.camelize.constantize
puts "Deleting #{klass}"
klass.delete_all
end
end
check process delayed_job
with pidfile /home/USER_NAM/APP_NAME/shared/pids/delayed_job.pid
start program = “/usr/bin/env RAILS_ENV=production /home/USER_NAM/APP_NAME/current/script/delayed_job start”
stop program = “/usr/bin/env RAILS_ENV=production /home/USER_NAM/APP_NAME/current/script/delayed_job stop”
#! /bin/sh
set_path="cd APP_FULL_PATH"
case "$1" in
start)
echo -n "Starting delayed_job: "
su - imdeploy -c "$set_path; RAILS_ENV=production script/delayed_job start" >> /var/log/delayed_job.log 2>&1
echo "done." ;;
stop) echo -n "Stopping delayed_job: "
su - imdeploy -c "$set_path; RAILS_ENV=production script/delayed_job stop" >> /var/log/delayed_job.log 2>&1
echo "done." ;;
1.DRY - Dont' Repeat Yourself
2.Two spaces, no tabs
3.Boolean Tests: don't use "and" and "or", always use "&&" and "||"
Comments
--------
1.Remove old commented code
2."How to" comments - If you add/change any method/variables etc.., always add detailed description in just above line. So, anybody can understand that code.
Camels for Classes, Snakes Everywhere Else
1.DRY - Dont' Repeat Yourself
2.Two spaces, no tabs
3.Boolean Tests: don't use "and" and "or", always use "&&" and "||"
Comments
--------
1.Remove old commented code
2."How to" comments - If you add/change any method/variables etc.., always add detailed description in just above line. So, anybody can understand that code.
Camels for Classes, Snakes Everywhere Else
1.DRY - Dont' Repeat Yourself
2.Two spaces, no tabs
3.Boolean Tests: don't use "and" and "or", always use "&&" and "||"
Comments
--------
1.Remove old commented code
2."How to" comments - If you add/change any method/variables etc.., always add detailed description in just above line. So, anybody can understand that code.
Camels for Classes, Snakes Everywhere Else
2.2.2 :015 > array = Array.new
#=> []
2.2.2 :016 > array = Array.new(5)
#=> [nil, nil, nil, nil, nil]
2.2.2 :017 > array = [ '1', '2', '3' ]
#=> ["1", "2", "3"]
2.2.2 :018 > array = ('1'..'3').to_a
#=> ["1", "2", "3"]
2.2.2 :019 > array = *('1'..'3')
#=> ["1", "2", "3"]
class Msg91MessageService
def send_sms(to_number, message)
require 'msg91ruby'
begin
api = Msg91ruby::API.new(ENV['MSG91_AUTH_KEY'], ENV['MSG91_SENDER_ID'])
api.send(to_number, message, 4)
rescue => e
end
end
end
@ParthivPatel-BTC
ParthivPatel-BTC / omniauth_callbacks_controller.rb
Created September 10, 2019 01:58
OmniauthCallbacksController
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_oauth2
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
auth = request.env["omniauth.auth"]
@user.access_token = auth.credentials.token
@user.expires_at = auth.credentials.expires_at
@user.refresh_token = auth.credentials.refresh_token
@user.save!
@ParthivPatel-BTC
ParthivPatel-BTC / user.rb
Created September 10, 2019 02:01
OAuthUserModel
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :omniauthable, :omniauth_providers => [:google_oauth2]
has_many :tasks
def self.from_omniauth(access_token)
data = access_token.info
user = User.where(:email => data["email"]).first