Skip to content

Instantly share code, notes, and snippets.

@umar-siddiqui
umar-siddiqui / create_sm.rb
Last active March 16, 2018 13:51
create_sm.rb
Settings.client_databases.to_h.map{ |k,v| v }.uniq.each_with_index do |db, index|
puts "-------------------& DB - #{db} &-----------------\n\n"
Client.all.each do |client|
Mongoid::Multitenancy.current_tenant = client
puts " & Client - #{client.name} &\n\n"
UserRole.find_or_create_by!(name: 'Supplier Manager')
UserRole.find_or_create_by!(name: 'Project Admin')
UserRole.find_or_create_by!(name: 'Budget Admin')
end
end
@umar-siddiqui
umar-siddiqui / transpose_transformer.rb
Created January 16, 2018 09:26
Transpose transformer
module TransformationEngine
##
# This class is for transpose the rows
class TransposeTransformer < BaseTransformer
attr_accessor :fixed_cols, :varying_cols
def initialize(rule_hash)
super(rule_hash)
self.type = 'collection'
self.fixed_cols = rule_hash[:fixed_cols].split(',').map(&:to_sym)
@umar-siddiqui
umar-siddiqui / currencyToUsd.js
Last active January 14, 2018 08:32
closure exp for currency conversion
function currencyUsd(rate) {
return function(amt) { return (amt / rate) + ' USD' }
}
inrToUsd = currencyUsd(65)
krwToUsd = currencyUsd(1058)
inrToUsd(65) // 1 USD (65inr is 1usd)
krwToUsd(1058) // 1 USD (1058krw is 1usd)
- PPT for javascript, CSS and HTML
- Closure and its examples
- Protractor for unit testing
http://www.protractortest.org/#/
- Jquery and Ajax CORS
https://stackoverflow.com/questions/2067472/what-is-jsonp-all-about
- Mobile security considerations
@umar-siddiqui
umar-siddiqui / arrayToString.js
Last active January 13, 2018 21:11
Array of any elements to string
var x = [
'1',
12,
[1, 2, { a: 'z' }],
{ a: 'zzz' }
]
function ArrayToString(x) {
var result = '[ '
def profit(ex1, ex2, in_amt)
trd_amt = in_amt.to_f + in_amt.to_f * 0.01
in_ripple = (in_amt.to_f/ex1.to_f)
final_amt = in_ripple*ex2.to_f
final_amt-trd_amt
end
in_amt_inr = 10000 # Investment amount in INR
cryp_inr = 69.70 # cyrpto 1 price in INR
cryp_btc = 0.000073 # cyrpto 1 price in USD
cryp2_btc = 0.019470 # cyrpto 2 price in USD
cryp2_inr = 18350 # cyrpto 2 price in INR
ex1_to_ex2_tf = 0.04
conv_btc_ef = 0.0
conv_btc_to_cryp2_ef = 0.0
ex2_to_ex1_tf = 0.001
Mongoid.override_database 'sterlite_resustain_io'
Mongoid::Multitenancy.current_tenant = Client.first
callbacks = IndicatorRecord._save_callbacks.select { |cb| cb.kind == :before }.map { |cb| cb.as_json["key"] }.map(&:to_sym)
indi = Indicator.find('5910150062cee9ae1a000002')
indicator_attri = indi.indicator_attributes.where(attribute_type: 'formula')
IndicatorRecord.skip_callback(:save, :before, *callbacks)
IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002', grade: '6th', :start_date.gte => 'June 1,2015', type_of_set: 'Sample', :start_date.lte => 'March 1,2016').each_with_index do |ir,i|
puts i
m = [
{
:src => :letters,
'Sample' => { 'BoY' => :boy_letter_score_for_sample, 'EoY' => :eoy_letter_score_for_sample },
'Control' => { 'EoY' => :eoy_letter_scores, 'BoY' => :boy_letter_score }
},
{
:src => :sound_score,
'Sample' => { 'BoY' => :boy_sound_score_for_sample, 'EoY' => :eoy_sound_score_for_sample },
'Control' => { 'EoY' => :eoy_sound_score_for_control, 'BoY' => :boy_sound_score_for_control }
def analytics_migration(old_project_id, new_project_id)
Analytic.where(project_ids: old_project_id).each do |analytic|
next unless analytic.project_ids.present?
analytic.project_ids = analytic.project_ids.map{ |_id| _id == old_project_id ? new_project_id : _id }
analytic.save!
end
end
def project_view_details_progress_outcomes_outputs_impacts(old_project_id, new_project_id)
class Output;belongs_to :project;end