Posts

Showing posts from 2021

Revert changes to a file in a commit || Revert changes to a file from pushed commit

Here are our git logs 343333 Good commit 457g222 In this commit we want some revert || BAD Commit 2343534 Initial commit Rebase from the previous commit of BAD Commit, amend the problem commit, & continue. 1) Start interactive rebase:    git rebase -i 2343534 2) Mark the problem commit for edit in the editor by changing pick to e (for edit):     e 457g222    pick 343333 3) Revert changes to the bad file:    git show -- file_that_you_want_to_revert.txt | git apply -R 4) Add the changes & amend the commit or make new commit    git add badfile.txt     git commit --amend / /if you want to amend it     git commit -m "your commit message here" / /if you want to create new commit 5) Finish the rebase or push to remote   git rebase --continue //if you did not created new commit in previous steps   git push origin_name branch_name -f   //if created new commit in previour steps  

Load Testing Tool | Vegeta | API Vegeta testing tool

For Ubuntu Install in ubuntu           wget https://github.com/tsenart/vegeta/releases/download/cli%2Fv12.5.1/vegeta-12.5.1-linux-   amd64.tar.gz           tar xfz vegeta-12.5.1-linux-amd64.tar.gz           mv vegeta /usr/bin/vegeta #try with root user permission Shell Script to run  Create a file vegeta_ubuntu.sh and paste following code #!/bin/bash touch post_targets.list #creating a file truncate -s 0 post_targets.list cat >./post_body.json <<EOF  {     "wifi": {       "ssid": "$SSID",       "pw":   "$PW"     }   } EOF echo 'PUT https://staging-sps.luxola.com/api/v2.5/ba/wishlist/variants/202146?card_number=6501087579617' > post_targets.list echo 'X-Site-Country:SG' >> post_targets.list echo 'X-App-Version: 1.0.0'  >> post_targets.list echo 'X-App-Platform: mobile_app'  >> post_targets.list echo 'Authorization:Bearer eyJraWQiOiJXWGZCdjZWQ2xLY09KOGJBVmhlZWRHLXI1ZVhNOUI4

What are delegate, delegate method, SimpleDelegator in ruby

 delegate methods in Rails, exposing only necessary methods of containing objects, thereby, making them more easily accessible. class Parent   def initialize     @child = Child.new   end end class Child   def initialize     @data = []   end   def insert(data)     @data << data   end   def fetch(key)     @data[key]   end end parent = Parent.new if you try this parent.insert("imrahul") then you will get response undefined method `insert' for #<Parent:0x000055f4915673a0 @child=#<Child:0x000055f491567350 @data=[]>> (NoMethodError)   This code will work if we overide methods of child class class Parent   def initialize     @child = Child.new   end   def insert(data)     @child.insert(data)   end   def fetch(index)     @child.fetch(index)   end end class Child   def initialize     @data = []   end   def insert(data)     @data << data   end   def fetch(key)     @data[key]   end end parent = Parent.new parent.insert("imrahul") So this is how dele

Completely uninstall elasticsearch in Linux

sudo apt-get remove elasticsearch sudo apt-get --purge autoremove elasticsearch sudo dpkg --remove elasticsearch sudo dpkg --purge elasticsearch sudo dpkg --purge --force-all elasticsearch sudo rm -rf /var/lib/elasticsearch/ sudo rm -rf /etc/elasticsearch If still facing any issues then you have to delete source file too. cd /etc/apt/sources.list.d/ sudo rm -rf elastic-*   Install Elasticsearch in ubuntu 20, 18, 16

Install Elastic search 5.x in ubuntu 20, 18, 16

Look for OpenJDK in APT sudo apt search openjdk Install OpenJDK 8 sudo apt-get install openjdk-8-jdk Add the proper GPG key for ElasticSearch wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - Make sure to install/update transport sudo apt-get install apt-transport-https Save the repo definition echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list Update APT and install ElasticSearch from APT sudo apt-get update && sudo apt-get install elasticsearch Reload the daemon sudo /bin/systemctl daemon-reload Allow ElasticSearch to start on boot sudo /bin/systemctl enable elasticsearch.service Lets fire up ElasticSearch... sudo systemctl start elasticsearch.service Lets see if we have some logs sudo ls -la /var/log/elasticsearch/ Have a look at the logs and make sure that ElasticSearch has properly initiated sudo cat /var/log/elasticsearch/elasticsearch.

What is the Peatio cryptocurrency exchange or trading plateform?

  Cryptocurrency Exchange A cryptocurrency is nothing but a digital currency. Cryptocurrency exchanges are the platforms where you can buy, sell or exchange cryptocurrencies with other digital currency or with other assets such as fiat money. Fiat currency is like paper money for example Rupees, Dollars whose value is decided by the government. To start with the cryptocurrency exchange, you have to create an account in a cryptocurrency exchange. The exchange will then verify your account. When you want to buy the cryptocurrency, check the asks and when you want to sell the cryptocurrency, check the bids. The ask represents the lowest price sell order that is currently available in the market or the lowest price that someone is willing to go short. The bids represent the highest price buy order that is currently available in the market. Peatio Cryptocurrency Exchange Peatio is an open-source cryptocurrency exchange developed in Ruby On Rails framework. You can easily use the Peatio cryp

Transition Block in Rails with_lock

What is with_lock? how it work Ans:  If two users read a value from a record and then update it simultaneously, one of the values has to “win” and data integrity will be compromised. This is dangerous especially when dealing with money or inventory stocks. For example: User has a card balance = 10 User opens browser A and fill out 5 USD to buy User opens browser B and fill out 10 USD to buy User hits “Buy” button of both browsers at the same time Request A reads card balance=10 Request B reads card balance=10 Request A updates balance -= 5 (balance now is 10-5=5) Request B still has the instance card balance=10 (even though request A already decremented it) Request B updates balance -= 10 (balance now is 10-10=0) Final balance is now 0 User was able to purchase 15 USD when the initial balance was only 10 USD. This is race condition potentially at its worst case! Rails doesn’t do locking when loading a row from the database by default. If the same row of data from a table is loaded by t