Monday 26 March 2018

Create migration with account wise

  self.table_name = "push_event_trackings1"

  def self.for account_id
    tname = "push_event_trackings#{account_id}"
    model_name = tname.classify
    if Object.const_defined?(model_name)
      fields_class = model_name.constantize
    else
      fields_class = Object.const_set(model_name, Class.new(PushTracking){
        self.table_name = tname
      })
    end
    return fields_class.using(:sms)
  end
 
  def self.create_table account_id
    fields_table_name = "push_event_trackings#{account_id}"
    Octopus.using(:sms) do
      ActiveRecord::Migration.execute "CREATE TABLE `#{fields_table_name}` (
        `id` bigint(20) NOT NULL AUTO_INCREMENT,
        `push_device_id` int(11) DEFAULT NULL,
        `push_event_id` int(11) DEFAULT NULL,
        `cart_id`  int(11) DEFAULT NULL,
        `sku` varchar(255) DEFAULT NULL,
        `description` varchar(255) DEFAULT NULL,
        `quantity` int(11) DEFAULT NULL,
        `value` float DEFAULT NULL,
        `product_category` varchar(255) DEFAULT NULL,
        `brand` varchar(255) DEFAULT NULL,
        `model_number` varchar(255) DEFAULT NULL,
        `order_id` varchar(255) DEFAULT NULL,
        `order_date` datetime DEFAULT NULL,
        `order_status` varchar(255) DEFAULT NULL,
        `coupon_code` varchar(255) DEFAULT NULL,
        `campaign_id` int(11) DEFAULT NULL,
        `session_id` int(11) DEFAULT NULL,
        `platform` int(11) DEFAULT NULL,
        `price` float DEFAULT NULL,
        `content_id` int(11) DEFAULT NULL,
        `title` varchar(255) DEFAULT NULL,
        `category` varchar(255) DEFAULT NULL,
        `event_data` text COLLATE utf8_unicode_ci,
        `latitude` float DEFAULT NULL,
        `longitude` float DEFAULT NULL,
        `created_at` datetime NOT NULL,
        `updated_at` datetime NOT NULL,
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8"
      ActiveRecord::Migration.add_index(fields_table_name, :push_device_id)
      ActiveRecord::Migration.add_index(fields_table_name, :push_event_id)
    end
  end

  run migration on console according to account id
  account = Account.first
  PushEvenTracking.create account.id

truncate word with screen resolution

.wrap{
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

Check Query Execution Time in spark

def time[A](f: => A) = {
  val s = System.nanoTime
  val ret = f
  println("time: " + (System.nanoTime - s) / 1e9 + " seconds")
  ret
  }
val test = time('statement')


val test = time(spark.sql("SELECT * from mmc_push_event.push_devices"))

Friday 23 March 2018

Install Cassandra in ubuntu and CentOS

Cassandra requires that the Oracle Java SE Runtime Environment (JRE) be installed.
So, in this step, you'll install and verify that it's the default JRE.
  • sudo add-apt-repository ppa:webupd8team/java
  • sudo apt-get update
  • sudo apt-get install oracle-java8-set-default
  • java -version
You should see output similar to the following:
Output
java version "1.8.0_60" Java(TM) SE Runtime Environment (build 1.8.0_60-b27) Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

 Installing Cassandra

Note that Cassandra 2.2.2 is the latest version at the time of this publication. Change the 22x to match the latest version. For example, use 23x if Cassandra 2.3 is the latest version:
  • echo "deb http://www.apache.org/dist/cassandra/debian 22x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
The add the repo's source:
  • echo "deb-src http://www.apache.org/dist/cassandra/debian 22x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
To avoid package signature warnings during package updates, we need to add three public keys from the Apache Software Foundation associated with the package repositories.
Add the first one using this pair of commands, which must be run one after the other:
  • gpg --keyserver pgp.mit.edu --recv-keys F758CE318D77295D
  • gpg --export --armor F758CE318D77295D | sudo apt-key add -
Then add the second key:
  • gpg --keyserver pgp.mit.edu --recv-keys 2B5C1B00
  • gpg --export --armor 2B5C1B00 | sudo apt-key add -
Then add the third:
  • gpg --keyserver pgp.mit.edu --recv-keys 0353B12C
  • gpg --export --armor 0353B12C | sudo apt-key add -
Update the package database once again:
  • sudo apt-get update
Finally, install Cassandra:
  • sudo apt-get install cassandra
 Cassandra should have been started automatically at this point. However, because of a bug, it does not. To confirm that it's not running, type:
  • sudo service cassandra status
If it is not running, the following output will be displayed:
Output
* could not access pidfile for Cassandra
This is a well-known issue with the latest versions of Cassandra on Ubuntu. We'll try a few fixes. First, start by editing its init script. The parameter we're going to modify is on line 60 of that script, so open it using:
  • sudo nano +60 /etc/init.d/cassandra
/etc/init.d/cassandra
CMD_PATT="cassandra.+CassandraDaemon"
Change it to:
/etc/init.d/cassandra
CMD_PATT="cassandra"
Close and save the file, then reboot the server:
  • sudo reboot
Or:
  • sudo shutdown -r now
After logging back in, Cassandra should now be running. Verify:
  • sudo service cassandra status
If you are successful, you will see:
Output
* Cassandra is running

 Connecting to the Cluster

  • sudo nodetool status
In the output, UN means it's Up and Normal:
Output
Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns Host ID Rack UN 127.0.0.1 142.02 KB 256 ? 2053956d-7461-41e6-8dd2-0af59436f736 rack1 Note: Non-system keyspaces don't have the same replication settings, effective ownership information is meaningless
Then connect to it using its interactive command line interface cqlsh.
  • cqlsh
You will see it connect:
Output
Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 2.2.2 | CQL spec 3.3.1 | Native protocol v4] Use HELP for help. cqlsh>
Type exit to quit:

Method - 2  Install Cassandra on CentOS 7


yum -y update

yum -y install java

vim /etc/yum.repos.d/datastax.repo

- copy and paste this code to
[datastax]
name = DataStax Repo for Apache Cassandra
baseurl = http://rpm.datastax.com/community
enabled = 1
gpgcheck = 0

:wq

yum -y install dsc20

Start-Up Cassandra

systemctl start cassandra

Method-1 Try this method first if this will not working use method 2 which is given below 
""connect cassandra to cqlsh""
----------xXx------------
Check Cassandra Service Status

systemctl status cassandra

Enable Cassandra to Start at Boot

systemctl enable cassandra
-----------xXx----------------

Method-2 
""connect cassandra to cqlsh""

- sudo service cassandra start

after that type

cqlsh 127.0.0.1 or cqlsh 



Monday 12 March 2018

Generate Custom string

small_rand = [*('a'..'z')].shuffle
number_rand = [*('0'..'9')].shuffle
cap_rand = [*('A'..'Z')].shuffle
password_rand = small_rand[0..1].join + number_rand[0..6].join + cap_rand[0]

Sunday 11 March 2018

testing configration in application.rb

config.generators do |g|
  g.test_framework :rspec,
    :fixtures => true,
    :view_specs => false,
    :helper_specs => false,
    :routing_specs => false,
    :controller_specs => true,
    :request_specs => true
  g.fixture_replacement :factory_girl, :dir => "spec/factories"
end

Revert last commit or second last and more....

 Git revert commit_id -m 1 this command willl revert last commit  Git revert commit_id -m 2 this command will revert second commit with same...