teleren/devto huggingface dataset:
normalize data without normalizr
Published: 2022-09-22 05:20:14

Hi there 👋🏼

This is a short post about how normalize data using native available right now.

If you using a normalizr you know what I mean.

I've a simple server response data

```javascript
const data = [
    { id: 1, name: 'Apple', type: 'fruit' },
    { id: 2, name: 'Orange', type: 'fruit' },
    { id: 3, name: 'Tomato', type: 'vegetable' },
];
```

and I wanna get the entities and collection by attribute.

So, define it all.

```javascript
const attribute = 'id';
const entities = [];
const collection = {};
```

Next step will be iterate data and write

```javascript
data.forEach((item) => {
    entities.push(item[attribute]);
    collection[attribute] = item;
});
```

In final we have entities and collection and can handy to iterate and get date by iterable attribute.
What is JDK Architecture in JAVA
Tags: java, webdev, beginners, programming
Published: 2022-09-22 05:09:34

**JDK Architecture** 

**JVM**:- 

- JVM Stands For Java Virtual Machine it is an interpeter which is use to convert byte code to machine level languages line by line

- JVM is present in JRE

**What is JRE?**

- JRE stands For JAVA RUNTIME ENVIRONMENT

- It Consists of JVM And built in library files which is use to executes JAVA Applications

- If We want to only execute Java Applications we need to install JRE

- JRE is Present In JDK

**JDK**:- JAVA Development Kit

- JDK stands For java Development Kit

- it is a package given by oracle community.

- Which is use to develop as well as run java software execution

- JDK consists of JRE and Development tools


**Note**:- JDK is Platform Dependent,  software made by  JDK are Platform  Independent 



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wts3bac4sadrl5z5sdco.png)
HTML Ro'yxatlar
Published: 2022-09-22 05:04:23


Ro'yxatlar hosil qilish uchun `ul` tegidan foydalanamiz.
``` html
<ul> 
<li>1-element</li>
</ul>
```
##   text `li` ichiga yoziladi `ul` da type iga circle berilsa ichi bo'sh aylana agar square berilsa to'rtburchak disc berilsa ichi bo'yalgan aylana chiqarib beradi 

---
##  Ko'p hollarda esa `ul` o'rniga `ol` tegi ishlatiladi. Buning qulayligi shindaki `ol` tegi sizga raqamlar ketma-ketligini katta va kichik  harflar ketma-ketligini va rim raqamlari ketma-ketligini o'zi yozib beradi. Buni quyidagi misolda korishingiz mumkin.
---
```html
<ol type="1">
<li> Jamoliddin </li>
<li> Shamsiddin </li>
<li> Asomiddin  </li>
</ol>
```
1.Jamoliddin
2.Shamsiddin
3.Asomiddin

shaklida paydo bo'ladi . Bu tegda qanday nomerlanishini type ga qiymat berishimiz mumkin. 
`ol` tegida bundan tashqari start nomli kalit so'zi mavjud bu nomerlanishni qaysi harfdan yoki sondan boshlanishini ko'rsatishingiz mumkin agar bunda reversed kalit so'zi ham mavjud bu orqali siz nomerlanishni teskari tartibda malga oshirishingiz mumkin .

###  `dl` - orqali elementga sarlavha qo'yish mumkin bu quyidagicha yoziladi

``` html
<dl> 
<dt>1-element</dt>
<dd>1-element ta'rifi</dd>
 </dl>
```
1-element
1-element ta'rifi 
natijani ko'rishimiz mumkin .
DOUBT !! Use of Relative-Locator to find the element.
Tags: selenium, java, testing, beginners
Published: 2022-09-22 04:28:40

Note : We can find the location of the element with the id-name but just wanted to know how can we access with the help of relative-locators!!


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

Hello just wanted to know how to access the 'X' button from the side menu with the help of "Relative-locators' using Selenium in java.

For that page login to this sample web-page for testing.
Link : https://www.saucedemo.com/

I have tried it with near, above functions By class-name "bm-item-list" but the driver could not locate it.

Appreciate your help !!!
AWS Fargate Cheat Sheet
Tags: 30daysofaws, day12, certifieddeveloperassociate
Published: 2022-09-22 04:06:13

Serverless compute for contai­ners.

AWS Fargate is a serverless, pay-as-you-go compute engine that lets you focus on **building applications without managing servers**.

Deploy and manage your applications, not infrastructure. Fargate removes the operational overhead of scaling, patching, securing, and managing servers.

Compatible with both Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS).

- [Documentation](https://aws.amazon.com/fargate/)
- [User Guide](https://docs.aws.amazon.com/fargate/?id=docs_gateway)


![AWS Fargate Flow](https://d1.awsstatic.com/re19/FargateonEKS/Product-Page-Diagram_Fargate%402x.a20fb2b15c2aebeda3a44dbbb0b10b82fb89aa6a.png)

## Alternatives

- Google Kubernetes Engine (GKE)
- Red Hat OpenShift Container Platform
- Azure Kubernetes Service (AKS)
- Rancher
- Azure Container Instances
- Cloud Foundry
- Oracle Cloud Infrastructure Container Engine for Kubernetes

## Q

How AWS Fargate different from AWS ECS?

In AWS ECS, you manage the infrastructure - you need to provision and configure the EC2 instances.
While in AWS Fargate, you don't provision or manage the infrastructure, you simply focus on launching Docker containers. You can think of it as the serverless version of AWS ECS.

> - [Practice notes](https://romankurnovskii.com/en/docs/aws-certified-developer-associate/fargate/)
> - [Questions](https://dev.to/romankurnovskii/aws-ec2-top-
questions-certified-developer-exam-27oo)
I made a VS Code code snippet manager
Tags: vscode, tooling
Published: 2022-09-22 03:35:40

Hi all. I often use VS Code code snippet to speed up my coding. It's a very useful feature in VS Code that I can create some snippet and use some special syntax to transform the snippet (like capitalize and generate uuid). 

For example, I can use this snippet to quickly generate a setState code:

```js
const [$1, set${1/(.*)/${1:/capitalize}/}] = useState($2)
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5khd1yrjsw5myrbbxpnt.gif)

But it's very hard to maintain the snippet because snippet file in VS Code is a JSON file. Every line of snippet was separate into an Array like:

```json
{
  "For Loop": {
    "prefix": ["for", "for-const"],
    "body": ["for (const ${2:element} of ${1:array}) {", "\t$0", "}"],
    "description": "A for loop."
  }
}
```

To make it easier to maintain the snippets in VS Code, I made a code snippet manager tool to write snippet in nature way, then one click sync to VS Code.


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

You can download it now on: https://codespeedy.randyloop.com 

It supports Windows and macOS. And the app size is only 7MB (No electron).

It's not open source yet because I'm not sure how many users it will have.
557. Leetcode solution in Java
Tags: java
Published: 2022-09-22 03:23:55

```
class Solution {
  public String reverseWords(String s) {
    StringBuilder sb = new StringBuilder(s);
    int i = 0;
    int j = 0;

    while (i < sb.length()) {
      while (i < j || i < sb.length() && sb.charAt(i) == ' ')
        ++i;
      while (j < i || j < sb.length() && sb.charAt(j) != ' ')
        ++j;
      reverse(sb, i, j - 1);
    }

    return sb.toString();
  }

  private void reverse(StringBuilder sb, int l, int r) {
    while (l < r) {
      final char temp = sb.charAt(l);
      sb.setCharAt(l++, sb.charAt(r));
      sb.setCharAt(r--, temp);
    }
  }
}

```


#leetcode
#challenge
here is the link for the problem: 
https://leetcode.com/problems/reverse-words-in-a-string-iii/
Git pre-commit hook not working (macOS)
Published: 2022-09-22 03:19:33

## Problem

``` log
the '.husky/pre-commit' hook was ignored because it's not set as executable.
```

## Why

it's probably a problem that wasn't created taking into account the file permissions of Linux at the time of init on Windows.
([Refernce](https://github.com/typicode/husky/issues/1177#issuecomment-1212831091))

## Solve
``` bash
chmod ug+x .husky/*
chmod ug+x .git/hooks/*
```
🔐How to encrypt variables in NodeJS
Tags: encrypt, hashing, npm, node
Published: 2022-09-22 02:54:15

Ever imagined what would happen if someone gets access to your MongoDB account where all your crucial information are stored.

All this comes down to another major issue when you have more than a few users who've submitted their confidential data relying on you.

# Need of Encryption 💁‍♂️

Storing user's data without any encryption at all might not be a good idea. 

A good fix to avoid compromising with someone's privacy would be to **encrypt**🔒 data before storing in Database and **decrypt**🔓 data while accessing from the Database.

---

## -> How to Encrypt variables 🛡️

While hash can be a good idea to implement before storing your user submitted variables, that might not work to regain data from the Database.

Again npm packages like _'bcrypt'_ & _'crypto'_ can be super useful and complicated at the same time. 

Let's see a method that's easy to understand as well as implementable in a flash.

---

## -> Using Keyhasher

Assuming you already have a nodejs project set up, let's first install the npm package using: 

```shell
npm i keyhasher
```
Running this in the terminal will install the package.
Let's require the package in the Node project.

```javascript
const key = require('keyhasher');
```
Try to keep this at the top of the project file.

---

### --> How Keyhasher Works 

[Keyhasher](https://www.npmjs.com/package/keyhasher) has two functions for Encryption and Decryption respectively. 

Both the funtions takes in two arguments, the hashable or reverse hashable input and the Passkey 🔑.

Simple example of the functions are given as-

```javascript
var hashAble = key.hash("Hi", 572);
console.log(`Hashed Phrase: ${hashAble}`)

// Hashed Phrase: X4A=

var rawWord = key.revHash("X4A=", 572);
console.log(`Output: ${rawWord}`)

// Output: Hi
```

In the hash Function, "Hi" is the text that is being encrypted, while I've used '572' as the Passkey🔑 that can be provided either directly to function or by using environment variable.

The function returns a Phrase "X4A=", which can be stored into the database.

With change to the passcode the Encrypted phrase changes. The same password is needed to decrypt the Encrypted phrase.

---

### --> Securing the Passcode

**The passcode can be any integer number** like 12383473, 3481234, 341343, 8534582, 98, 1236, 894.

A better practice would be to store the passcode🔑 in the configuration file.

Create a `.env` file and store your passkey in the following format.

```
PASSCODE = "23143341"
```

After storing the passcode safely, it can be used in the project with following syntax.

```javascript
var hashAble = key.hash("Hi", process.env.PASSCODE);
console.log(`Hashed Phrase: ${hashAble}`)

// Hashed Phrase: X4A=

var rawWord = key.revHash("X4A=", process.env.PASSCODE);
console.log(`Output: ${rawWord}`)

// Output: Hi
```
Laravel Scout: Create A Global Search
Tags: laravel, scout, search, global
Published: 2022-09-22 01:49:57

This is continuity form the previous post [here](https://dev.to/nasrulhazim/laravel-scout-create-a-single-api-endpoint-for-searching-purpose-only-1bj4).

I was asked if it is possible, if we create a Global Search? Yes it is possible. We are the programmer, we program things how they should behave and act.

I did minor changes on route and helper, then it's done!

**TLDR;**

The route:

```php
<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::middleware('auth:sanctum')->get('/search', function (Request $request) {
    abort_if(
        empty($request->search),
        404,
        'Please provide search keyword'
    );

    return search($request);
});
```

And the helper:


```php
<?php

use App\Enums\SearchType;
use Illuminate\Http\Request;
use Laravel\Scout\Searchable;

if (! function_exists('search')) {
    function search(Request $request = null)
    {
        if(is_null($request)) {
            $request = request();
        }

        $type = SearchType::tryFrom($request->type);
        $keyword = $request->search;
        $paginate = $request->query('paginate', false);
        $types = empty($type) ? SearchType::cases() : [$type];

        $data = [];
        foreach ($types as $type) {
            throw_if(
                ! in_array(Searchable::class, class_uses_recursive($type->value))
            );
        
            $class = $type->value;
        
            $query = $class::search($keyword);
        
            $data[$type->label] = $paginate
                ? $query->paginate()
                : $query->first();
        }

        return [
            'data' => $data,
            'meta' => [
                'searched_at' => date('Y-m-d H:i:s')
            ],
        ];
    }
}
```

I also update my enum, remove the `labels()` ovewrite:


```php
<?php

namespace App\Enums;

use Spatie\Enum\Laravel\Enum;

/**
 * @method static self user()
 * @method static self profile()
 */
class SearchType extends Enum
{
    public static function values(): array
    {
        return [
            'user' => \App\Models\User::class,
            'profile' => \Profile\Models\Profile::class,
        ];
    }
}
```

Now you are done! A Global Search in action.
Learnitive.com: An Interactive Teaching and Learning Platform
Tags: webdev, beginners, productivity, tutorial
Published: 2022-09-22 01:23:32

### What is Learnitive.com? 🤖

[Learnitive Education](https://edu.learnitive.com/) is an online course marketplace like #udemy #skillshare or #educative that helps instructors and students get in touch together and share knowledge. We allow everybody to teach just about anything of **academic** in nature on Learnitive. 👋👋

You don’t need a complete degree to become an instructor at Learnitive.com. Instead, all you need is a computer or a smartphone to record yourself as you share your knowledge and skills with people across the globe. 

Join now! [Learnitive.com](https://www.learnitive.com/)
Amazon EC2 On-Demand Instance vCPUs limits
Tags: aws, ec2, limit, vcpu
Published: 2022-09-22 01:06:17

## On-Demand Instance vCPUs limits

There is a limit on the number of running On-Demand Instances per AWS account per Region. On-Demand Instance limits are managed in terms of the **number of vCPUs** that your running On-Demand Instances are using, regardless of the instance type. [Each limit specifies the vCPU limit for one or more instance families](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-on-demand-instances.html#ec2-on-demand-instances-limits).

- To see the current vCPUs limits of your account from AWS EC2 console
    - Enter "vcpu" in the "Find limits" to shortlist the limits
- To find out the current running instances (of the same instance family of the EC2 type you want to check), go to EC2 console.
- Calculate how many vCPUs you nee
    - You can use the [vCPU limits calculator](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-on-demand-instances.html#vcpu-limits-calculator) to see what will be the numbers for adding instances of certain type.
- Request a limit increase
    - Even though EC2 automatically increases your On-Demand Instance limits based on your usage, you can request a limit increase if necessary. See Request a limit increase for details.

See also https://aws.amazon.com/premiumsupport/knowledge-center/ec2-on-demand-instance-vcpu-increase/.
My laravel package to connect prestashop easily
Tags: laravel, prestashop, github, composer
Published: 2022-09-22 00:59:38

hello guys, this is my first post here
i'd like to share with you my first laravel package, that is a prestashop connector, it is on progress
i'll be happy to receiv your ideas and reveiws 
https://github.com/islemdev/Prestavel
Amazon EC2 Image Builder Gotchas
Tags: aws, ec2imagebuilder, gotcha
Published: 2022-09-22 00:56:27

## Gotchas

- In `AWS::ImageBuilder::ContainerRecipe`, `Parameters` is supported only from Console and AWS CLI, but not from CloudFormation. Confirmed with AWS support.

- In `AWS::ImageBuilder::ContainerRecipe`, `ParentImage` (or `Base image` in Console) cannot reference another AWS account's ECR repo - this is not mentioned in [AWS documentation](https://docs.aws.amazon.com/imagebuilder/latest/userguide/create-container-recipes.html). Confirmed with AWS support.

- If something is not right at early stage (e.g. parse file in Component Data), you will see `Internal Failure` in CloudFormation console, but the errors will not be logged in S3 nor CloudWatch Logs.

- CloudWatch Logs - `/aws/imagebuilder/${ImageName}`
    - Logging things happen in the EC2 instance of the build only.
    - Not for Component Data syntax error, version conflict, etc.

- Tags are not inherited from the CloudFormation stack for all Image Builder resources (Component, Image Recipe / Container Recipe, Infrastructure configuration, Distribution, Image Pipeline).

- Adding, removing, renaming Tags, need to change Version; otherwise `Internal Failure` will be shown in the CloudFormation console, nothing in S3 log nor CW logs. Also need to update upstream resource's version e.g. Recipe Version.

- Whenever a change to Recipe (include Git Component)
    - Build time ~30 mins
Contributing is fun!
Tags: opensource, cpp, ssg
Published: 2022-09-22 00:33:57

## Hi again! Glad you've come

This week I've been working on adding some features to [SauSaGe](https://github.com/rudychung/SauSaGe) - Static Site Generator (SSG) built with C++.

To be frank, it's been some time since I last wrote in C++, and it does feel rusty, but it always feels good writing in C++. It just has a special place in my heart.

For SauSaGe, I decided to add some Markdown support and Headings 1 and 2 (# and ##) features. So, I started an [issue](https://github.com/rudychung/SauSaGe/issues/6) on Rudy's repo and got to work.

Like with every GitHub contribution, I started this one with a fork of the repo, where I created a separate branch for the issue, and started analyzing the code. I feel like reading the initial code is so much more important, than writing the features themselves. If you understand the environment, you will eventually understand how to work in such environment. It is also important not to change the structure of the code without the owner's agreement.

I firstly made support for `.md` files, which was easy enough, and then I edited the HTML generation function, so if the file is `.md`, the Headings will be parsed from text. After my changes were done, I pushed everything to my branch and initiated a [pull request](https://github.com/rudychung/SauSaGe/pull/10).

I liked this process a lot. Not only does it open a whole world of other people's projects for you to play with, but also everything is kept clean and organized, just how I like it.
Day 625 : Slow
Tags: hiphop, code, coding, lifelongdev
Published: 2022-09-22 00:30:28

_liner notes_:
- Professional : Still getting over the jet lag and had to take a nap. Did some prep work for a meeting. Investigated a way to turn some React Components into Web Components. Helped out with some community questions. Not a bad day at all.

- Personal : Last night, I just watched some shows. I caught up with Atlanta. The final season is really good so far. Looked into some new technology that came out.

![Aerial view of a rocky coast in Kioloa, Australia with waves crashing on the rocks](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pohg21eufhzkr413rrka.png)

So the protective cover on my foldable screen is starting to detach. I called into Samsung support and turns out my warranty ended like 11 days ago while I was in Japan. Of course. But the people were nice and I think it was a screen issue, they are allowing me to mail in the phone to get it replaced. Got the mailing label, just need to put it in a box and ship it off. Going to catch up on some more shows and maybe look into a side project. There's a thing I've been meaning to do with https://doingstuff.in so I may work on that. Right now, I'll just take it slow because I have another trip coming up.

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube 9duyDvjGwjU %}
Add Versioning to API Routes in Laravel
Tags: laravel, apiversioning, easy
Published: 2022-09-22 00:12:31

1. Create a folder named **api** in **routes**
2. Copy **routes\api.php** into the **api** folder
3. Rename **api.php** to **v1.php**
4. Change below **app\Providers\RouteServiceProvers.php**
    ```php
    Route::prefix('api')
    	->middleware('api')
    	->namespace($this->namespace)
    	->group(base_path('routes/api.php'));
    ```

    into

    ```php
    // example route will be /api/v1/users
    Route::prefix('api/v1') // add a version number
    	->middleware('api')
    	->namespace($this->namespace)
    	->group(base_path('routes/api/v1.php')); // update the path to the api routes
    ```
Using Google Container Registry, Docker Buildx, and GitHub Actions
Tags: docker, buildx, gcr, gcp
Published: 2022-09-25 07:35:23

---
title: Using Google Container Registry, Docker Buildx, and GitHub Actions
published: true
date: 2022-09-22 00:00:00 UTC
tags: docker, buildx, gcr, gcp
canonical_url: https://justin.poehnelt.com/posts/github-action-docker-build-gcr-io/
---

Today, I was trying to integrate the [docker/build-push-action](https://github.com/docker/build-push-action) with Google Container Registry (GCR). I was able to get the build working, but I was unable to push the image to GCR due to authentication issues. The solution involved the following.

1. Using the [google-github-actions/auth](https://github.com/google-github-actions/auth) action to authenticate with Google Cloud.
2. Calling `gcloud auth configure-docker --quiet gcr.io` to configure the Docker CLI to use the Google Cloud credentials.

The workflow looks like this.

```yaml
- name: Setup auth
  id: "auth"
  uses: "google-github-actions/auth@v0"
  with:
    workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
    service_account: "github-deployer@${{ secrets.GOOGLE_CLOUD_PROJECT }}.iam.gserviceaccount.com"
- name: Setup docker
  uses: docker/setup-buildx-action@v2
- name: Authenticate docker
  run: |
    gcloud auth configure-docker --quiet gcr.io
- name: Build and push
  uses: docker/build-push-action@v3
  with:
    context: .
    push: true
    tags: ${{ env.IMAGE }}
    cache-from: type=gha
    cache-to: type=gha,mode=max
```

I was unable to get the cache working with GCR. I’m not sure if it’s a bug or if I’m doing something wrong.

### IAM Role

I also created a custom role based upon `Storage Legacy Bucket Writer` to add to the `github-deployer@` service account.

  
![Custom role for pushing images to gcr.io](https://justin.poehnelt.com/images/container-pusher-role-e9S7fpbvYy-600.jpeg)    
    

This includes the following permissions.

- `storage.buckets.get`
- `storage.multipartUploads.abort`
- `storage.multipartUploads.create`
- `storage.multipartUploads.list`
- `storage.multipartUploads.listParts`
- `storage.objects.create`
- `storage.objects.delete`
- `storage.objects.list`

And it works! 🎉