teleren/devto huggingface dataset:
Stack Permutation
Tags: geeksforgeeks, algorithms, stack, solution
Published: 2022-09-07 18:10:42

## Problem Statement

You are given two arrays A and B of unique elements of size N. Check if one array is a stack permutation of the other array or not.
Stack permutation means that one array can be created from another array using a stack and stack operations.

Link to the problem statement:: https://practice.geeksforgeeks.org/problems/stack-permutations/1

> Example 1:

```
Input:
N = 3
A = {1,2,3}
B = {2,1,3}
Output:
1
Explanation:
1. push 1 from A to stack
2. push 2 from A to stack
3. pop 2 from stack to B
4. pop 1 from stack to B
5. push 3 from A to stack
6. pop 3 from stack to B
```

> Example 2:

```
Input:
N = 3
A = {1,2,3}
B = {3,1,2}
Output:
0
Explanation:
Not Possible
```

#### Expected Time Complexity: O(N)

#### Expected Auxiliary Space: O(N)

## Solution

How could a stack permutation be checked when you have input and output, the best way is to replicate the stack itself and enter the input.

Also while entering input, if any occurrence of output comes in we as the output needs to stimulate the stack ie, pop out the element. This needs to be done. While performing these operations whenever we encounter any illegal operation like,
1. stack underflow, or 
2. output array iteration completed but stack still empty or 
3. stack top and output array iteration point does not match and there is no other input operation that could make use believe that there might come a situation validating the permutation.

In these invalid cases, there is a clear answer indicating this permutation is not possible. When you see there is no more element in stack and output are is satisfied till the end, it is an indication you have achieved your permutation.

```
class Solution {
    public static int isStackPermutation(int n, int[] ip, int[] op) {
        Stack<Integer> stack = new Stack<>();
        int opItr = 0;
        for(int i = 0; i < ip.length; i++) {
            while(opItr < op.length && !stack.isEmpty() && stack.peek() == op[opItr]) {
                stack.pop();
                opItr++;
            }
            stack.push(ip[i]);
        }
        while((opItr < n) && !stack.isEmpty() && (stack.peek() == op[opItr])) {
            opItr++;
            stack.pop();
        }
        return (opItr == n && stack.isEmpty())? 1 : 0;
    }
}
```
Day 1: Getting the basics down
Tags: python, beginners, programming
Published: 2022-09-07 18:02:10

Things I learnt on **Day 1** of coding Python:

1. Using the "F string" to join text with variables used in the code 
2. How to create functions and how to call functions
3. Setting up if and elif statements within the code
4. How to use a dictionary and call elements within the dictionary

Listening to the course I felt like it was easy and I got the basics down, however, when I tried to recreate the game (Of course it was the Rocks, Paper, Scissors game) I was lost in the nitty gritty of it all and struggled in almost every line of how to do certain things.

On my 2nd try yesterday, I did manage to get it right, being a bit slower and taking only a litttlee bit of help from the tutorial.

However, today, when I revisited the game, I was able to recreate almost 91% of the code by myself and only needed a bit of clarification at the end. 

So, here is my 91% of the code I recreated again. I know it is basic, but it helps me keep track and learn.

## CODE: ROCK, PAPER, SCISSORS

```
import random

def get_choices():
    player_choice = input("Enter your choice :")
    options = ["rock", "paper", "scissors"]
    computer_choice = random.choice(options)
    choices = {"player": player_choice, "computer": computer_choice}
    return choices


def check_winner(playerchoice, computerchoice):
    print(f"You chose {playerchoice} and computer chose {computerchoice}")

    if playerchoice == computerchoice:
        return "It is TIE"
    elif playerchoice == "rock":
        if computerchoice == "paper":
            return "Paper covers rock. You lose!"
        elif computerchoice == "scissors":
            return "Rock smashes scissors. You win!"
    elif playerchoice == "paper":
        if computerchoice == "rock":
            return "Paper covers rock. You win!"
        elif computerchoice == "scissors":
            return "Paper cut by scissors. You lose!"
    elif playerchoice == "scissors":
        if computerchoice == "paper":
            return "Paper cut by scissors. You win!"
        elif computerchoice == "rock":
            return "Rock smashes scissors. You lose!"


choices = get_choices()
result = check_winner(choices["player"], choices["computer"])
print(result)

```
int32 to IPv4
Tags: codewars, javascript, problemsolving, beginners
Published: 2022-09-07 17:39:55

As you can see in the below screenshot, it has the problem description and what the input and output are supposed to be - <br>
![Problem description and examples of input and output screenshot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8vsjbfcyiqs8n5mzpvhd.jpg)

The input would be an integer e.g.
> 2149583361 

The output must be in IPv4 format e.g.
> "128.32.10.1"

The programming language used here is Javascript but you can use any language of your choice.

Approach - 
- Convert the decimal integer to its binary representation
- Convert the binary form to its 32 bit form
- Divide the 32 bits into 8 bits each and store them in an array
- Convert all 8 binary bits to its decimal form
- Store them as a string

The steps would be -

- Take a variable and store the input in it

`let int32="2149583361";`

- Take another variable and convert the input from decimal to binary using Javascript's inbuilt toString() method and providing it the parameter 2 to convert the decimal integer to its binary string

`let s=int32.toString(2);`

- Take an empty variable and store 0's in it of length => 32-(length of string)

```
let zero_s="";
  let temp=32-s.length;
  for(let i=0;i<temp;i++) 
    zero_s+="0";
```

- Take another variable and store the final 32 bits string by appending the zero bits string to the original input string

`let res_s=zero_s+s;`

- Use a for loop to traverse through the 32 bit string and split them into 8 bits each part and store them in an array

```
let array=[];
  let z=0;
  for(let j=0;j<4;j++) {
    let r=res_s.substring(z, 8+z);
    array.push(r);
    z+=8;
  }
```

- Take another array to store the converted decimal strings element using Javascript's inbuilt parseInt() method
  
```
let array2=[];
  for(let k of array) {
    let qq=parseInt(k, 2);
    array2.push(qq);
  }
```

- Print the output by converting the array into a string using dots(.) to seperate them with the help of join() function

`return array2.join(".");`

This problem uses the concept of decimal to binary conversion and vice-versa. 

It also jogs your memory to array to string conversion and vice-verse.
Why Python is best choice for Data Science?
Tags: python, datascience
Published: 2022-09-07 17:26:17

Dear Devs: You've come to the right place if you're wondering which programming language to study if you want to work as a data scientist in 2022. I've already revealed the top Python and data science courses, and today I'll explain why learning Python is the greatest option for data science.

Python and R are the two main programming languages available when learning data science and machine learning, however [data science with Python Training](https://www.igmguru.com/data-science-bi/python-training/) is preferred by the majority of data scientists and machine learning experts.

I spent a lot of time wondering why Python is so beloved by data scientists. And what makes Python the only language to choose for machine learning and data science research.

To learn more, I started reading a lot of papers and books and enrolling in Data Science classes using both Python and R. What I discovered, however, was nothing more than unexpected.

It was actually a very straightforward rationale that gave Python an advantage over R and other popular programming languages like Java, C++, Ruby, and JavaScript.

Everyone, from novice to seasoned programmers, loves Python for its ease of use and robust set of libraries and tools that make dealing with data quite simple.

For instance, using the Padas library, you may quickly clean up unprocessed survey data before utilising it to build your machine learning model. Python makes this task more simpler than it would be in other programming languages like Java, which would require you to write a lot more code.

Python is the top programming language for data science and machine learning in 2022 due to its simplicity, faster learning curve, robust toolkit, and library.
ptc print: a modern C++ implementation of the Python print() function with further improvements
Published: 2022-09-07 17:17:43

Hello everybody,

I want to present you `ptc::print` a modern C++ library for custom printing to the output stream. It is basically a detailed implementation of the Python `print()` function, with several additions.

In particular, some of its features are:

- It is constructed through the `Print` functor, which is a fully type- and thread-safe class with automatic memory management, implemented through an header-only library, with no external dependencies. 
- It supports also the usage of ANSI escape sequences.
- It supports the printing of all the standard types and also std ones (`std::vector`, `std::map` etc...).
- It is possible to choose to print using different char types (`char`, `wchar_t`...).

And has a very very simple syntax:

```
#include <ptc/print.hpp>

int main()
 {
  ptc::print("Hello", 123, nullptr, "bye");
 }
```

It has also many more features like the possibility to choose end and separator characters (like in Python) or to set a pattern among each printed argument.

In the main readme you can find all the information you want, a list of todo stuff and some preliminar benchmarking studies I performed with respect to other similar libraries.

If you like the repo don't forget to leave a star on GitHub! Thanks.

Repository link: https://github.com/JustWhit3/ptc-print
Micro-frontend Pratical guide - Part 1
Tags: javascript, react, microfrontend
Published: 2022-09-07 17:12:07

---
title: Micro-frontend Pratical guide - Part 1
published: true
description: Advance Frontend Learnings
tags: javascript, react, microfrontend
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
---

## What is Micro-frontend?

It is an advanced FE concept used when the codebase is very big and large number of developers actively working on it.

Micro-frontend architecture become famous after the success of microservices architecture where the backend is divided into different services each having its API layer, and database. 

Micro-frontend architecture allows us to build a single application from multiple separate builds (commonly known as modules). These modules can be technology agnostic, team can work and deploy independently. 

For example - A Ecommerce company can have multiple teams working on a single web application 
1. Home screen team - specializes on loading home screen content lighting fast
2. Cart team - focus on cart journey 
and so on. 


## Do you need to have Microfrontend architecture in your side projects?

Yes and No. 
If you want to learn then yes, there is no other way you can get practical knowledge. 
Will it have any performance or other impact? - No. 
Setting it up as architecture is time-consuming and an extra burden of maintaining different repositories.   

## Pros and Cons

### Pros 
* **Scalability** - Useful for complex codebase with large numbers of developers. Easier to scale project by incremently growing team working on individual module
* **Allow usage of multiple framework** - Each team can choose its framework based on team expertise.
* **Faster development and deployment** - Each team can work on its module independent of other team. Once a module is updated or deployed, it will be available in the main app without the need for redeployment of main app. 
* **Maintainability** - Easy to maintain module as compared to complete app. 

### Cons
* **Complexity** - Setting up micro-frontend architecture is complex and time-consuming. 
* **Team Dependency** - If a module is down then corresponding feature will be down affecting the complete app. 
* **Team Communication** - Communication gap can lead to duplicate methods, functionality across different modules


### Implementation Guide is available [here](https://dev.to/rv90904/micro-frontend-pratical-guide-part-2-3262)
undefined and null in JavaScript
Published: 2022-09-07 16:56:28

Undefined means a variable has been declared but there is no value assigned yet in that variable. Unassigned variables are initialized by the default value of undefined in JavaScript. Good to said, the value does not exist in the compiler. It is the global object.

Null means an empty or non-existent value, null is also an object. Good to said, It is the intentional absence of the value. It is one of the primitive values of JavaScript.
Epic Todo ✅
Tags: javascript, webdev, programming, beginners
Published: 2022-09-07 16:53:18

> **Implement a full-stack todo application in different tech stacks using different tools and techniques**

## Aim ✨
_To make a fullstack todo application with different variations of backend api's (REST, Graph, RPC) and frontend libraries/frameworks (React, react-native, Nextjs, graphql-client) using different tools and techniques._

## Overview 📚
- Build different versions of client using `react, react-native, nextjs`
- Use different client-side tools `react-query, axios, redux, redux-saga, mobx, custom hooks, graphql-client, react-bootstrap, tailwind-css, chakra-ui`
- Use different rendering strategies `CSR, SSR, ISR (all using nextjs)`
- Build different versions of server api using `REST (MVC architecture), Graph (graphql), RPC (tRPC/gRPC)`
- Use different server-side tools `joi, yup, zod, jwt, express-jwt, bcrypt, argon2d, morgan, express, busboy, formidable, multer, helmet, winston`
- Use different databases `postgres (SQL), mongodb (noSQL)`
- Use different ORMs `prisma, mongoose, typegoose`
- Use firebase tools `firebase-auth, firestore`
- Implement basic CI/CD using `github-actions`
- **Setup horizontal scaling with `pm2, nodejs-built-ins (fork, process, worker)`
- **Use message-queues `rabbit-mq, bullmq`
- **Use server-side caching `redis`
- **Use websockets with `socket.io`

> PS: All items marked with _(**)_ will be low priority

<br>

## Procedure 👨‍🔬
- Different versions of frontend todo-client using different libraries mentioned above.
- Fetch data using different tools mentioned above.
- Experiment with different client-side techniques like lazy-loading, Suspense, code-splitting and component-injection.
- Experiment different techniques in server-side like refresh-token/access-token, email verification, logging, clusters, thread-workers, caching, sticky-sessions.
- Enable basic CI/CD for projects.
- All different variations of stack will be in different branches of this repository.

## Outcome 🎯
- Learn these different tools and tech stacks.
- Experiment with a variety of 3<sup>rd</sup> party services like firebase-auth and firestore, other ecosystem tools.
- To Become a better full-stack engineer.

## Why a todo-app ⚛️
- Its a dynamic application which requires GET, POST, PUT/PATCH, DELETE operations in terms of database operations.
- We can build this app with many variations and the codebase size will be manageable by a single or small group of devs who want to learn and explore hands on.
- We can experiment and prototype rapidly since the application logic is simple.
- We can then increase the engineering complexity and not feel lost due to simple nature of application.

### **Attention ( _for developers_ ) 🛑
_This repository code is based in the nodejs and javascript ecosystem, we will mainly work with javascript and add typescript functionality in a different branch._



> Visit the repository on Github [Epic-Todo](https://github.com/utsavo-afk/epic-todo)

_PART I 👉 Full-stack todo app built using react, express and mongodb (coming soon!)_

```Let me know if you'll be following along with the progress down in the comments 🥳```
Day-8 of Machine Learning
Tags: beginners, machinelearning
Published: 2022-09-07 16:50:55

Day-8 of Machine Learning:
- Scaling features using mean normalization and Z-score normalization.
- Explore impact of learning rate on convergence. The learning rate controls the size of the update to the parameters. If learning rate value is bigger, then cost increases and don't reach at local minima. similarly, if of learning rate is smaller value then it takes more iterations to reach at local minima.
React: Code splitting
Tags: javascript, react, tutorial, programming
Published: 2022-09-07 16:05:16

Hi everyone! recently I was working on complex multiple module react app and also it has lots of dependencies on third party libraries. So the loading time of some of the components was beyond its expectations and the size of bundle was the other part.

Any web application will be user accessible/friendly only if the response time is lowest as possible and smaller bundle size will  improvise build time and save storage.

Bundling is a process to merge all imported modules in a single files. Bundling is good when size of dependencies is small but as dependencies grow merging in a single file is a problem. Here code splitting comes in a picture, Code splitting is a feature supported by [Webpack](https://gist.github.com/gaearon/ca6e803f5c604d37468b0091d9959269) and comes pre-configured with [code-react-app](https://create-react-app.dev/docs/code-splitting/).

## Code Splitting
It is a process to lazy load only the things that are required by our application causing speeding up the load time of our application. With code splitting the code that is never needed will not be loaded and the code size will be lower at initial build.

### Dynamic imports

```
let sortedString = import('./StringUtils')
    .then(StringUtils=>{
        StringUtils.sort(str)
    })
    .catch(err=>{
    //handles error
   })

```
In the example, StringUtils module is not imported before this code and the bundle size is smaller. When webpack comes across this syntax it automatically starts code splitting. 

### React.lazy

Lets you render dynamic imports as regular components. It automatically renders the bundle containing the component when it is first rendered.

`let UtilsComponent = React.lazy(()=>import('./StringUtils'))`

React.lazy takes a function as input that imports a module and returns a promise that resolves into a module with a default export to a component.

### React.suspense

React.suspense is used to render lazy components which shows fallback component until we are waiting for lazy component to render.

```
import React, { Component, Suspense } from 'react'

export default class Statics extends Component {
  render() {
    let RandomColor = React.lazy(()=>import('./RandomColor'));
    return (
      <div>
        <Suspense fallback={<div>Loading....</div>}>
          <RandomColor/>
        </Suspense>
      </div>
    )
  }
}
```

fallback props of React.Suspense takes any component that will be displayed until the lazy component is loaded.

So here we have solved both of are problem, our bundle size is smaller since we are dynamically importing components only when they are required. Load time is also low as the bundle size is low due to dynamically importing components.

That's all for today, until then Happy Coding!..
Insider, Criminal organization
Published: 2022-09-07 16:33:24

---
title:  Insider, Criminal organization

published: true
description: 
tags: 
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
---
##Insider
Those are the objects or persons that add the virus software or piece of code into the organization's system or database for their personal gain or for the profit of another organization.
there can be an employee of that organization or company or part-time employee, any contractor or businessman person that can be a familiar of that company.
This type of person has some privileges and rights to access some private type of data that can't access by any unauthorized person. He or she misuses their privileges and give's that private information to another person who uses that information and harms that organization.
##Criminal organization
A Cyber-Criminal is a criminal that makes a crime through a computer device or any other electrical smart device. they use the as a weapon.
They target any type of software system, Database, or personal computer.
They attack anyone for any personal gain or for the organization's profit and make a target in the loss.
They use computers in this crime in three components
As a weapon
As a target
As an accessory
* As a weapon
The hacker or cracker uses the computer as a weapon to load the virus or threats into the target's computer.
for sending spam messages to another's computer for fraud, theft of data, and getting back account/Id.
* As a target
The hacker sends the malware and viruses to the target and clear all information and get access to those computer or PC. -They do some takes or get access like their ID and get those privileges and perform illegal tasks.
* As a accessory
The hackers use the computer as an accessory to store the data it. And they store some illegal information in it and hide those from everyone.

##The cybercriminals work in a group that was divided into 4 parts mainly:
###Programmer:
They write the programs and make the software to hack the system or create tools that help to access data unauthorisedly.
###Distributers:
They sell the data and information that comes after getting hack the system or any database for money or other there demands.
###IT Expert:
They manage the overall server of their group and manage the devices and boost the performance of the device and help to go faster in work.
###Hackers:
They actually exploit and damage the server and get those vulnerabilities.