teleren/devto huggingface dataset:
Binary search tree (BST) - Insertion
Published: 2022-08-09 15:20:00

**Để insert một node vào BST, chúng ta cần tuân thủ 4 quy tắc sau:**

- Các node mới luôn được chèn vào leaf node.
- Bắt đầu từ node root và gọi đệ quy cho đến khi pointer left, hoặc right == null.
- Nếu value của node hiện tại nhỏ hơn value của node mới, thì chuyển sang node bên phải của node hiện tại, còn lại chuyển sang node bên trái.
- Nếu node hiện tại là null, hãy insert node mới đó bằng cách gán node hiện tại = node mới


```
<script>
 
// javascript program to demonstrate insert 
// operation in binary search tree
// BST node
class Node
{
    constructor()
    {
        this.key = 0;
        this.left = null;
        this.right = null;
    }
};
 
// Utility function to create a new node
function newNode(data)
{
    var temp = new Node();
    temp.key = data;
    temp.left = null;
    temp.right = null;
    return temp;
}
 
// A utility function to insert a new
// Node with given key in BST
function insert(root, key)
{
 
    // Create a new Node containing
    // the new element
    var newnode = newNode(key);
     
    // Pointer to start traversing from root and
    // traverses downward path to search
    // where the new node to be inserted
    var x = root;
     
    // Pointer y maintains the trailing
    // pointer of x
    var y = null;
 
    while (x != null)
    {
        y = x;
        if (key < x.key)
            x = x.left;
        else
            x = x.right;
    }
     
    // If the root is null i.e the tree is empty
    // The new node is the root node
    if (y == null)
        y = newnode;
         
    // If the new key is less than the leaf node key
    // Assign the new node to be its left child
    else if (key < y.key)
        y.left = newnode;
         
    // else assign the new node its right child
    else
        y.right = newnode;
         
    // Returns the pointer where the
    // new node is inserted
    return y;
}
 
// A utility function to do inorder
// traversal of BST
function Inorder(root)
{
    if (root == null)
        return;
    else
    {
        Inorder(root.left);
        document.write( root.key +" ");
        Inorder(root.right);
    }
}
 
// Driver code
/* Let us create following BST
        50
    / \
    30 70
    / \ / \
20 40 60 80 */
var root = null;
root = insert(root, 50);
insert(root, 30);
insert(root, 20);
insert(root, 40);
insert(root, 70);
insert(root, 60);
insert(root, 80);
// Print inorder traversal of the BST
Inorder(root);
 
// This code is contributed by itsok.
</script>
```
**Output**
`20 30 40 50 60 70 80`
Modifying JSON - easy or difficult?
Published: 2022-08-09 15:18:54

You probably have many technical challenges to face in your work. Some of them are time-consuming, others fast to solve. Sometimes you face problems very well understandable and potentially easy to solve … but in the end, you see that plenty of hours were consumed to find a solution that should take less than an hour.

So… how about modifying JSON? Is it easy or difficult in Ruby (& Rails)?

Let's assume we have a simple structure with HTML fragments within:

```ruby
{
  "a": {
    "b": [
      {
        "c": "<span id=\"head\"></span>"
      },
      {
        "d": "<span id=\"body\"></span>"
      }
    ],
    "e": "#ffffff"
  },
  "f": "<span id=\"footer\"></span>",
  "g": 123
}
```

and we have a list of variables like:

```ruby
head = "Hey John!"
body = "I invite you to my Birthday party!"
footer = "Best regards."
```

Our goal is to find specific DOM fragments within that tree and inject text. Other values cannot be changed. So we'll end with something like that.

```ruby
{
  "a": {
    "b": [
      {
        "c": "<span id=\"head\">Hey John!</span>"
      },
      {
        "d": "<span id=\"body\">I invite you to my Birthday party!</span>"
      }
    ],
    "e": "#ffffff"
  },
  "f": "<span id=\"footer\">Best regards.</span>",
  "g": 123
}
```

Looks like the solution is quite simple. You can convert it to hash and use the **deep_transform_values** method in combination with the **nokogiri** gem.

```ruby
hash.deep_transform_values { |value|
  if value.is_a?(String)
    html = Nokogiri::HTML5.fragment(value)

    head_node = html.at_css("#head")
    body_node = html.at_css("#body")
    footer_node = html.at_css("#footer")

    head_node&.inner_html = head
    body_node&.inner_html = body
    footer_node&.inner_html = footer

    html.to_s
  else
    value
  end
}
```

… and that's all.
The Journey Thus Far
Published: 2022-08-09 15:13:00

![Alt Text](https://media.giphy.com/media/4mBzKXTeRmEOA/giphy.gif)

---

###Things have changed
Since the beginning we were preparing a presentation for our Umbrella Project, our over-arching project idea throughout the course of the apprenticeship, and now projects have been divvied out to us to work in pairs on. I'm certainly glad to have a partner to work with as it will make things that much more simple to get done.

The first 3 weeks of the apprenticeship we solely Monday-Friday with the Develop Carolina team and going through workshops to learn about various aspects of software development, UX design, and the product lifecycle as a whole.

Now its Mondays and Fridays with them and Tuesday-Thursday with our employer host company who will have us working with them on one of their projects. Thankfully my employer host is Booz Allen Hamilton, and I'm incredibly excited to work with them.

![Alt Text](http://www.nicknotas.com/wp-content/uploads/2011/06/Lets_Get_Physical.png)

---

###Collaboration and The Umbrella Project
In order to work well with my partner, I aim to have open and frequent communication. Especially since it's remote work, it can be even more difficult for us to be on the same page. So talking a lot and effectively talking will make us work well together. Along with being open to critique from each other. That's needed cause we both are in this together, so we should try to make it as perfect as possible.

That sense of collaboration is incredibly important because if we can't work together properly, how can we actually make a project that we are proud of that does what we want it to do? The same goes for my time at the Booz Allen. I hope to get to work together with my team, and work well with them as it's incredibly important, especially for such a large and renowned consulting company.


###That's a wrap
For now, those are all the major updates, I'm now working for Booz Allen and have a partner for the Umbrella Project which we are laying out the foundation for, but other than that we are still very much in the early stages. Can't wait to get into the deep end of everything.
Getting started with DevSecOps
Tags: devsecops, developersecurity, opensource, developertool
Published: 2022-08-09 15:00:16

_You might have heard a lot about DevOps, but what do you know about DevsecOps ?_

_Well in this blog, I am going to introduce this term and why we need to focus on DevSecOps as a key function._




### What is DevSecOps?

DevSecOps stands for Developer, Security and Operations. DevSecOps can be taken as DevOps process but with a security layer.

If we go by looking at the traditional DevOps model - the security process is almost absent but usually executed post-deployment which is not a very good idea for any kind of tool/application or project. DevOps revolves around three pillars - People, Product and Processes (as quoted by - Donavan Brown) but when we talk about DevSecOps, we apply security techniques to all these three components.

“The purpose and intent of DevSecOps is to build on the mindset that everyone is responsible for security with the goal of safely distributing security decisions at speed and scale to those who hold the highest level of context without sacrificing the safety required,” describes Shannon Lietz, co-author of the “DevSecOps Manifesto.”

![Image credits : Blog.mastek.com](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/65cq3ri374yub2umbucv.png)







DevSecOps is different from DevOps in the following ways -

- Continuous Integration, delivery and deployment to make sure security testing is regular and automated before the application is pushed to production.

- Application built like microservice

- Infrastructure as Code - planning, designing, implementing and managing app infrastructure through code


**Features of introducing DevSecOps-**

- Observability
- Traceability
- Compliance
- Confidence

**Following the Shift Left Trend :**

```
The earlier you run the security,
the better for your team, product and costs.
You don’t want your developers to work again
on the code base and other issues post-deployment.
This means, the engineers work on
security issues parallelly to working on the product.
```

Some tips that can make your security operations better when your application is under development -

- Make security part of backlog or sprint activity
- Assume breaches - progressively expose them to engineering teams so that vulnerabilities can be identified and fixed.

DevSecOps practices reduce the time to patch vulnerabilities and free up security teams to focus on priority work. As a process, they also ensure and simplify compliance, saving application development projects from having to be retrofitted for security.


There’s no doubt that DevSecOps revolutionizes the way organizations handle security for applications.  However, due to a variety of reasons—such as a lack of awareness of what DevSecOps is, there might be a shift in interests.


_**What’s next ?**_

After exploring DevOps, I am working on learning more about DevSecOps. Here is an open source tool for the same - [BoxyHQ](www.boxyhq.com)

Find Github : github.com/boxyhq
Join the BoxyHQ Discord Community **[here](https://discord.gg/TwXaPmxK)**
CSRF verification failed. Request aborted. in django rest framework
Tags: question, drf, csr, django
Published: 2022-08-09 14:46:03


halo i'm working on a project, using drf, but i'm getting CSRF verification failed. Request aborted at first everything was working, but now when i test my api i keep keep getting,CSRF verification failed below is my setting & view  codes

settings file 
```
REST_FRAMEWORK = {
    
    DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication
   ),

    'DATE_INPUT_FORMATS': [("%Y-%m-%d")],
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated'
    ),
    
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework.parsers.JSONParser',
        'rest_framework.parsers.FormParser',
        'rest_framework.parsers.MultiPartParser',
    ),
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 100

}
```

views
```
class createProfileView(generics.CreateAPIView):
    queryset = UserProfile.objects.all()
    serializer_class   = UserProfileSerializer
    permission_classes= [permissions.IsAuthenticated]
    parser_classes = (MultiPartParser, FormParser)

    def create(self,request, *args, **kwargs):
        serializer = self.get_serializer(
            data=request.data, instance = request.user.user_profile 
        )
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)
        headers = self.get_success_headers(serializer.data)
        res  = {
            'msg' : 'Profile successfully created',
            'status':status.HTTP_201_CREATED,
            'headers': headers,
            'data': serializer.data,
            
        }
        return Response(res)

    def perform_create(self, serializer):
        serializer.save(user=self.request.user)
```


can anyone help
Can code be poetic?
Tags: discuss, programming, writing
Published: 2022-08-09 14:42:00

_Disclosure: I'm not a software developer and I don't really have an opinion on this. I'm just curious what others think._ 💡

![Jimmy Fallon wearing all black and a beret and snapping his fingers. He looks like a stereotypical poet.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yru6dni0c6e8btq4vd93.gif)

Have you ever come across or created any code that you felt was poetic?

I've heard folks describe code as being written elegantly. I've also heard folks talk about leaving good guidance via comments in their code. But, I'm curious if anybody has seen anybody take these elements and try to make something creative or artistic out of it — not what the code creates, but the code itself.

What do you think? Can code be poetic or artistic in a writerly sense? Do you have any examples of code like this that you'd like to share?
CSRF verification failed. Request aborted. in django rest framework
Tags: question, django, csrf, drf
Published: 2022-08-09 14:37:00

halo i'm working on a project, using drf, but i'm getting CSRF verification failed. Request aborted at first everything was working, but now when i test my api i keep keep getting,CSRF verification failed below is my setting & view  codes

settings file 
```
REST_FRAMEWORK = {
    
    DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication
   ),

    'DATE_INPUT_FORMATS': [("%Y-%m-%d")],
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated'
    ),
    
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework.parsers.JSONParser',
        'rest_framework.parsers.FormParser',
        'rest_framework.parsers.MultiPartParser',
    ),
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 100

}
```

views
```
class createProfileView(generics.CreateAPIView):
    queryset = UserProfile.objects.all()
    serializer_class   = UserProfileSerializer
    permission_classes= [permissions.IsAuthenticated]
    parser_classes = (MultiPartParser, FormParser)

    def create(self,request, *args, **kwargs):
        serializer = self.get_serializer(
            data=request.data, instance = request.user.user_profile 
        )
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)
        headers = self.get_success_headers(serializer.data)
        res  = {
            'msg' : 'Profile successfully created',
            'status':status.HTTP_201_CREATED,
            'headers': headers,
            'data': serializer.data,
            
        }
        return Response(res)

    def perform_create(self, serializer):
        serializer.save(user=self.request.user)
```


can anyone help
MERN stack project for beginners
Tags: mernstack, javascript, beginners, tutorial
Published: 2022-08-09 14:25:00

**Youtube Tutorial: [https://youtu.be/7s7RHc_8SaU][yt-link]**
**Source Code: [github repo](https://github.com/ShaifArfan/mern-task-management-tool/tree/youtube-tutorial)**

**Made with ❤️ by [Shaif Arfan][arfan-ig]**

---

## Project Details

This project is for beginners only. In this project we are going to create a task management app (todo app). Where user create register an account with name, email, password. Inside the app user can create tasks, check tasks and delete tasks. Beside that user can update their own profile.

It is a simple app. In the project we didn't focus on styles, so the ui is simple.

## What we are going to learn/use

- **backend**
- [MongoDb](https://www.mongodb.com/)
- [Mongoose](https://mongoosejs.com/)
- [Express](https://expressjs.com/)
- [NodeJs](https://nodejs.org/)
- [jSON Web Token](https://jwt.io/)
- [bcrypt](https://www.npmjs.com/package/bcrypt)
- **frontend**
- [React](https://reactjs.org/)
- [react-router-dom](https://reacttraining.com/react-router/web/guides/quick-start)
- [react-hot-toast](https://react-hot-toast.com)
- [axios](https://www.npmjs.com/package/axios)
- [vite.js](https://vite.net/)

## Requirements

Basic knowledge of react and express.
if you don't have basic knowledge of express, then you can watch these videos [simple crud with express and mongoDb](https://youtu.be/jBoAG8yoRlo), [jwt auth with express](https://youtu.be/rXu9Z2yMZzA).

## Getting Started

You can follow our complete youtube tutorial [https://youtu.be/7s7RHc_8SaU
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dz9k4nef1lt6lozkzejc.png)][yt-link]

## Other projects

📚 [All Web Cifar Projects][wc-projects]

## Feedback

If you have any feedback, please reach out to us at [@web_cifar][wc-ig], or webcifar@gmail.com

## Get Support

For support, join our [Community Group][wc-fb-group].

Happy Coding! ✨🚀

[yt-link]: https://youtu.be/7s7RHc_8SaU
[arfan-ig]: http://instagram.com/shaifarfan08
[wc-ig]: http://instagram.com/web_cifar
[wc-projects]: https://github.com/ShaifArfan/wc-project-tutorials
[wc-fb-group]: https://www.facebook.com/groups/webcifar
Code Golfing Tips & Tricks: How to Minify your JavaScript Code
Published: 2022-08-09 14:22:16

If you are into JavaScript code golfing or just looking to minify your code, here’s a collection of tips and tricks to help you understand JavaScript intricacies and make your code shorter.

## What is Javascript Golfing?

JavaScript golfing is the process of writing the smallest amount of JavaScript code to do something awesome. It tests your ability to reduce, reuse, and recycle for the purpose of achieving the tiniest footprint possible.

## Why and when should minified code be used?

The purpose of code golfing is to test one’s abilities, during challenges. That said, you should not use techniques like this in your normal code, as it compromises readability. Ideally, you should only use these tricks during a challenge.

As the article is way too long, here's a link to the original article:

[Code Golfing Tips & Tricks: How to Minify your JavaScript Code](https://getbutterfly.com/code-golfing-tips-tricks-how-to-minify-your-javascript-code/)
Tarot Reader version 1.0
Tags: programming, project
Published: 2022-08-09 13:15:14

As part of Codecademy's CS101 Final Project, I took it upon myself to create a program that would give a spread of tarot cards and the meanings of the cards that were drawn.

In the body of the program's code, I created a class titled TarotCard, and created a list where every item in the list was made into a TarotCard object and given a meaning associated with the card, based on information credited in the source code itself. Below is a link to the source code that I've uploaded onto GitHub.
[
https://github.com/dylancortez727/tarot_project/blob/main/tarot.py](url)

In conclusion, I definitely enjoyed creating this project, and hope that I might be able to return to it in the future and add new details, such as readings for the minor arcana and even user interactability.
What is the !! (not not) operator in JavaScript?
Tags: javascript
Published: 2022-08-09 14:15:38

You will be aware of the [Logical NOT (!) operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT), which is used to negate the expression. In this article, we will see what is !! (not not) operator and its uses.

## Truthy and Falsy

Before understanding the not not (!!) operator, we need to understand what is truthy and falsy in JavaScript. Truthy value is a value that is considered `true` in a Boolean context. That means, if we have an expression as `if("John")`or `if(1)` then this will evaluate to `true`. Hence, a non-empty string, non-zero number, etc are considered as truthy.

Similarly, falsy is some value that evaluates to `false`. Examples are `0`, `''` `""`, `null`, `undefined` etc.

### Examples of truthy

The following are the expressions that will evaluate to `true`. Hence all the values inside the if conditions are truthy values.

```js
if (true)
if ({})
if ([])
if (42)
if ("0")
if ("false")
if (new Date())
if (-42)
if (12n)
if (3.14)
if (-3.14)
if (Infinity)
if (-Infinity)

```

### Examples of falsy

Following values are considered as falsy in JavaScript:

- false
- 0
- -0
- '', ""
- null
- undefined
- NaN

A complete list can be found [here](https://developer.mozilla.org/en-US/docs/Glossary/Falsy).

## The use of !! operator

Let's say we have a function called `getProductDetails` which returns the product details when a valid product id is passed. When an invalid product id is passed it may return an empty string or `undefined`. So the code for processing the product details received as a response would look like this:

```js
const product = getProductDetails(123)

if (product !== undefined || product !== "") {
  // Process product details
}
```

With the help of not not operator, we can shorten this as follows:

```js
const product = getProductDetails(123)

if (!!product) {
  // Process product details
}
```

`!!` is not an operator but two logical NOT (!) operators.
The first one (in the right) will convert the operand (the value under evaluation) to the negated boolean and the second ! will negate the boolean value again to get the boolean representation of the operand.

That is, `!"John"` will be evaluated to `false` and `!false` will be evaluated to `true`.

In case of a falsy value, `!0` will be evaluated to `true`, and `!true` will be `false`.

One interesting thing to note is that `!!new Boolean(false)` is `true` because `new Boolean(false)` will create an object, which is truthy even though it contains a false value.
HandleBuzz - Email Marketing Platform
Published: 2022-08-09 14:04:00

Email marketing is the best way to reach out to your niche audience. It's affordable and effective too. 

[Handlebuzz](https://www.handlebuzz.com) is an emerging email marketing platform. The email marketing services they provide come at an affordable price. They also give you a fully-featured dashboard to manage and run email marketing campaigns easily. What are you waiting for? 

Start now, For free - https://www.handlebuzz.com/


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gp1044anhiqbc96nypy1.png)
Video – A Brief Introduction to Microsoft Power Automate
Tags: development, video, flow, powerautomate
Published: 2022-08-12 14:31:15

---
title: Video – A Brief Introduction to Microsoft Power Automate
published: true
date: 2022-08-09 14:00:00 UTC
tags: Development,Video,flow,PowerAutomate
canonical_url: https://barretblake.dev/2022/08/video-a-brief-introduction-to-microsoft-power-automate/?utm_source=rss&utm_medium=rss&utm_campaign=video-a-brief-introduction-to-microsoft-power-automate
---

This week I’m presenting my first YouTube video: A Brief Introduction to Microsoft Power Automate. Give it a view.

<iframe title="An Introduction to Microsoft Power Automate" width="1200" height="900" src="https://www.youtube.com/embed/2MNnKel_9V8?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

The post [Video – A Brief Introduction to Microsoft Power Automate](https://barretblake.dev/2022/08/video-a-brief-introduction-to-microsoft-power-automate/) first appeared on [Barret Codes](https://barretblake.dev).