teleren/devto huggingface dataset:
Week III Task Force 4.0
Tags: coding, teamwork
Published: 2021-11-14 21:24:01

> Code Can't Lie 🤣 

Hello again, now I could say that I am already a Task Force🦾 , this week was cool and super I have experienced working as a team and the merits from it. Basically this is the week that the team(Task-Force) really become one element, by this we started working together brainstorming to come up with a great __MVP__(Minimum Viable Product), I have also liked the way we started sharing our own personal life experience which was also a great takeaway like Empathy.

I have loved the Soft skills that I have been introduced to, ain't going to lie it was really a valuable sessions. As Backend Developers we also have to work and collaborate on Technical skills that's where the team working , cooperation and creativity comes to play, This week we have worked on **ERD** *Entity relationship diagram* mainly we've designed possible Entities to be used in our project not only that we have  created their cardinalities as well as creating their *__SQL__* queries . throughout SQL I have come to see a *__json__* datatype in MySql🤔 That's made me  realize that This Field is all about learning journey, The more you learn the more you tend to find you know less but, in anyways it is great and super.

I can't wait to see you the next Week !!! ✌.
Middleware in FastAPI
Tags: python
Published: 2021-11-14 20:46:13

According to official documentation, **FastAPI** is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.

# The key features are:

*  **Fast**: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic). One of the fastest Python frameworks available.

* **Fast to code**: Increase the speed to develop features by about 200% to 300%. *

* **Fewer bugs**: Reduce about 40% of human (developer) induced errors. *
* **Intuitive**: Great editor support. Completion everywhere. Less time debugging.
* **Easy**: Designed to be easy to use and learn. Less time reading docs.
* **Short**: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.
* **Robust**: Get production-ready code. With automatic interactive documentation.
* **Standards-based**: Based on (and fully compatible with) the open standards for APIs: OpenAPI (previously known as Swagger) and JSON Schema.

# Middleware.
A "middleware" is a function that works with every request before it is processed by any specific path operation. And also with every response before returning it.

* It takes each request that comes to your application.
* It can then do something to that request or run any needed code.
* Then it passes the request to be processed by the rest of the application (by some path operation).
* It then takes the response generated by the application (by some path operation).
* It can do something to that response or run any needed code.
Then it returns the response.

# Create a middleware
To create a middleware you use the decorator **@app.middleware("http")** on top of a function.

**The middleware function receives**:

* The request.
* A function **call_next** that will receive the request as a parameter.
  * This function will pass the request to the corresponding path operation.
  * Then it returns the response generated by the corresponding path operation.
* You can then modify further the response before returning it.
```python
     @app.middleware("http")
     async def log_requests(request: Request, call_next):
     idem = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6))
     logger.info(f"rid={idem} start request path={request.url.path}")
     start_time = time.time()
    
     response = await call_next(request)
    
     process_time = (time.time() - start_time) * 1000
     formatted_process_time = '{0:.2f}'.format(process_time)
     logger.info(f"rid={idem} completed_in={formatted_process_time}ms status_code={response.status_code}")
    
     return response`
```
i need a help how to handel path traversal in node js.
Published: 2021-11-14 20:35:33

I am working on a project when I test it on synk I am getting path traversal warning with image upload. I am using express file upload. if someone help me that would be great for me.  
hope I will get some help from this community. 

![here is the code ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cr93lkm5kh6jhjex901b.png)
HACKTOBERFEST 2021
Tags: hacktoberfest, opensource, webdev, programming
Published: 2021-11-14 20:33:15

It was a great experience participating in Hacktoberfest this year. This was my second participation in Hacktoberfest. I am glad to share that I have successfully completed Hacktoberfest and learned a lots of things.

Also, I just ordered my Hacktoberfest badge.

Thank you Hacktoberfest!!
Thank you Digital Ocean!!
Thank you DEV!!
Mutability of JavaScript
Tags: javascript, mutability
Published: 2021-11-14 19:46:02

I love the way JavaScript code has a dynamic aspect that allows for on-the-fly changes

Coming from a *Safety-Critical Software* background, any dynamic construct, like inheritance, was discourages

Now, learning web programming I am loving the freedom JavaScript includes. Some are likely an effect of being interpreted, but others are just plain cool

## Object Bracket Notation

ability to reference object elements as an array, somewhat like PHP's *associative arrays*

```javascript
let myObj = {'prop1': 14};
myObj['prop1'] = 41;
```

## Adding Object Elements on-the-fly

Coming from C/C++ OOD/P, everything is fixed and unbending

With JS Object, you can tack on a new element, including functions

I had some fun with this in an NPM module [Quick JSON Config](https://www.npmjs.com/package/quickjsonconfig) I wrote a while back

As the node app reads in each top-level element of the JSON file, it adds get/set function to it's class instance

```javascript
  /**
   * Embeds each json element into this class. Creates a simple get/set method for each
   * @param {object} el - json key-value pair for embedding
   */
  _embedElement(el) {
    let getName = `get${el}`;
    this[getName] = function () {
      return this._jsonData[el];
    }

    let setName = `set${el}`;
    this[setName] = function (newVal) {
      if (typeof newVal === typeof this._jsonData[el]) {
        this._jsonData[el] = newVal;
      }
    }
  }
```
Here I create the functions to get/set the element, then tack it on to the instance using the Bracket Notation

## Promisify Functions

Working in Node and using some older (well, actually, it is more like *not maintained packages*), the mutations are used to wrap function is async/await and Promise constructs

I have not looked into how packages like [bluebird](https://www.npmjs.com/package/bluebird) does this, but I expect it is similar to the above items I expressed

## Of Course...

This means developers must understand these constructs so they do not shoot themselves (or their customers) in the foot

While safety-critical software has rules and limitations, many are to prevent letting the runtime environment make decisions and change how your code executes
Host a static website on AWS under a minute with Terraform
Tags: aws, terraform, cloudfront, s3
Published: 2021-11-14 20:23:32

If you have a static website and you want a simple solution, S3 and Cloudfront are great choices. S3 with Cloudfront secure, scalable way to host static content. Also, we will get an SSL certificate for our domain and it will be free.

#### Prerequisites

Before the deployment of this terraform module, make sure your hosted zone exists in Route 53 and move your domain to Route53 by changing NS records on your DNS provider.

![terraform-s3-cloudfront-route53](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tophd1lmax66q2podj4.jpg)


We will use 4 AWS Services;

* S3 - Storing website files (HTML, CSS, JavaScript)

* Cloudfront - CDN

* Certificate Manager - SSL Certificate

* Route 53 - DNS records


Since we are using Cloudfront we don't need the public bucket, so we will create a private S3 bucket. We will use OAI (Origin Access Identity) settings when we create Cloudfront. This means that only our Cloudfront distribution can access and read the files in our S3 bucket. Also, we will create an SSL certificate from Certificate Manager and Cloudfront redirect all HTTP traffic to HTTPS.


![cloudfront-oai](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gxdt39ga82ch41dafw6.png)


First clone the repository

```
git clone git@github.com:emreoztoprak/terraform-aws-s3-cloudfront-acm.git

```

Change these two variables in the **terraform.tfvars** file.

```

SiteTags = "Example" (Tag value of the resources.)

domainName = "example.com"

```

You can now run this module when you change the variables.

```
terraform init
terraform plan
terrafom apply --auto-approve

```
After the deployment is completed upload your website files to in S3 Bucket. I configured DefaultRootObject as index.html. Basically, when users access your root URL they will see index.html file.

I just uploaded a simple HTML file.

Congratulations. You made it. :)

![aws-cloudfront](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zvx04yfdub78ls5g9z0e.png)

Hope you find this tutorial helpful!
Target class [role] does not exist: Laravel
Published: 2021-11-14 20:06:37

Hi, quickly: if this is as a result of using the spatie laravel role package, use this approach to solve the problem

Add the following to `$routeMiddleware` array located in `app/Http/Kernel.php`:
 
```
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,

'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,

'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class,
```
[Reference](https://laracasts.com/discuss/channels/laravel/laravel-spatie-error-target-class-role-does-not-exist)
Uploading Docker Images to AWS ECR
Tags: aws, cloud, cloudskills, programming
Published: 2021-11-14 19:38:55

## AWS

#### `Create an ECR Repo`

```bash
aws ecr create-repository --repository-name <name>
```

#### `Log-in to ECR` 

```bash
aws ecr get-login-password --region region | docker login --username AWS --password-stdin <registry_id>.dkr.ecr.<region>.amazonaws.com
```

#### `Tag your image`

Tag your image with the Amazon ECR registry, repository, and optional image tag name combination to use. This is important if we want to push to ECR and not DockerHub.

```bash
docker tag <image_id> <registry_id>.dkr.ecr.region.amazonaws.com/<repo_name>:<tag>
```

#### `Upload image to ECR`

```bash
docker push <registryId>.dkr.ecr.<region>.amazonaws.com/<repo>:<tag>
```
Java Main Method
Tags: java, programming, beginners, tutorial
Published: 2021-11-14 19:34:18

Hello everyone, this week I am going to go over one of the most important concepts in Java, the main method.  The main method in itself is pretty easy to understand as it is the part that runs the program but there are components to it most early programmers don’t take the time to learn.

Lets start by taking a look at the syntax of the method:

![Java Main Method Syntax](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q24owzagkqkrfcayexzt.png)

Public: The method must be public so it is accessible.  If the method is marked as private, protected, or default the JVM will not be able to locate it.

Static: The static keyword allows methods to be called without instantiating an object first.  We don’t want to be required to create an object to run the main method.

Void: The main method doesn’t return anything so we use void as the return type.

Main(): This is the default signature for the JVM and is used to execute a program.

String args []: This is a string array of command line arguments that are passed to the main method.  If this is left out of the parameters the JVM will not be able to locate the main method because it looks for a method with a string array.

What is a command line argument?

```
$ java myProgram arg1 arg2 arg3
```

You can then use these arguments from the array in your main method if needed.

```
public class Example {
	public static void main(String[] args) {
		for(String arg: args){
			System.out.println(arg);
		}
	}
}
```

The last thing I want to touch on is how the main method applies to a process.  The main method is a thread in a process that is automatically created by the JVM.  Each time a thread is created, the JVM allocates a stack of memory to it.  Since additional threads are created from the main thread each additional is considered a child of the main thread which means it must finish execution last.  This is because the thread that created another must perform the various shutdowns to safely stop it.  For more information on multi-threading please click the [link](https://dev.to/jryther/understanding-threading-5c9o) to see my post on it.

That is all for this week.  Please leave a like and comment down below if you found it useful.  Follow me for more posts like this each week as I work to improve my programming knowledge with you all.  Have a great day and happy coding!

Resources:

https://www.javatpoint.com/java-main-method

https://techvidvan.com/tutorials/java-command-line-arguments/

https://javagoal.com/main-thread-in-java/
Lambda container approach in AWS
Tags: aws, cloud, programming, devops
Published: 2021-11-14 19:28:24

## `Zip vs Container Approach`

There are two ways to use Lambda functions in AWS. One is to provide the deployable artifact in the form of a zip file. You then have a variety of runtimes you can choose from: https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html.

The other approach is the Lambda container approach. IMO, the container approach to Lambda management has two main advantages over the zip approach. 

### `Runtime selection`

With the zip approach, you have to rely on Amazon supporting the desired runtime. For example, if your code depends on Python3.10, you better hope that Amazon supports that. In a container approach however, the runtime is something you have full control over. Just make sure either your base image supports the runtime or you install the runtime as part of one of your RUN statements.

### `Building dependencies`

Non-native packages such as pandas, lxml, etc have to be built in the target environment for the compiled binaries to work. For example, if you build pandas on Mac, then the compiled binaries will work on Mac - not on Amazon Linux 2 which is what Lambda runs on.

With containers, you no longer have to worry about building for a target OS, as you're able to encapsulate OS details in an image. Put simply, the image you build locally will just work in Lambda. How easy is that!
Object Validator for PHP 8
Tags: programming, php, webdev, discuss
Published: 2021-11-14 19:27:11

Have you ever tried to validate an object in PHP. Maybe you use Models, ViewModels or RequestModels.Maybe you hate writing if-else, loops and swiches to check your values.Maybe you do not like to use different validators for every framework.

At least I do.

#So I present you my general solution using the strengths of PHP 8.Clean, concise and easy.

- Lots of validations

- Supprots also nested object validation

- Repeatable validation attributes

- Works with private properties and methods

- Works with constructor promotion

- Memory and time profiling

- Custom error messages

- Custom property and method names for the exceptions

##Example
```php
<?php

use RMValidator\Attributes\PropertyAttributes\Collection\UniqueAttribute;
use RMValidator\Attributes\PropertyAttributes\File\FileExtensionAttribute;
use RMValidator\Attributes\PropertyAttributes\File\FileSizeAttribute;
use RMValidator\Attributes\PropertyAttributes\Numbers\RangeAttribute;
use RMValidator\Attributes\PropertyAttributes\Object\NestedAttribute;
use RMValidator\Attributes\PropertyAttributes\Strings\StringContainsAttribute;
use RMValidator\Enums\ValidationOrderEnum;
use RMValidator\Options\OptionsModel;
use RMValidator\Validators\MasterValidator;

require __DIR__ . '/vendor/autoload.php';


class Test 
{
    public function __construct(
        #[RangeAttribute(from:10, to:50)]
        #[RangeAttribute(from:10, to:30)]
        public int $param)
    {
        
    }

    #[RangeAttribute(from:10, to:30)]
    const propTest = 40;

    #[UniqueAttribute()]
    public function custom() {
        return ['asd', 'asdk'];
    }

    #[FileSizeAttribute(fileSizeBiggest: 20, fileSizeLowest: 10)]
    #[FileExtensionAttribute(expected:['php'])]
    private function getFile() {
        return __FILE__;
    }

    #[FileSizeAttribute(fileSizeBiggest: 20, fileSizeLowest: 10)]
    #[FileExtensionAttribute(expected:['php'])]
    public string $file = __FILE__;

    #[StringContainsAttribute(needle:"asd")]
    public string $string = "23asd";

    #[RangeAttribute(from:10, to:30)]
    public int $prop = 40;
}

class UpperTest
{
    #[NestedAttribute(excludedProperties:['param'])]
    private Test $test;

    public function __construct(Test $test) {
        $this->test = $test;
    }
}

$test = new Test(40);

try {
    MasterValidator::validate(new UpperTest($test), 
    new OptionsModel(orderOfValidation: [ValidationOrderEnum::PROPERTIES, 
                                         ValidationOrderEnum::METHODS,
                                         ValidationOrderEnum::CONSTANTS], 
                     excludedMethods: ['getFile'], 
                     excludedProperties: ['file']));
} catch(Exception $e) {
    var_dump($e);
}

```

Enjoy. Any feedback, recommendations and support are welcome :)

https://github.com/IvanGrigorov/VMValidator
Makanan Daerah
Tags: makanandaerah
Published: 2021-11-14 19:06:31

Indonesia adalah kepulauan yang terdiri dari berbagai suku dengan budaya yang sangat beragam. Begitu juga dengan hasil alami yang digunakan sebagai makanan.

Secara umum, bahan-bahan makanan berasal dari dua sumber, yaitu dari makanan nabati dan makanan hewani.
Bahan-bahan makanan nabati adalah bahan makanan yang berasal dari tanaman seperti umbi, sayuran, buah-buahan, dan sereal.

Bahan-bahan makanan hewan adalah makanan yang berasal dari hewan, seperti ayam, telur, daging, ikan, dan susu.

Perbedaan budaya dan makanan yang tersedia membuat pemrosesan produk makanan khusus berbeda di setiap wilayah sehingga menghasilkan berbagai jenis produk makanan dengan karakter yang berbeda.
https://makananinternasional.com/makanan-tradisional-khas-daerah-setiap-provinsi-di-indonesia/
What! What? Yes,What is the difference between ANSI & UNICODE 
Published: 2021-11-14 18:58:06

এএনএসআই এবং ইউনিকোড দুটি অক্ষর এনকোডিং যা এক সময়ে বা অন্য সময়ে ব্যাপকভাবে ব্যবহৃত হয়েছিল। এএনএসআই অনেক পুরানো এবং উইন্ডোজ 95/98 এবং তার বেশি বয়সের অপারেটিং সিস্টেম দ্বারা ব্যবহৃত হয় বলে ইউনিকোড হল একটি নতুন এনকোডিং যা বর্তমান সকল অপারেটিং সিস্টেমের দ্বারা ব্যবহৃত হয়। ANSI- এর অনেক সীমাবদ্ধতা ছিল যা ব্যবহারের প্রাথমিক পর্যায়ে সহজেই স্পষ্ট ছিল না কিন্তু কম্পিউটিং বিশ্বব্যাপী ছড়িয়ে পড়তে শুরু করলে বেদনাদায়কভাবে স্পষ্ট হয়ে ওঠে। ANSI- এর প্রধান অসুবিধা হল অনেক কোড পেজের ব্যবহার, যে ভাষা ব্যবহার করা হচ্ছে তার উপর নির্ভর করে; ইংরেজি (পশ্চিম ইউরোপীয় ল্যাটিন নামে পরিচিত), গ্রিক, তুর্কি, হিব্রু, আরবি এবং আরও অনেকের জন্য রয়েছে। কোন সমস্যা নেই যখন সমস্ত কম্পিউটার যারা ডেটা অ্যাক্সেস করে তারা একই কোড পৃষ্ঠা ব্যবহার করে, কিন্তু যখন বিভিন্ন কোড পৃষ্ঠাগুলি ব্যবহার করা হয়, তখন পড়া ডেটা লিখিত ডেটার মতো হবে না। এর ফলে ডেটা দুর্নীতি হতে পারে এবং নির্দিষ্ট পরিস্থিতিতে প্রোগ্রাম ক্র্যাশও হতে পারে। এএনএসআই কেন মিটমাট করতে পারে না তার কারণ হল এটি প্রতিটি কোড পয়েন্টকে উপস্থাপন করতে মাত্র 8 বিট ব্যবহার করে। এই প্রস্থ স্থির এবং শুধুমাত্র 256 বিভিন্ন সমন্বয় আছে। তুলনায়, ইউনিকোড প্রতিটি কোড পয়েন্টের জন্য সর্বোচ্চ 32 বিট ব্যবহার করে; UTF-32 এর নির্দিষ্ট প্রস্থে ব্যবহৃত হয়। কিন্তু যেহেতু প্রতিটি অক্ষরের জন্য চারটি বাইট ব্যবহার করা স্থানটির এত বড় অপচয়, তাই স্থান বাঁচানোর জন্য UTF-8 এবং UTF-16 এ পরিবর্তনশীল প্রস্থের এনকোডিং নিযুক্ত করা হয়। যেহেতু ইউনিকোড একটি নতুন মান, আশা করা যায় যে পুরানো অপারেটিং সিস্টেমগুলি এটি সমর্থন করতে পারে না। যদিও UTF-8 এবং ANSI এর কোড পয়েন্টগুলি অনেকটা অভিন্ন, উইন্ডোজ 95 এর মতো পুরনো অপারেটিং সিস্টেমগুলি এর সাথে কাজ করতে পারে না। অতএব, ইউনিকোড ব্যবহারকারী প্রোগ্রামগুলি এই অপারেটিং সিস্টেমে সঠিকভাবে চালাতে পারবে না। বিপরীত, অথবা নতুন অপারেটিং সিস্টেমে ANSI কোডেড প্রোগ্রাম চালানোর ক্ষেত্রে, এটি সম্ভব কারণ ANSI এবং ইউনিকোডের মধ্যে রূপান্তর করার প্রক্রিয়া রয়েছে। শুধু মনে রাখবেন যে রূপান্তর ওভারহেড প্রক্রিয়াকরণের একটি বিট যোগ করে। আজকের কম্পিউটারে এটি উল্লেখযোগ্য নাও হতে পারে, তবে প্রোগ্রাম দক্ষতা উন্নত করার জন্য এটি এখনও নোট করা মূল্যবান। সারসংক্ষেপ: 1. ANSI হল একটি অতি পুরনো অক্ষর এনকোডিং এবং ইউনিকোড হল বর্তমানে ব্যবহৃত বর্তমান মান 2. ANSI বিভিন্ন ভাষার জন্য বিভিন্ন পৃষ্ঠা ব্যবহার করে যখন ইউনিকোড না 3. ANSI নির্দিষ্ট প্রস্থ এনকোডিং ব্যবহার করে যখন ইউনিকোড স্থির এবং পরিবর্তনশীল উভয় প্রস্থ ব্যবহার করতে পারে 4. ইউনিকোড প্রোগ্রাম পুরনো সিস্টেমে কাজ করবে না 5. ANSI প্রোগ্রামগুলি বর্তমান কম্পিউটারে ইউনিকোড প্রোগ্রামের তুলনায় ধীর
installed-check 5.0.0: Robustness galore
Tags: node, showdev, javascript, npm
Published: 2021-11-14 18:56:43

A few seconds ago I shipped [version 5.0.0](https://github.com/voxpelli/node-installed-check/releases/tag/v5.0.0) of [`installed-check`](https://github.com/voxpelli/node-installed-check) CLI and its companion [`installed-check-core`]((https://github.com/voxpelli/node-installed-check-core/releases/tag/v5.0.0)) module, delivering a more robust, more well tested and all-round better tool.

## So what does `installed-check` do?

It check's that your project's `engine.node` is equal to, or a subset of, of that of your dependencies.

## What's new?

Replaced old [`@voxpelli/semver-set`](https://github.com/voxpelli/semver-set), a fork of another project, with a brand new rewritten from scratch [3.x version of it](https://github.com/voxpelli/semver-set/releases/tag/v3.0.0).

The new `@voxpelli/semver-set` is well tested and hardened – all to ensure better intersection calculations of semantic versioning ranges – essential for calculating `engine.node` compatibility. Eg. `^10.17.0 || >=12.0.0` and `>=8.0.0` now properly calculates.

The new `@voxpelli/semver-set` also fixes an issue with the license of the former module. Since its a full rewrite I could pick a license myself, so it's now [under MIT](https://github.com/voxpelli/semver-set/blob/main/LICENSE).

Other news for the `installed-check` modules includes a swap from the non-standard [`VError`](https://github.com/joyent/node-verror) to my [`pony-cause` pony-fill](https://github.com/voxpelli/pony-cause#errorwithcause-creating-an-error-with-a-cause) for the now standardised [Error Causes](https://v8.dev/features/error-cause)

`installed-check` in general now also has much more tests and have fixes for issues those tests uncovered, making for a much more robust experience going forward.

## How do I get started?

Add it to your project:

```bash
npm install -d installed-check@latest
```

Then add it (early) to the tests in your `package.json`:

```json
"scripts": {
  "test": "installed-check"
}
```

A more full-featured example can be found in eg. my [`list-installed`](https://github.com/voxpelli/list-installed/blob/a905a08d9e0bdb5a6da9f6a449a528eadc91cbda/package.json#L17) project.

Happy compatibility checking! 🥳