Tuesday 31 January 2017

Set up rails enviorment

export RAILS_ENV=production
https://www.digitalocean.com/community/questions/how-to-set-rails-environment


check your .bach file and add RAILS_ENV='staging' OR RAILS_ENV='production' whatever you want to set your enviorment


OR

Open bashrc file by

Command:  sudo  vi ~/.bashrc

add below code at the end of the file 


if [[ $- != *i* ]] ; then
    # Shell is non-interactive.  Be done now!
    return
fi

export RAILS_ENV=staging
 

Designing css get particular font css or get working font how to

1) Search font by name : google search Courgette font for download and download font extract that file

2) Search transfonter or go to https://transfonter.org/

3) Upload you font on that and convert that font and download converted font

4) Extract downloaded font  and copy : .eot and .ttf and .woff file into font folder

5) Open style.css file copy that font css and change url to font folder 

S3 amazon buket transfer to another one s3 buket server copy to other sever

1) install amazon cli tool at local on cmd prompt
Command: sudo apt-get install awscli

2) add configuration details off existing s3 bucket [details needed: api-key,api-secret-key,region,response:json  ]
Command: aws configur

Ex:
aws configure
AWS Access Key ID [None]: gdsgdugdhasbfdsh3HSLQ
AWS Secret Access Key [None]: hdbfdbsfbdsjkfjkdn/c1bhjdvfadbshfbdsjhfb
Default region name [None]: us-east-1
Default output format [None]: json

3)Create new s3 buket in amazon and in PRoperty>Permission section add_user for Everyone all access


4)

aws s3 sync s3://current-buket s3://new-bucket 

 

5) How to access new bucket 

   -Login to amazon > mouse hover on Service  and go to Security, Identity & Compliance > IAM section

-  Create New user with S3 bucket access permission 

- Time of creating you get Api-key , secret-key and url save this credential 

or save csv file of credential 

 

 rails of S3 bucket by  CarrierWave :

File : config>initializers>carrierwave.rb



:


 


Friday 20 January 2017

Caching with Rails: An Overview

1) Page Caching  : gem actionpack-page_caching

2) Action cashing : gem actionpack-action_caching

3) Fragment Caching : By default Rails provides

4) Russian Doll caching


Thursday 19 January 2017

Rails Encrypt and decript a key encoding in rails or decoding in rails ruby on rails encrypt decrypt

 
 Create This model in your Model directory : where ever you want to use just include PublicAccessViewHelper
and call encrypt and decrypt method for encryption code and decrypting secret key
 
 
require 'openssl'require 'base64'require 'addressable/uri'require 'uri'

module PublicAccessViewHelper
    def self.included(base)
      base.extend self    end
    def cipher 
 OpenSSL::Cipher::Cipher.new('aes-256-cbc')  # ('aes-256-cbc')    end
    def cipher_key      '@!\xF\xCD\x\x18d\xFD\xFx91\xD4\x03\x92ym\x8F\xD3\x807\xC3\98\xE0\x8E\x8F\xD5T$T\x1CAF\x1Fc\tZE\xE0\x04\xD5\xD7|(J\x8B\xE14\x03S\xF3\xE2y\\X\x9E'    end
    def decrypt(encrypted_data)
=begin      c = cipher.decrypt      c.key = Digest::SHA256.digest(cipher_key)      URI.encode(c.update(Base64.decode64(value.to_s)) + c.final)
=end      # URI.decode(value)      # salt  = SecureRandom.random_bytes(64)      # key   = ActiveSupport::KeyGenerator.new('password').generate_key(salt) # => "\x89\xE0\x156\xAC..."      crypt = ActiveSupport::MessageEncryptor.new(cipher_key)
      crypt.decrypt_and_verify(encrypted_data)
    end
    def encrypt(secret_data)
      crypt = ActiveSupport::MessageEncryptor.new(cipher_key)
      encrypted_data = crypt.encrypt_and_sign(secret_data)
      return encrypted_data=begin      c = cipher.encrypt      c.key = Digest::SHA256.digest(cipher_key)      URI.encode(Base64.encode64(c.update(value.to_s) + c.final))      URI.encode(value)=end    end
    def encrypt_url(value)
      c = cipher.encrypt
      c.key = Digest::SHA256.digest(cipher_key)
      Base64.encode64(c.update(value.to_s) + c.final)
    end
end

Monday 2 January 2017

Create Jquery function for check element exist

jQuery.fn.exists = function(){return this.length>0;}


Example :

if($(".spl_req").exists()){   console.log("Element Exist");}else{
 console.log("Element Not Exist");
}