teleren/devto huggingface dataset:
ArtDraw SVG Editor
Tags: javascript, svg, design, draw
Published: 2023-01-19 15:21:57

Another SVG editor...
At the moment my head is full of javascript, beziers, and a lot of concepts about the SVG standard.
At the beginning the task seemed that it could be done in 2 or 3 months, today 6 months later... I believe that it lacks otron 6 months more...
A great advantage was that I could use some Javascripts libraries that speed up the work. The problem is that to find the perfect library, you have to test and test.


![ArtDraw SVG Editor Online](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4bdwdjz5nvl6yjk29e1y.jpg)

And the headache of performing boolean operations between shapes... Clipper is a great help, except for the problem that the
result is a polygon with thousands (literally) of nodes.

More than a job, this has been a constant learning experience. My Javascript was very rusty and this has been a work in between browser tabs. Minimize the work and open Stackoverflow...

If you want you can take a look at the work.
[ArtDraw SVG Editor Online](https://artdraw.muisca.co/svg/app.html)


![SVG Editor Online](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ynmpdcco0poge1k8j17u.png)

There is still a lot to do, bugs to fix, toys to add... Wow, work... 
And finally, get traffic and publicize the program. And I think that is more complicated than programming the application.
Binary Search Algorithm
Published: 2023-01-19 15:11:46

Binary search is an efficient algorithm for finding an item from a sorted list of items. It works by repeatedly dividing the search interval in half. The idea is to determine, in logarithmic time, whether the item you are searching for is in the lower or upper half of the interval. If it is in the lower half, you repeat the process on that half; if it is in the upper half, you repeat the process on that half. This process continues until the item is found or the search interval is empty.

Here is an example of a binary search algorithm implemented in Python.

```
def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid - 1
        else:
            low = mid + 1
    return None

my_list = [1, 3, 5, 7, 9]

print(binary_search(my_list, 3)) # Output: 1
print(binary_search(my_list, -1)) # Output: None

```

In this example, we define a function called binary_search() that takes in two parameters: an array and a target element. The function uses a while loop to repeatedly divide the array in half until the target element is found or the array is exhausted. The loop starts by setting two pointers, left and right, to the first and last elements of the array, respectively. The pointer mid is set to the middle of the array by taking the average of left and right. If the element at the mid index is equal to the target element, the function returns the index of the target element. If the element at the mid index is less than the target element, the left pointer is set to one position to the right of mid. If the element at the mid index is greater than the target element, the right pointer is set to one position to the left of mid. The loop continues until the left pointer is greater than the right pointer, at which point the function returns -1 to indicate that the target element was not found in the array. It’s important to note that the array should be sorted to be able to use binary search. In the example above, the array is sorted in ascending order. Binary search has a time complexity of O(log n) which is faster than linear search (O(n)), which makes it suitable for large datasets.

JavaScript and C++ example on this [post](https://mahiuddin.me/blogs/binary-search-algorithm/)
AWS Hosting on a Budget: How to Cut Costs by 10x
Tags: aws, devops, cloud, tutorial
Published: 2023-01-19 15:07:20

​​It's not a surprise that plenty of companies spend more than they should on AWS services. The larger the organization, the greater the expense. Just hosting can run a couple of thousand dollars annually for a single application or corporate website. When you factor in multiple development environments and additional apps, the total cost for cloud hosting could rise from tens of thousands to hundreds of thousands per year. However, there are several simple ways to significantly lower your bill. Let's explore a few tips.

Let me show you, how in a few clicks you could reduce your AWS hosting price by 90%

_Everything I will write below has been tested in practice. Here is an example of how one of [our](https://uuusoftware.com) clients' accounts looked like_


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pr1ib1sqdr10ch6lxefj.png)

**Choosing a more efficient EC2 instance** can significantly reduce costs. Upgrading to higher generation tiers, such as the newest T3 tier, can provide significant performance gains. For example, upgrading from T1 to T3 and moving from "medium" to "nano" can result in such a significant performance increase that T1.medium will run faster than T3.nano, while reducing the monthly cost from $36 to $3.

Saving money by **not using RDS instances for low-load applications** can also be a cost-effective solution. For example, if your application has 200-300 daily users, you can delete an RDS instance, which will save you $19.80 per month. Instead of deleting the database, you can move it to the same EC2 T3.nano instance by installing the database server directly in that instance. Although the instance has only 500 MB of RAM, creating a 3-4 GB swap file can be sufficient to host web servers and databases on the same instance for low-load applications.

Reducing the size of the **storage used to store the snapshots** can also help reduce costs. Snapshot volumes also incur costs. For example, if you have 124 GB of total storage but only use 20% of it, reducing the volume to 25 GB can reduce the price from $13.52 per month to $3.49 per month.

And finally. **Removing other unused instances** is a good practice to reduce costs. It is recommended that you review your resources monthly and determine which ones can be removed, such as storage, snapshots, or services. Keep in mind that very few resources in AWS are free.

And that's how our client bill looked after all the changes I wrote above:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f97yclbxwpy9rmd8e6x1.png)

Woohoo!
How to import server or client certificate on AWS Certificate Manager (ACM)
Published: 2023-01-19 14:48:18


## How to import server or client certificate on AWS Certificate Manager (ACM)

AWS certificate manager (ACM) is certificate store we can either request a public ceritificate or import a certificate into ACM.

For several reasons we import the certificates into ACM and use it for client server mutual certificate based authentication. one of the example is when we setup AWS client VPN and one of the authentication method is mutual certificate authentication and we need to create and import the server/client certs into AWS.

Below is the steps how to create and upload a server/client certifiate into AWS ACM. Its using OpenVPN easy-rsa tool to create the cert and the keys.

Download the easy-rsa tool into your local computer and locate easy-rsa/easyrsa3 folder.

**$ git clone https://github.com/OpenVPN/easy-rsa.git**

**$ cd easy-rsa/easyrsa3**

Initialize new PKI environment. this will cleanup all existing CA, certs or keys inside easy-rsa folder. we would need to backup those before doing this.This will create new ca.crt and ca.key into the easyrsa3 folder.

**$ ./easyrsa init-pki**

Generate server certificate and the key. This will create server.crt and server.key into the easyrsa3 folder.

**$ ./easyrsa build-server-full server nopass**

Generate client certificate and key.

**$ ./easyrsa build-client-full client1.domain.tld nopass**

Copy the .crt and .key files into common folder and intiate aws cli comand to import the certificate into AWS ACM. You can find the .crt files into easy-rsa/easyrsa3/pki/issued folder and .key files into easy-rsa/easyrsa3/pki/private folder.Make sure the user has access to imort ACM certificates.

To import server certs

**$ aws acm import-certificate — certificate fileb://server.crt — private-key fileb://server.key — certificate-chain fileb://ca.crt**

To import client certs

**$aws acm import-certificate — certificate fileb://client1.domain.tld.crt — private-key fileb://client1.domain.tld.key — certificate-chain fileb://ca.crt**
Property 'id' does not exist on type 'string | JwtPayload' [duplicate]
Tags: typescript, node, jwt, mongodb
Published: 2023-01-19 14:46:57

I just want to get user by id but I got an error that states id does not exist on type string , my code is shown below:

```
import asyncHandler from "express-async-handler"; 
import { NextFunction, Request, Response } from "express";
import User from "../models/User";
import jwt from "jsonwebtoken";
import configs from "../config/config";

const protect = asyncHandler (async (req: Request, res: Response, next: NextFunction) => {
    try {
        const token = req.cookies.token
        if (!token) {
            res.status(401)
            throw new Error("Not authorized, please login");
        }

        // Verify Token
        const verified = jwt.verify(token, configs.JWT_SECRET)

       // Get user id from token
       const user = await User.findById(verified.id).select("-password")

       if (!user) {
        res.status(401)
        throw new Error("User was not found")
       }
       req.user = user
       next()

    } catch (error) {
        
    }
});

export default protect;
```
sudoedit (`sudo -e`) に係る脆弱性 (CVE-2023-22809)
Tags: sudo, sudoedit, security, vulnerability
Published: 2023-01-19 14:31:43

## 脆弱性情報

[`sudo`](https://www.sudo.ws/) の、sudoedit (`sudo -e`) に係る脆弱性です。任意のファイルを変更され、権限奪取、およびそれをもとにした情報窃取が行われるおそれがあります。

### CVE

[CVE-2023-22809](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-22809)

### 影響範囲

公式サイトには [次のように書かれています](https://www.sudo.ws/security/advisories/sudoedit_any/#impact):

> If no users have been granted access to sudoedit there is no impact.

(私訳: sudoedit へのアクセスが許可されているユーザーが存在しない場合、影響はありません。)

一例を挙げます。`/etc/sudoers` (あるいは `visudo` の編集先) に次のような行が存在する場合:

```conf
someuser ALL=(root) sudoedit /etc/some.conf
```

`someuser` は本件の不具合を悪用することで他のファイルを編集できます。

## 対応方法

1.8 以降のバージョンの場合、2023-01-19 本日リリースの最新版 ([1.9.12p2](https://github.com/sudo-project/sudo/releases/tag/SUDO_1_9_12p2)) に更新することが推奨されています。

### 暫定対応

すぐのアップデートが難しい場合、

sudoers に 1 行追加することでリスクを軽減できる、と公式サイト (英語) で [案内](https://www.sudo.ws/security/advisories/sudoedit_any/#workaround) されています:

```
Defaults!sudoedit    env_delete+="SUDO_EDITOR VISUAL EDITOR"
```

## 参考

本記事は[小社のツイート](https://twitter.com/scqrinc/status/1616009030228643841)をもとにしています。
sudoedit (`sudo -e`) security flaw (CVE-2023-22809)
Tags: sudo, sudoedit, security, vulnerability
Published: 2023-01-19 14:30:37

## Security vulnerability

A new [`sudo`](https://www.sudo.ws/) vulnerability was found. It was on sudoedit (`sudo -e`) flaw. With it, attackers can edit arbitrary files, and therefore machines were at the risk of the pwned and having information steeled.

### CVE

[CVE-2023-22809](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-22809)

### Impact

(with appreciation to @jmau111's [comments](https://dev.to/jmau111/comment/248dj))

The official website [statements](https://www.sudo.ws/security/advisories/sudoedit_any/#impact):

> If no users have been granted access to sudoedit there is no impact.

It is the case, for example, that `/etc/sudoers` (or the target `visudo` uses) has such a line:

```conf
someuser ALL=(root) sudoedit /etc/some.conf
```

`someuser` can edit another file by exploiting the flaw.

## Solution

If sudo is 1.8 or greater, it is recommended to update it to the latest version ([1.9.12p2](https://github.com/sudo-project/sudo/releases/tag/SUDO_1_9_12p2)) released today, on 2023-01-19.

### Temporary workaround

In case that you can't update it right now,

the official website [describes](https://www.sudo.ws/security/advisories/sudoedit_any/#workaround) there is a way to mitigate it by adding the line below to sudoers:

```
Defaults!sudoedit    env_delete+="SUDO_EDITOR VISUAL EDITOR"
```

## Reference

This post is based on [the tweets by my company](https://twitter.com/scqrinc/status/1616078762831118336)
C++ ga Kirish
Tags: beginners, tutorial, webdev
Published: 2023-01-19 14:23:22

Today we will learn **_C++_**.

To demonstrate:

```cpp
#include <iostream>
using namespace std;

int main () {
cout<<"      _/\\__" <<endl;
cout<<"---==/    \\\\"<<endl;
cout<<"     |.    \\|\\"<<endl;
cout<<"     |  )   \\\\\\" <<endl;
cout<<"     \\_/ |  //|\\\\"<<endl;


  
return 0; 
  }

```

@dawroun
Next.js - generate build separate files
Tags: nextjs, react, webdev
Published: 2023-01-19 14:15:42

Hello, right now we are making software for our clients to be able to have their own shops - it is written in next.js - they will host it on shop_name.ourdomain.com

How should we go about building the app? Locally when we make a build it is really fast, but should we build separate apps for each of our clients? Can we automate the process? 

What is the right thing to do here?

Thank you in advance
Install Terraform in the AWS CloudShell
Tags: terraform, aws
Published: 2023-01-19 14:05:00

The [AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/working-with-cloudshell.html) is a browser-based shell that makes it quick and easy for you to securely manage, explore and interact with your AWS resources. 

CloudShell is pre-authenticated with your console credentials, so there is no need to login again. 

Tools such as AWS CLI, Python, Node.js, npm, Git and BASH utilities are pre-installed for ease of use. 

Unfortunately [Terraform](https://www.techielass.com/introduction-to-terraform/) isn’t installed, however, in this article I am going to walk you through the process of installing it within AWS CloudShell. 

## Install Terraform in AWS CloudShell

* Head over to the [AWS Management Console](https://aws.amazon.com/console/)
* Click on the  AWS CloudShell icon on the console navigation bar

![AWS Management Console](https://community.ops.io/remoteimages/uploads/articles/z6otdfispwj1xfxdf36t.png)

* We’re going to use the Terraform Version Manager to help install Terraform
* With the AWS CloudShell type in: 

```bash
git clone [https://github.com/tfutils/tfenv.git](https://github.com/tfutils/tfenv.git) ~/.tfenv
```

![Git clone Terraform Version Manager](https://community.ops.io/remoteimages/uploads/articles/mmoibxaq2alu5389hb5k.png)


* Next we want to make a new directory called _~/bin_, to do that issue the command: 

```bash
mkdir ~/bin
```

* Now we’re going to make a symlink for tfenv/bin/* scripts into the path ~/bin by typing the command: 

```bash
ln -s ~/.tfenv/bin/* ~/bin/
```

![AWS directory](https://community.ops.io/remoteimages/uploads/articles/cxjcfesodrwceh0p2bac.png)

* With the Terraform Version Manager installed, we can now install Terraform. Type in the command: 

```bash
tfenv install
```

![Terraform install](https://community.ops.io/remoteimages/uploads/articles/eb0vzyd8ye1c66tfx8e9.png)

This will install the latest version of Terraform for you.  You can specify a specific version if required when using the _tfenv install_ command.

If you wish to default to using a certain version of Terraform you can use the command: 

```bash
tfenv use 1.3.7
```

It’s worth noting that this only installs Terraform within the AWS CloudShell region that you are working within.  If you use multiple AWS regions then you will need to follow the above steps each time. 

A copy of all the steps are all encapsulated within a script [here](https://gist.github.com/weeyin83/d93e4df3c58e4a8aa4dfbf1bf99425ab). 

You can now work with Terraform within the AWS CloudShell console.
How to create a Pre-signed URL in S3
Published: 2023-01-19 14:02:45


## How to create a Pre-signed URL in S3

When you create a S3 bucket by default all the objects in the buckets you upload are privte and only the object owner has permission to access it.

However, the object owner can optionally share objects with others by creating a presigned URL, using their own security credentials, to grant time-limited permission to download the objects.

When you create a presigned URL and shared it, Anyone who receive the URL can access the objects even if the objects is private. For example if you upload a file object into the bucket and both the bucket and the file object is private, You can create the presigned URL and share it.

**To create a Pre-signed URL from AWS console**

Login to AWS console and select the bucket and object you want to create -pre-signed URL.Go to Actions and select share with Presigned URL option.AWS console maximum you can create presigned url with12 hours experation time.For loger time we would need to create the URL from AWS CLI/SDK.

![](https://cdn-images-1.medium.com/max/2424/1*Zhi4fXgB7ZjXJ1KiHgW6Gw.png)

**To create a Pre-signed URL from AWS CLI**

When you create presigned URL using a temporary token ( eg : from ec2 machine with instance profile attached ) the URL expires when the temporary tocken expires even if the URL was created with more expiration time.

The credentials you can use to create a presigned url include .

* **AWS Identity and Access Management (IAM) instance profile:** Valid up to six hours.

* **AWS [Security Token Service](https://docs.aws.amazon.com/STS/latest/APIReference/API_GetSessionToken.html) (STS):** Valid up to 36 hours when signed by an AWS Identity and Access Management (IAM) user, or valid up to one hour when signed by the root user.

* **IAM user:** Valid up to seven days when using [AWS Signature Version 4](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html).

If you want more expiration time for presigned URL more then 36 hours upto 7 days, i would recommed to use and configure AWS Access Key ID and AWS Secret Access Key into AWS CLI.

After Access/secret key into aws configure use below AWS CLI command to create presigned URL. Below example will create a presigned URL with max expiration of 7 days.

**aws s3 presign s3://DOC-EXAMPLE-BUCKET/Drawing.zip— expires-in 604800**
Application Security 101: Understanding and Preventing Common Threats
Published: 2023-01-19 13:57:43


In the digital age, application security is more important than ever before. With the ever-increasing use of the internet, applications are becoming a target for malicious attackers. Application security is a process used to protect applications and their data from unauthorized access, malicious attacks, and other security threats. It is essential to ensure that applications are secure and reliable, as they are often critical components in the operation of an organization or business.


Application security is a critical element of an overall security strategy. It involves the implementation of security controls such as authentication, authorization, and encryption to protect applications and their data. 



These controls are designed to prevent unauthorized access, as well as protect against malicious attacks. Additionally, application security also involves the implementation of secure coding practices, such as vulnerability assessment and code review, to identify and address security flaws in applications.



Application security is also important for protecting user data. As the internet has become a primary source of information, the need to protect user data has increased significantly. Application security measures such as data encryption, authentication, and authorization help protect user data from unauthorized access and malicious attacks. Additionally, application security also helps to ensure that user data is securely stored and transmitted.

[click to visit full article originally published on 20/01/23](https://www.javaoneworld.com/2023/01/application-security-101-understanding.html)
The Art of Dynamic Programming: Solving Complex Problems with Simplicity
Published: 2023-01-19 13:55:28

Dynamic Programming is a powerful technique used to solve complex problems by breaking them down into smaller sub-problems. It is a bottom-up approach in which a problem is solved by solving its sub-problems first and then combining their solutions. The concept of dynamic programming was developed by Richard Bellman in the 1950s.


Dynamic programming is a useful tool for solving problems with overlapping sub-problems. It works by breaking down a problem into smaller sub-problems and then solving them one by one. 

This technique is more efficient than other methods, such as brute force or divide-and-conquer, because it only needs to solve each sub-problem once. The solutions to the sub-problems are stored in a table, and the final solution is obtained by combining the solutions to the sub-problems.

Dynamic programming can be used to solve a wide variety of problems, such as finding the shortest path between two points, determining the optimum way to cut wood, or scheduling jobs on a computer. It is also used in bioinformatics, graphics, economics, and other fields.

def fibonacci_dp(n):
  mem = [0] * (n + 1)
  mem[1] = 1
  mem[2] = 1
  for i in range(3, n+1):
    mem[i] = mem[i-1] + mem[i-2]
  return mem[n]

print(fibonacci_dp(8)) # prints 13


This approach is much faster than the previous.
 one, as it only requires a single loop and has a linear time complexity.


[click to visit full article originally posted on 20/01/23](https://www.javaoneworld.com/2023/01/the-art-of-dynamic-programming-solving.html)
How to convert Degrees to Radians
Published: 2023-01-19 13:47:31

When working with rotating view animations or 2d/3d games, you would have to eventually deal with degrees and radians at some point.

Even though, most people have a better understanding of degrees over radians, most of the angles are dealt in radians in Swift [and general math as a matter of fact].
Before diving into the coding path, let’s get the math part clear.

1 pi radian = 180 degrees

> Note: pi = 3.14

Thus, for converting degrees to radians, you have to multiply it by pi and divide by 180.

Radians = Degrees * π / 180


#Computed Property Extension

One of the easy, clean and efficient way to convert degrees to radians is to extend a computed property to BinaryFloatingPoint which is basically a generic type which includes all the decimal numeric types - Float, Double.

```
extension BinaryFloatingPoint {
    var radians : Self {
        return self * .pi / 180
   }
```

Usage:

```
let degree : Float = 360 // 360 degrees
let radians = degree.radians // 6.28 radians // 2π radians 
```

#Extension Methods

Another convenient way of converting degrees to radians using a method over BinaryFloatingPoint, Double and Float.

```
extension BinaryFloatingPoint {
    func inRadians() -> Self {
        return self * .pi / 180
    }
}
```

Usage:

```
let degrees : Float = 360 // 360 degrees
let radians = degrees.inRadians() // π radians
print(radians)
```

This above method works for decimal based data types. In the case, the degrees variable is an integer, you can try the following method for converting it to radians.

```
// prints 6.283185 in console
```

This works! Congratulations! You have successfully converted degrees to radians.

In a similar way we have an exercise for you, if you are looking forward to convert radians into degrees, then give it a try yourself and share it with us on Twitter [@swiftanytime](https://twitter.com/swiftanytime). Till then,

Eat. Sleep. Swift Anytime. Repeat.