Skip to content

Instantly share code, notes, and snippets.

@umar-siddiqui
umar-siddiqui / condition_eval.rb
Created October 22, 2015 09:39
conditions evaluation in rb file
.select do |ind_user_access|
condition = ind_user_access.move.conditions.first
next true if condition.nil?
next false unless object.attributes[condition.indicator_attribute.name]
eval_str = "#{object.attributes[condition.indicator_attribute.name]}" \
" #{condition.operator}" \
" #{condition.value}"
next true if eval(eval_str)
false
end
@umar-siddiqui
umar-siddiqui / org_node_mapping_seed.rb
Last active November 17, 2015 08:33
seed data for deepali
client_name = 'ZZZZZZZ'
indicator_name = 'Fuel Consumption - DG sets'
org_node_type_name = 'Branch'
data_frequency_name = 'Monthly'
workflow_name = 'Travel Workflow'
user_name = 'IndusInd'
move_name = 'Submit'
Mongoid::Multitenancy.current_tenant = Client.find_by(name: client_name)
@umar-siddiqui
umar-siddiqui / destroy_discussion.rb
Created November 16, 2015 13:59
delete un wanted discussion questions
Section.in(name: ['Strategic Integration', 'Operational Integration']).map(&:questions).flatten.select{ |quest| quest.label == 'Discussion' }.map(&:destroy)
@umar-siddiqui
umar-siddiqui / wkhtmltopdf.rb
Last active December 11, 2015 06:18
html to pdf
sudo add-apt-repository ppa:ecometrica/servers
sudo apt-get update
sudo apt-get install wkhtmltopdf
# add gem 'wicked_pdf'
bundle
# add gem 'delayed_job_mongoid'
bundle
https://www.stormconsultancy.co.uk/blog/development/generating-pdfs-in-rails-with-pdfkit-and-deploying-to-a-server/
require 'mailman'
Mailman.config.imap = {
server: 'imap.gmail.com',
port: 993, # you usually don't need to set this, but it's there if you need to
ssl: true,
# Use starttls instead of ssl (do not specify both)
#starttls: true,
username: 'umar@treeni.com',
password: 'fresh786'
}
@umar-siddiqui
umar-siddiqui / rails_server_setup_capistrano.md
Created January 21, 2016 10:27
RailsServerSetupCapistrano

Rails Setup

Configure ssh

  • Add ssh key to server cat ~/.ssh/id_rsa.pub | ssh bill@xxx.xxx.xxx.xxx -p 4321 'cat - >> ~/.ssh/authorized_keys'

  • Change permission of ssh folder sudo chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh/

Install Apache and Dependencies

#!/bin/bash
FRMUSER=$1
FRMIP=$2
TOUSER=$3
TOIP=$4
scp -r $FRMUSER@$FRMIP:/var/www/$FRMIP/shared/public/pdfs ./ &&
scp -r ./pdfs $TOUSER@$TOIP:/var/www/$TOIP/shared/public &&
scp -r $FRMUSER@$FRMIP:/var/www/$FRMIP/shared/public/csv ./ &&
scp -r ./csv $TOUSER@$TOIP:/var/www/$TOIP/shared/public &&
@umar-siddiqui
umar-siddiqui / remove_other_client.rb
Last active February 4, 2016 07:38
Remove other clients from DB
client = Client.find_by(name: '<Client Name which we want to keep>')
models = Dir["/home/webonise/Projects/treeni-data-management/app/models/**/*.rb"]
.map{ |file_name| Object.const_get(file_name.split('/').last.split('.').first.camelize) }
.reject{|i| i == Client }
models.each do |model|
model.ne(client_id: client._id).destroy_all
end
@umar-siddiqui
umar-siddiqui / drop_restore_db.sh
Last active August 24, 2016 07:43
Script for fetching DB on server and restoring locally.
#!/bin/bash
## Parameter 1 :: Database name on server
## Parameter 2 :: Server Domain name
## Parameter 3 :: Capistrano deployment script
## eg ./drop_restore_db.sh havells_resustain_io havells.resustain.io security
dbname=$1
instancedomain=$2
envi=$3
echo "#################### [INFO] Executing Command :: cap $envi deploy:mongo_backup\"[$dbname]\""