Posts

MySQL Multi Source Master Slave Replication using GTID

Image
We are using GTID-based master-slave replication. In this replication, both master and slave should have the same GTID. This blog post aims to provide a step-by-step guide to help you set up MySQL Replication using GTIDs and help you replicate your MySQL data with ease. Prerequisite Master Source 1 Channel name:  DEVELOPMENT Database: mydb1 Enable Replication For Tables testing1 testing2 testing3 Mysql Server Running: 192.168.0.201:3307 Master Source 2 Channel name:  PRODUCTION Database: mydb1 Enable Replication For Tables testing4 testing5 testing6 Mysql Server Running: 192.168.0.201:3308 Slave Mysql Server Running: 192.168.0.209:3306 Configuration of  masters(192.168.0.201:3307/192.168.0.201:3308) and slave (192.168.0.209:3306) my.cnf config for master (192.168.0.201:3307) my.cnf config for master (192.168.0.201:3308) my.cnf config for slave (192.168.0.209:3306) Steps for taking a dump and restoring it Run the following commands in both masters 192.168.0.201:3307 and 192.168.0.201:3

Dockerfile

Hey everyone, This article is about the Dockerfile that we use in building container images. It is nothing but a simple text file with instructions to build a custom image. Docker file helps us to provide instructions on what needs to be pulled, what arguments need to be run after building the image, and providing some configurations. FROM : Specifies the base image to use for the build. It is typically the first instruction in a Dockerfile. Example: FROM ubuntu:latest RUN : Executes commands in the shell of the container. These commands are run during the build process to install packages, configure the environment, etc. Example: RUN apt-get update && apt-get install -y python3 COPY or ADD : Copies files or directories from the host machine into the image. COPY is preferred for simple file copying, while ADD has additional features like extracting tar files and downloading files from URLs. Example: COPY app.py /app/ WORKDIR : Sets the working directory for any RUN, CMD, ENTRY

Regex 101: An Introduction to Regular Expressions for Developers

Regular expressions (regex) are a powerful tool for searching and manipulating text. They allow you to describe patterns of characters that you want to match, rather than specifying every possible combination of characters. In this blog, we will go over some common regex operations and provide examples for each one. Matching a literal string: regex: hello will match the string "hello". Matching any character: regex: . will match any single character. Matching a set of characters: regex: [aeiou] will match any single vowel. Matching a range of characters: regex: [a-z] will match any single lowercase letter. Matching a negated set of characters: regex: [^aeiou] will match any single non-vowel character. Matching zero or one occurrence: regex: a? will match either the string "a" or an empty string. Matching zero or more occurrences: regex: a* will match any string that contains zero or more "a" characters. Matching one or more occurrences: regex: a+ will matc

Helm Commands Cheatsheet

Hi everyone😎, Sharing helm commands that I use day to day. helm create: This command creates a chart directory along with the common files and directories used in a chart. Create a new chart with the given name:-  helm create [CHART]

Minimum Bracket Reversal

For a given expression in the form of a string, find the minimum number of brackets that can be reversed in order to make the expression balanced. The expression will only contain curly brackets. If the expression can't be balanced, return -1. Example : Expression : {{{{ If we reverse the second and the fourth opening brackets, the whole expression will get balanced. Since we have to reverse two brackets to make the expression balanced, the expected output will be 2. Expression : {{{ In this example, even if we reverse the last opening bracket, we would be left with the first opening bracket and hence will not be able to make the expression balanced and the output will be -1. Input Format : The first and the only line of input contains a string expression, without any spaces in between.   Output Format : The only line of output will print the number of reversals required to balance the whole expression. Prints -1, otherwise. Note :You don't have to print anything. It has alrea

Stock Span

Afzal has been working with an organization called 'Money Traders' for the past few years. The organization is into the money trading business. His manager assigned him a task. For a given array/list of stock's prices for N days, find the stock's span for each day. The span of the stock's price today is defined as the maximum number of consecutive days(starting from today and going backwards) for which the price of the stock was less than today's price. For example, if the price of a stock over a period of 7 days are [100, 80, 60, 70, 60, 75, 85], then the stock spans will be [1, 1, 1, 2, 1, 4, 6]. Explanation: On the sixth day when the price of the stock was 75, the span came out to be 4, because the last 4 prices(including the current price of 75) were less than the current or the sixth day's price. Similarly, we can deduce the remaining results. Afzal has to return an array/list of spans corresponding to each day's stock's price. Help him to achi

Longest Increasing Subsequence

Given an array with N elements, you need to find the length of the longest subsequence in the given array such that all elements of the subsequence are sorted in strictly increasing order. Input Format The first line of input contains an integer N. The following line contains N space separated integers, that denote the value of elements of array. Output Format The first and only line of output contains the length of longest subsequence. Constraints 1 <= N <= 10^3 Time Limit: 1 second Sample Input 1 : 6 5 4 11 1 16 8 Sample Output 1 : 3 Sample Output Explanation Length of longest subsequence is 3 i.e. (5,11,16) or (4,11,16). Sample Input 2 : 3 1 2 2 Sample Output 2 : 2  

Delete node (recursive)

Given a singly linked list of integers and position 'i', delete the node present at the 'i-th' position in the linked list recursively.  Note : Assume that the Indexing for the linked list always starts from 0. No need to print the list, it has already been taken care. Only return the new head to the list.  input format : The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow. The first line of each test case or query contains the elements of the singly linked list separated by a single space. The second line of input contains a single integer depicting the value of 'i'. Remember/Consider : While specifying the list elements for input, -1 indicates the end of the singly linked list and hence, would never be a list element Output format : For each test case/query, print the elements of the updated singly linked list. Output for every test case will be printed in a seperate line. C

Find path in BST

Given a BST and an integer k. Find and return the path from the node with data k and root (if a node with data k is present in given BST) in a list. Return empty list otherwise. Note: Assume that BST contains all unique elements. Input Format : The first line of input contains data of the nodes of the tree in level order form. The data of the nodes of the tree is separated by space. If any node does not have left or right child, take -1 in its place. Since -1 is used as an indication whether the left or right nodes exist, therefore, it will not be a part of the data of any node. The following line of input contains an integer, that denotes the value of k. Output Format : The first line and only line of output prints the data of the nodes in the path from node k to root. The data of the nodes is separated by single space. Constraints: Time Limit: 1 second Sample Input 1: 8 5 10 2 6 -1 -1 -1 -1 -1 7 -1 -1 2 Sample Output 1: 2 5 8  

Construct BST

Given a sorted integer array A of size n, which contains all unique elements. You need to construct a balanced BST from this input array. Return the root of constructed BST. Note: If array size is even, take first mid as root. Input format: The first line of input contains an integer, which denotes the value of n. The following line contains n space separated integers, that denote the values of array. Output Format: The first and only line of output contains values of BST nodes, printed in pre order traversal. Constraints: Time Limit: 1 second Sample Input 1: 7 1 2 3 4 5 6 7 Sample Output 1: 4 2 1 3 6 5 7  

Elements Between K1 and K2

Given a Binary Search Tree and two integers k1 and k2, find and print the elements which are in range k1 and k2 (both inclusive). Print the elements in increasing order. Input format: The first line of input contains data of the nodes of the tree in level order form. The data of the nodes of the tree is separated by space. If any node does not have left or right child, take -1 in its place. Since -1 is used as an indication whether the left or right nodes exist, therefore, it will not be a part of the data of any node. The following line contains two integers, that denote the value of k1 and k2. Output Format: The first and only line of output prints the elements which are in range k1 and k2 (both inclusive). Print the elements in increasing order. Constraints: Time Limit: 1 second Sample Input 1: 8 5 10 2 6 -1 -1 -1 -1 -1 7 -1 -1 6 10 Sample Output 1: 6 7 8 10  

Search In BST

Given a BST and an integer k. Find if the integer k is present in the given BST or not. You have to return true, if a node with data k is present, return false otherwise. Note: Assume that BST contains all unique elements. Input Format: The first line of input contains data of the nodes of the tree in level order form. The data of the nodes of the tree is separated by space. If any node does not have left or right child, take -1 in its place. Since -1 is used as an indication whether the left or right nodes exist, therefore, it will not be a part of the data of any node. The following line of input contains an integer, that denotes the value of k. Output Format: The first and only line of output contains a boolean value. Print true, if node with data k is present, print false otherwise. Constraints: Time Limit: 1 second Sample Input 1 : 8 5 10 2 6 -1 -1 -1 -1 -1 7 -1 -1 2 Sample Output 1 : true Sample Input 2 : 8 5 10 2 6 -1 -1 -1 -1 -1 7 -1 -1 12 Sample Output 2 : false  

Access and modify all the resources of our Wiki.js using WikiJS API

Image
Hi everyone 😎 , Today we are going to see how to access or modify WikiJS resources using WikiJS API. WikiJS exposes GraphQL API to access and modify the stuff according to our requirements. So In this blog post, we going to see  How to set up WikiJS's local environment using docker. How to generate an API token in Wikijs. Using API tokens how to access WikiJS resources and how to modify them. First Local Setup using docker Here I am using docker to set up my local isolated WikiJS environment. Below is my docker-compose.yml file written by WikiJS contributors. To build the WikiJS environment we just need to run the following command  docker-compose up -df  [PATH_OF_DOCKER_COMPOSE_YML_FILE] To check the environment is in a running state run the following command docker ps Second Generate API token After setup our local environment we are ready to create our initial Administrator account in our WikiJS. 1. On the browser type localhost:80 2. Create an Administrator account  Email: loc

Setup MongoDB statefulset on AWS Fargate

Image
Hi everyone I am Manshu Sharma and today we will see how can we deploy the mongoDB on AWS fargate as a  statefulset  with help of the mongoDB community operator but before we start let's have a quick overview of two important terms statefulset,   stateful application . What actually statefulset is in Kubernetes? StatefulSet is a Kubernetes resource used to manage stateful applications and It manages the scaling , ordering and uniqueness of each pod. It requires headless service and we are responsible for creating this service. What actually is stateful applications? Stateful applications are those programs that save client data from the activities of one session for use in the next session. Consider it as an ongoing periodic conversation with the same person. Some examples of stateful applications are MySQL,    MongoDB, FTP server,  Redis Cache, Kafka  and any Login service that stores client authentication data on the server, labelling clients as having a “connected” or “discon

How to share a custom AMI to other accounts

Image
Hi everyone 🙂, I am Manshu Sharma and today we are going to discuss an interesting topic that will help us to share custom private AMI in all accounts & regions. In this post first, create a custom encrypted AMI from the public AMI, and then share the custom AMI with encrypted EBS snapshots across accounts and regions. This approach allows you to launch Amazon EC2 instances globally from multiple accounts by using the same base-encrypted AMI. Requirments We need two AWS accounts i.e SourceAccount & DestinationAccount Have a basic knowledge of AWS services SourceAccount:- In which you build a custom AMI and encrypt the associated EBS snapshots. DestinationAccount:- In which you launch instances using the shared custom AMI with encrypted snapshots. Note :- While writing this blog post I am considering two imaginary AWS account ids  111111111111   with region us-east-1 for  SourceAccount & 999999999999   with us-east-1 for DestinationAccount so be sure you replace this acco

Min Steps To 1

Given a positive integer 'n', find and return the minimum number of steps that 'n' has to take to get reduced to 1. You can perform any one of the following 3 steps: 1.) Subtract 1 from it. (n = n - ­1) , 2.) If n is divisible by 2, divide by 2.( if n % 2 == 0, then n = n / 2 ) , 3.) If n is divisible by 3, divide by 3. (if n % 3 == 0, then n = n / 3 ). Input format : The first and the only line of input contains an integer value, 'n'. Output format : Print the minimum number of steps. Constraints : 1 <= n <= 10 ^ 6 Time Limit: 1 sec Sample Input 1 : 4 Sample Output 1 : 2 Explanation of Sample Output 1 : For n = 4 Step 1 : n = 4 / 2 = 2 Step 2 : n = 2 / 2 = 1 Sample Input 2 : 7 Sample Output 2 : 3 Explanation of Sample Output 2 : For n = 7 Step 1 : n = 7 ­- 1 = 6 Step 2 : n = 6 / 3 = 2 Step 3 : n = 2 / 2 = 1

Jenkins :- Run a remote command on all Jenkins slaves via Master

Image
Hi everyone 😀, Today I want to share a solution related to run a common command in all slave nodes via the master node in Jenkins using the Jenkins pipeline. I also faced a similar issue before where I had to run docker related commands in all nodes. The approach is simple  First, we need to define an agent in our Jenkins pipeline. Second, we need to define two stages first one for the master (optional) and the second one are for slaves. Third, we need some built-in functions jenkins.model.Jenkins.instance.getNodes() :-  Returns all Node s in the system, excluding Jenkins instance itself which represents the built-in node slave.toComputer().isOnline() :-  To check slave node is online getDisplayName() :-  To get the name of the slave node thereafter we create a user-define function and in this,  we define two loops first one for getting all names of slave nodes and the second one is to define a node-block that is capable of executing commands in the slave nodes. The function will loo

Popular posts from this blog

How to pass parameters in webhook?

Access and modify all the resources of our Wiki.js using WikiJS API

Fahrenheit to Celsius