teleren/devto huggingface dataset:
Merge Sorted Array
Tags: leetcode, java, programming, array
Published: 2022-04-05 04:00:22

Problem link: https://leetcode.com/problems/merge-sorted-array/
solution video: https://youtu.be/hVl2b3bLzBw , by Striver, TakeUForward
Solution:
```
class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
      int i= m-1;
      int j= n-1;
      int k= m+n-1;
     while(i>=0 && j>=0){
      //nums2[j] is larger value so it will go at k 
            if(nums1[i]<nums2[j]){
                nums1[k--] = nums2[j--];
            }else{
                nums1[k--] = nums1[i--];
            }
        }
        //If length of nums2 is more than length of nums1
        while(j>=0){
            nums1[k--] = nums2[j--];
        }
    }
}
```
one approach is to create the **two pointer to arrays**, whether start from beginning or from the end. We will use to insert the array elements from back, as array is already sorted so easier to put large elements at the back of the array.

**Approach:** We will create two pointers to compare the elements of the array of nums1[] and nums2[], which is i and j, and there would be third pointer k, which is set on nums1[], where we have to insert the elements at. So the pointer values will be -

i= m-1; j= n-1; k=m+n-1;

we will compare nums1[i] with nums2[j], out of these one element will be larger, whichever is the larger, we will insert our that element at k pointer index, and decrement the larger valued pointer and k pointer by 1, keeping the smaller pointer at same place.

we will keep doing for a loop until either j or i becomes 0,so the whole operation will be performed under _while(j>=0|| i>=0)_ 




**The Traps**: 
* you may not set index properly, you will get array out of bounds errors.
* post assignment operator of the index:
`nums1[k] = nums2[j]; 
k--; 
j--; ` 
can be written as:
`nums1[k--] = nums2[j--];` 
as the operation will be completed first i.e. `nums1[k] = nums2[j]` then there will be decrement in 'k' and 'j' as this is post decrement.
* use if-else, instead of creating other loop or else you will end up exceeding the time complexity limit.
The time complexity of this algorithm: O(n+m), as we are inserting k elements

* There may be the chances that one of the array will not end up earlier so to handle that we may add extra lines of code:
```
while(i>=0){
nums1[k--]= nums1[i--];
}
while(j>=0){
nums1[k--]= nums2[j--];
}

```


In this particular problem you need not to create a new array as nums1[] has already given enough space to fill the elements from nums2[], so the space complexity O(1).
WTF is HATEOAS?
Tags: api, backend, rest
Published: 2022-04-05 03:10:42

Recently I have been diving into the world of Laravel. I took it upon myself to speed run this great (a little outdated) Udemy course on creating REST APIs [Link](www.udemy.com/course/restful-api-with-laravel-php-homestead-passport-hateoas) and come across something new and interesting. HATEOAS.

Wikipedia defines it as (get ready); *Hypermedia as the Engine of Application State is a constraint of the REST application architecture that distinguishes it from other network application architectures. With HATEOAS, a client interacts with a network application whose application servers provide information dynamically through hypermedia.*

WHAT?! 

So my friends let me break it down for you. 

Basically, it means that hypertext should be used to find your way through the API.

Let me give you an example. Below is a Laravel transformer I created (one way to change the attribute names of our data from whats in the DB to the client) with the links for that resource included.


![Code for HATOAS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ptx39uri8mp57dhcuxwh.png)

At the top we have the transformer transforming the attribute names and below this we have the links for our routes. 

Rel is the name of the link and the href is the route of the resource. My code is just getting the route and inputting the ID into the route URL of this resource.

Now, what does this look like in the response?


![API Response](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yjavgls9s97wg5cu09p6.png)

As you can see, each of our items has a new section called links and this contains links to the other resources that are linked to this one.

This enables easier navigation through our API's, kind of like a website!

I hope this little tip improves you API's!

Footer:
I am currently living in Japan and looking for work (local or remote) so if you have anything, send it my way!

Check out my portfolio here [link](www.russell-carey.com).
Check out my twitter here [link](www.twitter.com/russellcareyy).
Check out my GitHub here [link](https://github.com/RussellCarey).
VIM usage
Tags: vim, beginners
Published: 2022-04-05 02:40:11

Today I suddenly wanted to learn vim on a whim, and opened youtube to learn from blogger Huang Haojie. Here are some notes below.

> The address of his video: [vim入门教程（第2讲） - YouTube](https://www.youtube.com/watch?v=gZ8HBGwfLAo&list=PLAnjpYDY-l8Le8Zcj4TPVe96mK107B9iT&index=4)

* w： the next word
* B： the previous word

---

* H: left
* L：right
* J：dwon
* k：up

----

* ctrl + F： turn up
* ctrl + D:  turn down

---

* xxx(line number) + gg: jump to the specified line

* xxx(line number) + j: jump xxx lines down
* xxx(line number) + k: jump xxx lines up

----

* / + xxx(the word to find): find all the specified word

> we can jump by pressing on the N key on the keyboard.Instead,we can use the shift + n to find the previous word.

---

* cc: cut a specified line

> we can also cut specified lines use the command of 'cc', for example, if we want to cut 2 lines, we can use this command: 'c2c'.

* u: revoke the previous operation
* p: paste 

---

> This is the first time for me to write a blog in English, so if there is a mistake, please correct me.
Why computer floating points are inaccurate
Tags: javascript, tutorial, computerscience, todayilearned
Published: 2022-04-05 02:12:50

Some days ago I went through a curious situation, I had a simple function that would turn money into cents, It was working properly until this happened: ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2g87wkb18lkvwno469jt.png)
**18.17** was the float being sent to the function, the function was basically floatNumber x 100 and I had no idea why every number I tested was working just fine but this one was not, I tested it on my browser and the same thing happened, I had to find a way how to make it work… 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83gn0k7tioomedgin29c.png)

## It happens in almost every programming language 
  So, after some research, I discovered the 0.1 + 0.2 problem and why in most programming languages 0.1 + 0.2 != 0.3(yes, you read it right), take a look at some of these examples:
**JS:**![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjyp4oenpj568bbram9i.png)
**Java:**![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/czdcj06enotnlf7s3eyu.png)
**Dart:**![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9zjpnubh3fcknx26jvwb.png)
As you can see, in these languages 0.1 + 0.2 != 0.3.

## Why does this happen?
 
 Double-precision floating-point format, also known as binary64(https://en.wikipedia.org/wiki/Double-precision_floating-point_format), is a computer number format most of our processors follow, it stores our number in bits this way:![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqxi4gffdwvat6alnh1i.png)
Having 64 bits, 1bit is for the sign so we know if the number is positive or negative, 11bits are the exponent(https://en.wikipedia.org/wiki/Exponentiation) that will tell us if our mantissa represents an integer or a fraction, and 52bits for the mantissa(https://en.wikipedia.org/wiki/Significand) that gives us from 15 to 17 decimal digits precision, **the problem is:** some numbers just can’t be fully represented exactly in this way, only approximately. 

## The solution
**My solution:** The solution for my problem, converting money into cents was the following:![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7a6f2onugw3zomy40o99.png)
All I needed was to move the decimal points 2x to the right, and I did so by using the **e notation**(https://en.wikipedia.org/wiki/Scientific_notation#E_notation) which represents 10 to the power of the number that comes next, in my case, 2. 

**Final thoughts**
I brought only one solution, but there are more solutions out there that will fit better what you want to do, so go ahead, find out more solutions, and don’t forget to come back here and comment the solution you’ve found so more people will benefit from this article, wish you all the best.

## Read more
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
https://en.wikipedia.org/wiki/Double-precision_floating-point_format
Push Docker Image to AWS ECR - Bitbucket Pipeline
Tags: aws, kubernetes, bitbucket
Published: 2022-04-05 01:54:39

We'll do the following

- Create Bitbucket repository
- Push Docker image to ECR from Bitbucket
- Configure Bitbucket pipeline.


# Create Bitbucket repository

1: Created ssh key.

```bash
ssh-keygen -t rsa -C aaa@example.com
```

2: Add pub key to bitbucket.

3: set remote but... password is needed?

```bash
git remote add origin git@bitbucket.org:xxx/yyy.git
git push origin master

Password for 'https://aaa@bitbucket.org': 
# ????
```

4: Get remote URL

```bash
git config --get remote.origin.url

https://aaa@bitbucket.org/bbb/ccc.git
```

5: This should not be https... should be git.

```bash
git remote set-url origin git@bitbucket.org:xxxx/yyyy.git
```

error..


6: Specify ssh key

https://qiita.com/sonots/items/826b90b085f294f93acf

---

# Push Docker image to ECR from Bitbucket


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

**We have to create the IAM Role of OIDC.**

## Get identity provider of Bitbucket.

You can get the information from Bitbucket.

`{Your repository settings} > Pipelines > OpenID Connect`

Get the following.
- **Identity provider URL**
- **Audience**

## AWS IAM Setting.

### Create provider

- Go to `IAM > Identity providers > Add provider`.
- Fill in `Identity provider URL` and `Audience`.

### Create policy

```json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "GetAuthorizationToken",
            "Effect": "Allow",
            "Action": [
                "ecr:GetAuthorizationToken"
            ],
            "Resource": "*"
        },
        {
            "Sid": "AllowPushImage",
            "Effect": "Allow",
            "Action": [
                "ecr:BatchCheckLayerAvailability",
                "ecr:InitiateLayerUpload",
                "ecr:UploadLayerPart",
                "ecr:CompleteLayerUpload",
                "ecr:PutImage"
            ],
            "Resource": "arn:aws:ecr:ap-northeast-1:{AWS Account ID}:repository/*"
        }
    ]
}
```

### Create role

- Go to `IAM > Role > Create role`.
- Select `Web identity`.
- Select `Identity provider URL` and `Audience` created by previous step.
- Choose policy created in previous step.

---

# Configure bitbucket pipeline.

[Official](https://bitbucket.org/product/features/pipelines/integrations?p=atlassian/aws-ecr-push-image)

**Minimum configuration**

```yaml
image: atlassian/default-image:2

definitions:
  script: &ecrScript
    - docker build -t $REPO_NAME .
    - pipe: atlassian/aws-ecr-push-image:1.5.0
      variables:
        AWS_OIDC_ROLE_ARN: $OIDC_ROLE_ARN
        IMAGE_NAME: $IMAGE_NAME
        TAGS: "${BITBUCKET_TAG} build-$BITBUCKET_BUILD_NUMBER latest"

pipelines:
  custom:
    build-custom:
      - step:
          name: Deploy to ECR
          services:
            - docker
          oidc: true
          script: *ecrScript
```

**NOTE**

`AWS_DEFAULT_REGION` must be configured as Variable. Otherwise we will get the error `ValueError: Invalid endpoint: https://api.ecr..amazonaws.com`. Please check official document.
Refresh Gatsby Content Without Restarting Development Server
Tags: javascript, gatsby, webdev, beginners
Published: 2022-04-05 01:47:42

I can't count how many hours I've wasted staring at my terminal waiting for the Gatsby development server to restart after editing content. Luckily, Gatsby can expose an endpoint to refresh content without restarting the whole server.

## Prerequisite
- <a href="https://www.postman.com/" target="_blank" rel="noopener">Postman</a> HTTP client.

# Enabling Refresh Endpoint
Add `ENABLE_GATSBY_REFRESH_ENDPOINT=true` to your development <a href="https://www.gatsbyjs.com/docs/how-to/local-development/environment-variables/" target="_blank" rel="noopener">environment variables</a> to enable the refresh endpoint. The endpoint exposes as `http://localhost:8000/__refresh`.

```shell
{"title": ".env.development"}
ENABLE_GATSBY_REFRESH_ENDPOINT=true
```

# Triggering Refresh Endpoint
Using postman, send an HTTP `POST` request to the `http://localhost:8000/__refresh` endpoint.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/c4v63VNyJEkRBUkUE1/giphy.gif">

Much faster than a complete server restart.

<img width="100%" style="width:100%" src="https://media.giphy.com/media/FQWrwIB3zfGaNBlHLW/giphy.gif">

## Using the Terminal
The refresh endpoint can also be triggered using the terminal on Unix-based operating systems.

```shell
curl -X POST http://localhost:8000/__refresh
```

# Conclusion
The refresh feature is enabled by adding the `ENABLE_GATSBY_REFRESH_ENDPOINT=true` development environment variable. The endpoint is exposed as `http://localhost:8000/__refresh` and triggered by `POST` requests.

If you believe I've helped, consider signing up for my <a href="https://gregorygaines.substack.com/subscribe">newsletter</a> or <a href="https://www.gregorygaines.com/support">supporting me</a>.
Stand with Ukraine, Cancel the Debt
Tags: wealth, ukraine, diplomacy
Published: 2022-04-05 01:17:56


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

The war mongering European Nations (EU) have been providing significant humanitarian aids but all come at significant cost under the carpet. All of the sentiment to support Ukraine is successfully rewarding the pockets of bankers in Europe and North America. Across the world, the voice to support Ukraine is genuine; however, financial industries have not waved any interest payment that could be used to support the people in crisis. World sympathy, particularly American sympathy is going to be too expensive for Ukraine people to bear in the aftermaths of war. 

Ukraine, deeply troubled financially even before the war at 95 billion debt to Independent Monetary Funds (IMF), has been maintaining financial debt through giving free pass to North American Treaty Organization (NATO) to run biochemical weapon labs throughout the country. While Prime Minister Justin Trudeau and his Finance Minister Chrystia Freeland have been standing with Ukraine since day one; the NATO company is refusing to cancel the debt for Ukraine. 

Big bankers and weapon manufacturers are continuing to profit from the misery of people in the name of aid. Ukraine war may be over soon but people of Ukraine is unlikely to recover from the debt trap diplomacy of United States and the NATO allies. To really stand with Ukraine is to demand IMF to cancel all debts immediately so that children of Ukraine can one day live free in the country without being sold for American oligarchy. #Ukraine #wealth #diplomacy
Add Your Coding Projects To Your LinkedIn Page
Tags: linkedin, projects, beginners, tutorial
Published: 2022-04-08 13:36:14

---
title: Add Your Coding Projects To Your LinkedIn Page
published: true
cover_image: https://blog.eamonncottrell.com/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1649120826015%2F_LTCuvYEx.jpg%3Fw%3D1600%26h%3D840%26fit%3Dcrop%26crop%3Dentropy%26auto%3Dcompress%2Cformat%26format%3Dwebp&w=1920&q=75
date: 2022-04-05 01:07:49 UTC
tags: linkedin,projects,beginners,tutorial
canonical_url: https://blog.eamonncottrell.com/add-your-coding-projects-to-your-linkedin-page
---

## Upgrade Your LinkedIn Profile Page

Click your profile pic up in the top right, and then View Profile.

![view.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1649119426217/Bdm0uBBEh.png)

Profile's are kind of a hot mess on LinkedIn imo right now. I converted mine to [Creator Mode](https://www.linkedin.com/help/linkedin/answer/a522537/linkedin-creator-mode?lang=en) last year, which you can do in the Resources section of your profile. This is supposed to help with discovery, highlighting content on your profile, and gives you access to "creator analytics".

![creator.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1649119420013/gziaMWih9.png)

Honestly, I'm using Hashnode for most of my content and making posts on LinkedIn sometimes now, but it's probably good to have the creator mode on, regardless...since, you know, we're creators. 😊

At any rate, click the Add profile section button under your title.

![add.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1649119663888/-HAMGd_oQ.png)

This brings up a host of options. Under Additional, you'll find **projects**. Give it a click and add your great work!

![projects.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1649119741898/D7-JzquMr.png)

Fill out the details and you're good to go.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1649119877594/J7jXULRyk.png)

## Is it Worth It?

There are so many sections on LinkedIn, I hesitated to add another one to my profile. Add to this the fact that for some reason, there is not a way to rearrange the sections. 🤷‍♂️ You can edit what sections are visible, but they are ordered according to LinkedIn. Seems dumb.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1649120188392/D5Ozwg5Wq.png)

I may alter my profile further to remove some things like Honors & awards (mainly stuff from my college years). I think it's worth having projects, though, and I'll be sprucing that section up more over the course of this week.

Check out my page and let me know what you think: https://www.linkedin.com/in/eamonncottrell/

## Thanks for Reading!

I appreciate you taking the time to check this out. Come say hey to me on [Twitter](https://twitter.com/EamonnCottrell)! 👋
How to change Flutter Stop Error Screen Style?
Tags: flutter, dart
Published: 2022-04-04 23:52:33


In many cases you need to see the error exception of Flutter as friendly as possible when you develop your app. For example, this red stop screen error:

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

Fortunately, the red stop exception error screen of Flutter you can edit as you want with custom style.
In main function of dart you need to add customization of ErrorWidget.builder as the following:
`void main() {
  ErrorWidget.builder = (FlutterErrorDetails details) => Material(
    child: Container(
      padding: const EdgeInsets.symmetric(vertical: 40.0, horizontal: 20.0),
      child: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
// If you need to add another friendly photo 
             // you can here for example  
         
             const Text(
              'Error',
              textAlign: TextAlign.center,
              style: TextStyle(
                color: Colors.redAccent,
                fontSize: 24,
                fontWeight: FontWeight.bold,
              ),
            ),
            const SizedBox(height: 20),
            Text(
              details.exceptionAsString(),
              textAlign: TextAlign.justify,
              style: const TextStyle(
                color: Colors.red,
                fontSize: 18,
                fontWeight: FontWeight.normal,
              ),
            ),
          ],
        ),
      ),
    ),
  );
 runApp(MyApp());
}`

And the result of any error as this instead of it before customization:

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

Finally, the error or Flutter exception appear more friendly when you develop your apps.
The store will be closed for software upgrade
Tags: cicd, continuousdelivery
Published: 2022-09-27 09:49:36

---
title: The store will be closed for software upgrade
published: true
date: 2022-04-05 00:00:00 UTC
tags: cicd,continuousdelivery
canonical_url: https://jhall.io/archive/2022/04/05/the-store-will-be-closed-for-software-upgrade/
---

I stumbled upon this gem recently on LinkedIn. The photographer’s neighborhood fueling station is scheduled to be closed on April 14, for a software upgrade. (Shared with permission)

 ![](https://jhall.io/images/store-will-be-closed_hu4b57168e66b5bd1603839e37cd4dd11b_192649_600x0_resize_q85_box.jpg)

I don’t know how much money this store makes on an average day, but no doubt, this is an expensive upgrade!

Now I wouldn’t necissarily expect a corner gas station to have their POS (or whatever other system) upgraded automatically via continuous deployment. But in 2022, I can’t think of any legitimate reason that a place of business should need to close for a software upgrade.

* * *
_If you enjoyed this message, [subscribe](https://jhall.io/daily) to <u>The Daily Commit</u> to get future messages to your inbox._