Given an array [1,2,34,5,6,7,8,9], sum it up using a method:
def sum(array)
return array.inject(:+)
end
Given an array [1,2,34,5,6,7,8,9], sum it up using a method:
def sum(array)
return array.inject(:+)
end
sudo apt install curl
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarnsudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-devgpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Got this error: gpg: keyserver receive failed: Server indicated a failure
--------------------------------------------------------------------------------------------------
Then run for this command:
curl -sSL https://get.rvm.io | bash -s stable
then got this error:
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gzDownloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.ascgpg: Signature made Saturday 16 January 2021 12:16:22 AM ISTgpg: using RSA key 7D2BAF1CF37B13E2069D6956105BD0E739499BDBgpg: Can't check signature: No public keyGPG signature verification failed for '/home/sadhna/.rvm/archives/rvm-1.29.12.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
or if it fails:
command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - command curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
In case of further problems with validation please refer to https://rvm.io/rvm/security-----------------------------------------------------------------------------------------------------------Follow this link: https://rvm.io/rvm/security
Then run: gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Then run tow command:
command1 curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
command2 curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
---------------------------------------------------------------------------------------------------------------
Then rvm install: rvm install 2.6.7
So got this error:
Error running 'requirements_debian_update_system ruby-2.6.7',
please read /home/sadhna/.rvm/log/1624518537_ruby-2.6.5/update_system.log
Requirements installation failed with status: 100.
---------------------------------------------------------------------------------------
Solve this error:
source ~/.rvm/scripts/rvmrvm requirements$ cd /usr/local/src/ $ sudo wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz $ sudo tar -xf openssl-1.1.1n.tar.gz $ cd openssl-1.1.1n $ sudo ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib $ sudo make $ sudo make install $ sudo rmdir certs $ sudo ln -sf /etc/ssl/certs/ certs
rvm install 3.1.2 --with-openssl-dir=/usr/local/sslInstall Rbenv: https://www.swhosting.com/en/comunidad/manual/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-2204
https://github.com/simplecov-ruby/simplecov
==================================
Add gem file:
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'simplecov', require: false
end
then install bundle install
==================================
Add a spec/spec_helper.rb
require 'simplecov'
RSpec.configure do |config|
SimpleCov.start 'rails'
end
==================================
For User Model
validates :password, :presence => true, :on => :create
before_save :password_required?
before_update :password_required?
def password_required?
if self.password.present?
true
else
false
end
end
mysqldump -h HOST_NAME -u USER_NAME -p DATABASE_NAME > fittac_dev_07_01_2021.sql
https://github.com/jeygeethan/activestorage-backblaze
Add gem:
gem 'activestorage-backblaze' is gem only user for backblaze ke liye hai.
gem "aws-sdk-s3", require: false
Image upload on backblaze:
backblaze:
service: Backblaze
bucket_name: <%= ENV['BUCKET_NAME'] %>
bucket_id: <%= ENV['BUCKET_ID'] %>
key_id: <%= ENV['KEY_ID'] %>
key_token: <%= ENV['KEY_TOKEN'] %>
Run the command:
rails active_storage:install
Followed by:
rails db:migrate
In the config/storage.yml file, uncomment the 'amazon' configuration options. Make sure to add your region and bucket name.
Add this code config/storage.yml
amazon:
service: S3
access_key_id: <%= ENV['AWS_ACCESS_KEY'] %>
secret_access_key: <%= ENV['AWS_SECRET_KEY'] %>
region: <%= ENV['AWS_RESION'] %>
bucket: <%= ENV['AWS_BUCKET'] %>
==============================================
In the config/environments/development.rb there should be a line that says:
config.active_storage.service = :local
And in the config/environments/production.rb you'll need to remove the line:
config.active_storage.service = :local
And add the line:
This is amazon
config.active_storage.service = :amazon
=============================================
This is backblaze
config.active_storage.service = :backblaze
=============================================
Add a model:
has_one_attached :featured_image
==============================================
Image upload form minio
Add this code config/storage.yml
minio_dev:
service: S3
access_key_id: <%= ENV['STORAGE_ACCESS_KEY'] %>
secret_access_key: <%= ENV['STORAGE_SECRET_ACCESS_KEY'] %>
region: <%= ENV['STORAGE_REGION'] %>
bucket: <%= ENV['STORAGE_BUCKET'] %>
endpoint: <%= ENV['Endpoint'] %>
force_path_style: true
and config/development.rb and production.rb
config.active_storage.service = :minio_dev
---------------------------------
If in case getting this erro:
undefined method `has_one_attached' for #<Class:0x000055cfabb92460> (NoMethodError)
Add this line in application.rb
ActiveSupport.on_load(:active_record) do
include ActiveStorage::Reflection::ActiveRecordExtensions
ActiveRecord::Reflection.singleton_class.prepend(ActiveStorage::Reflection::ReflectionExtension)
include ActiveStorage::Attached::Model
endOn top:
attribute :profile_image do |object|
if object.profile_pic.attached?
# ENV["API_BASE_URL"] + Rails.application.routes.url_helpers.rails_blob_url(object.profile_pic, only_path: true)
object.profile_pic.service_url
end
end
Elasticsearch install step by step
java -v
java -version
echo $JAVA_HOME
ls /usr/lib/jvm//java-
for Result
java-1.7.0-openjdk-amd64/ java-1.8.0-openjdk-amd64/ java-7-openjdk-amd64/ java-8-openjdk-amd64/
==============================================================
for run Tab ke through check karna hai: echo /usr/lib/jvm/java-8-openjdk-amd64/
==============================================================
Set environment variable:
sudo nano /etc/environment
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/
PATH=$PATH:$HOME/bin:$JAVE_HOME/bin
export JAVE_HOME
export JRE_HOME
export PATH
============================================================
Run: echo $JAVA_HOME
For result: /usr/lib/jvm/java-8-openjdk-amd64/
===================================================================
sudo apt-get install apt-transport-https
==================================================================
wget https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
====================================================================
sudo add-apt-repository "deb https://artifacts.elastic.co/packages/6.x/apt stable main"
==================================================================
sudo apt update
=====================================
sudo apt install elasticsearch
Getting this error: sudo apt install elasticsearch
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package elasticsearch
For solve:
On terminal: wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-archive-keyring.gpg] https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list > /dev/null
sudo apt update
sudo apt-get install elasticsearch
sudo systemctl enable elasticsearch
------------------------------------------------
When getting this error:
sudo systemctl enable elasticsearch Synchronizing state of elasticsearch.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable elasticsearch
Then run this command: sudo systemctl is-enabled elasticsearch
---------------------------------------------
sudo systemctl start elasticsearch
Check the status: sudo systemctl status elasticsearch
====================================
sudo nano /etc/elasticsearch/elasticsearch.yml
is file me must nhi hai change karna, kyu ki default me port 9200 hota hai and host 127.0.0.1 hota hai
Only for:
Uncomment line
cluster.name: my-elasticsearch
node.name: elasticsearch-1
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
http.port: 9200
=====================================
sudo systemctl start elasticsearch
======================================
Check status:
sudo systemctl status elasticsearch.service
For this resulte
elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-11-05 17:48:01 IST; 11s ago
Docs: https://www.elastic.co
Main PID: 8632 (java)
Tasks: 63
Memory: 1.2G
CPU: 59.206s
CGroup: /system.slice/elasticsearch.service
├─8632 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10
└─8831 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller
======================================
curl -X GET http://127.0.0.1:9200
{
"name" : "elasticsearch-1",
"cluster_name" : "my-elasticsearch",
"cluster_uuid" : "OL-ZPjVBTcG4b9HlEgnOdw",
"version" : {
"number" : "7.9.3",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "c4138e51121ef06a6404866cddc601906fe5c868",
"build_date" : "2020-10-16T10:36:16.141335Z",
"build_snapshot" : false,
"lucene_version" : "8.6.2",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
==============================================
Link: https://www.youtube.com/watch?v=63nS1Z-pIfI