teleren/devto huggingface dataset:
How to copy S3 objects across different AWS Accounts
Tags: s3, aws, cloud, ami
Published: 2023-03-30 20:51:54

---
title: How to copy S3 objects across different AWS Accounts
published: true
date: 2022-12-18 10:32:46 UTC
tags: s3,aws,cloud,ami
canonical_url: 
---

Copying S3 files across different AWS accounts happens quite often if you manage multiple AWS accounts no matter for different teams, products or environments. It is not a complex setup but it shows how AWS perfectly design and operate cross-account permissions.

I created below video for the hands-on process. If you find it useful, please help to like and subscribe my channel for future videos

{% youtube PZbkYwhOfaE %}

There are two main steps regarding the permission setup:

![](https://cdn-images-1.medium.com/max/618/1*c-9G9ii13Ol-Go8fQskXgQ.png)

1. S3 Bucket policy: All root access from the destination account;

Below is the bucket policy. Destination account ID and source bucket name need to be replaced.

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowCopy",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::[destination_account_id]:root"
            },
            "Action": [
                "s3:ListBucket",
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::[source_bucket_name]/*",
                "arn:aws:s3:::[source_bucket_name]"
            ]
        }
    ]
}
```

2. IAM User/Role: Entity with required permissions to execute the copy/sync action.

You need to create a policy with below permissions and attach it to the IAM role or user which will execute the copy/sync action.

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::[source_bucket_name]",
                "arn:aws:s3:::[source_bucket_name]/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::[destination_bucket_name]",
                "arn:aws:s3:::[destination_bucket_name]/*"
            ]
        }
    ]
}
```

Source bucket name and destination bucket name need to be replaced. From above policy we can see, we need to allow GetObject from the source bucket and PutObject to the destination bucket which is for the copying behaviour.

3. In this article, I will use AWS CLI to execute the copy/sync action.

Below are examples and the region parameter is actually optional.

```
# copy file from source to destination
aws s3 cp s3://source_bucket_name/filename s3://destination_bucket_name/filename --source-region [source_bucket_region]
# sync source foloder to destination folder
aws s3 sync s3://source_bucket_name s3://destination_bucket_name --source-region [source_bucket_region]
```

Now you should know how to do the cross-account s3 objects copying.

Thanks.

Harry
How to execute any command from anywhere to anywhere in your laptop !
Tags: bash, linux, unix, terminal
Published: 2022-12-18 12:13:56

---
title: How to execute any command from anywhere to anywhere in your laptop !
published: true
description: In this tip i will show you how simple it is to run a command to any directory in your local machine
tags: bash, linux, unix, terminal
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uu6pc0ipayoog1316pli.jpg
---

Sometimes i got in situations where i want to execute a specific command or multiple commands inside a given directory without moving there as quickly as i can !
This may sound obvious to just jump there, do the stuff and come back but as a lazy guy, i like doing that as quickly as possible and hit enter once !

![target](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xxpojlupfhlk96l544mc.png)

So in this tip, you will need [zoxide](https://github.com/ajeetdsouza/zoxide), a nice tool that cache all your paths by their finals dirname, that mean wherever you are in your linux system `~/zig/zag/toum/yyyy`, you just have to type *cd xxxx* (which is here `~/boum/bam/xxx`), to go there !

So this is my tip:
- go to the target dir (`$1` as the given dir)
- execute the command (`{$@:2}` as all strings after the dir)
- get back from where i was (`cd -`)

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

Then add it inside your `~/.bash_aliases` and you're good to go !

You can copy the source code from [here](https://gist.github.com/Sanix-Darker/27a0cb536b9c2ec7f29f93c70b942785) !
React custom hook
Tags: react, hooks
Published: 2022-12-18 12:13:18

---
title: React custom hook
published: true
description: Building your own React Hooks
tags: React, hooks
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2022-12-18 11:54 +0000
---

> This post was originally posted on my blog @ [easy-code.blog](https://easy-code.blog)

Hooks are a new addition in React 16.8 and above. They let you use state and other React features without writing a class.

Building your own Hooks lets you extract component logic into reusable functions.

Let's take a look into this simple hook example:
```jsx
import React, {useState} from 'react';

const CounterApp = () => {
     // Declare a new state variable, which we'll call "count"
    const [count, setCount] = useState(0);

    const increment = () => setCount(count + 1);
    const decrement = () => setCount(count - 1);
    
    return (
        <div>
            <h1>Your number is {count}</h1>
            <button onClick={() => increment()}>
             Increment 
            </button>
            <button onClick={() => decrement()}>
             Decrement 
            </button>
        </div>
    );
};

export default CounterApp;

```

In the above example you will notice that when logic will have more cases it will be difficult and unable to reuse.

#### Extracting a Custom Hook:
When we want to share logic between two JavaScript functions, we extract it to a third function. Both components and Hooks are functions, so this works for them too!

A custom Hook is a JavaScript function whose name starts with ”use” and that may call other Hooks. For example, <mark>useCounter</mark> below is our first custom Hook:

```jsx
import React, {useState} from 'react';

const useCounter(value? : number) {
    // use parameter value or init with 0 value.
    const [count, setCount] = useState(value || 0);

    const incrementCounter = () => setCount(count + 1);
    const decrementCounter = () => setCount(count - 1);

    return {
        count,
        setCount,
        incrementCounter,
        decrementCounter
    }
}

export default useCounter;

```

#### Using the Counter Hook:

```jsx
import React, {useState} from 'react';
import {useCounter} from './my-counter-hook'

const CounterApp = () => {
     // Declare my Counter hook
    const [count, setCount, incrementCounter, decrementCounter] = useCounter(0);
    
    // extend for reuse
    const reset = () => setCount(0);
    return (
        <div>
            <h1>Your number is {count}</h1>
            <button onClick={incrementCounter()}>
             Increment 
            </button>
            <button onClick={() => decrementCounter()}>
             Decrement 
            </button>
        </div>
    );
};

export default CounterApp;

```


#### useYourImagination()

Custom Hooks offer the flexibility of sharing logic that wasn’t possible in React components before. You can write custom Hooks that cover a wide range of use cases like form handling, animation, declarative subscriptions, timers, and probably many more we haven’t considered. 




Happy Debugging 👨🏼‍💻👩‍💻
Algorithm with different complexity Big O Notation
Published: 2022-12-18 11:54:03

There are usually 5 type of algorithm complexities that belongs to the alogorithm . Aim of the good programmer is to write the algorithm which has good performance and complexity is reduced relative to the input data. they are relative to the input that we give to the algorithm in the java programming. below are the 5 types of the big 0 notation used. 

**_O(1) constant complexity_** : this is constant time complexity. it would mean that irrespective of the data, alogrithm would take same and constant time to do an operation. the efficiency of these algorithm remain constant with the input data. some of the example of this complexity is data dictionary, key value pairs.

**_O(n): linear complexity_**: this is linear time notation. this would mean that for the input size of n , n steps would be executed and as the input is increased. more time and more steps would be taken by the algorithm or the piece of code.
 
**_O(n*n) quadratic complexity_**: this is the worst case scenario for many searching and sorting technique, that we use. this would mean that as the input size increase the time taken by algorithm would almost double . we want to use them for the small input data, as they perform good with small input data. but as the input data is increased, performance of these algorithm decreases.

**_Logarithmic complexity.O(n log n)_** : this would mean that the with the increase in the input data, steps or the complexity and time taken would increase, but it will increase at the rate of log of n. usually base of log is 2, as we half the input size and data.

**_Exponential Complexity:_** these algorithm have runtime complexity of O(kN) . the example of these algorithm is the brute force algorithm to search the password and travelling salesman problem. the time exponentially increase and the study is still going on to make them better.
A list of critical justifications for utilizing Docker.
Tags: webdev, programming, tutorial, devops
Published: 2022-12-18 11:44:38

Docker is a tool designed to make it easier to deploy, run, and manage applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.

Using Docker has a number of benefits:

- Portability: You can build your application in a container on your local machine, and then run the same container on other machines, regardless of the underlying architecture. This makes it easy to deploy your application to different environments, such as staging and production.


- Isolation: Containers isolate applications from one another and from the host system, so you can run multiple applications on the same host without them interfering with each other. This can be especially useful when running microservices, where each service can be containerized and run independently.


- Ease of use: Docker provides a simple and consistent way to build, ship, and run applications. It simplifies the process of setting up a development environment and makes it easy to automate the deployment and management of your applications.


- Efficiency: Docker allows you to only package and ship the parts of your application that have changed, rather than the entire application. This can make your deployments faster and more efficient.


Overall, using Docker can help you develop and deploy applications more quickly and easily, and can make it easier to scale and manage your applications in different environments.

Thanks for reading...
**Happy Coding!**
Rock Out with the Best Vintage Speakers
Published: 2022-12-18 11:42:54

Are you a fan of rock and roll music? If so, you know the importance of having a good [sound system.](https://vintagespeakersguide.com/best-vintage-speakers-for-rock-music/) But you don't have to spend a lot of money to get a great setup. Check out our list of the best vintage speakers for rock music. From classic models to modern-day favorites, these speakers will have your rock and roll sounding just the way you like it. So let's start rocking out!
739. Leetcode Solution in cpp
Tags: cpp
Published: 2022-12-18 11:22:18

```cpp
class Solution {
 public:
  vector<int> dailyTemperatures(vector<int>& temperatures) {
    vector<int> ans(temperatures.size());
    stack<int> stack;  // decreasing stack

    for (int i = 0; i < temperatures.size(); ++i) {
      while (!stack.empty() && temperatures[stack.top()] < temperatures[i]) {
        const int index = stack.top();
        stack.pop();
        ans[index] = i - index;
      }
      stack.push(i);
    }

    return ans;
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/daily-temperatures
CORS how to enable them in .NET?
Tags: cqrs, dependency, dotnetcore, csharp
Published: 2022-12-18 10:57:24

---
title: CORS how to enable them in .NET?
published: true
description: CORS stands for Cross Origin Resource sharing, so what exactly is cross origin.
tags: CQRS, dependency, dotnetcore, csharp
# published_at: 2022-12-18 10:53 +0000
---

These two URLs have the same origin:
𝗁𝗍𝗍𝗉𝗌://𝗆𝗒-𝗌𝗂𝗍𝖾-𝗇𝗈-𝟣.𝖼𝗈𝗆/𝖦𝖾𝗍/𝖧𝖺𝗄𝗎𝗇𝖺𝖬𝖺𝗍𝖺𝗍𝖺
𝗁𝗍𝗍𝗉𝗌://𝗆𝗒-𝗌𝗂𝗍𝖾-𝗇𝗈-𝟣.𝖼𝗈𝗆/𝖦𝖾𝗍/𝖠𝗅𝗅𝖨𝗌𝖶𝖾𝗅𝗅

These URLs have different origins
𝗁𝗍𝗍𝗉𝗌://𝗆𝗒-𝗌𝗂𝗍𝖾-𝗇𝗈-𝟣.𝖼𝗈𝗆/𝖦𝖾𝗍/𝖧𝖺𝗄𝗎𝗇𝖺𝖬𝖺𝗍𝖺𝗍𝖺
𝗁𝗍𝗍𝗉://𝗆𝗒-𝗌𝗂𝗍𝖾-𝗇𝗈-𝟣.𝗇𝖾𝗍/𝖦𝖾𝗍/𝖠𝗅𝗅𝖨𝗌𝖶𝖾𝗅𝗅

To facilitate requests from different origins you need to enable CORS in .NET.

In .NET 6 by using the combination of these methods you can enable CORS as per your requirement.

𝐀𝐥𝐥𝐨𝐰𝐀𝐧𝐲𝐎𝐫𝐢𝐠𝐢𝐧: This policy allows requests from any origin.

𝐖𝐢𝐭𝐡𝐎𝐫𝐢𝐠𝐢𝐧𝐬: This policy allows requests from specific origins. You can specify one or more origins as arguments to this method.

𝐀𝐥𝐥𝐨𝐰𝐀𝐧𝐲𝐇𝐞𝐚𝐝𝐞𝐫: This policy allows requests with any header.

𝐖𝐢𝐭𝐡𝐇𝐞𝐚𝐝𝐞𝐫𝐬: This policy allows requests with specific headers. You can specify one or more headers as arguments to this method.

𝐀𝐥𝐥𝐨𝐰𝐀𝐧𝐲𝐌𝐞𝐭𝐡𝐨𝐝: This policy allows requests with any HTTP method (e.g., GET, POST, PUT, DELETE).

𝐖𝐢𝐭𝐡𝐌𝐞𝐭𝐡𝐨𝐝𝐬: This policy allows requests with specific HTTP methods. You can specify one or more methods as arguments to this method.

Few Things to Keep in mind

✔️CORS is not a security feature. CORS is a W3C standard that allows a server to relax the same-origin policy.

✔️An API isn't safer by allowing CORS.

✔️It's a way for a server to allow browsers to execute a cross-origin request that otherwise would be forbidden.

✔️Browsers without CORS can't do cross-origin requests.
Embedded Systems Weekly #131
Tags: embedded
Published: 2022-12-18 10:39:23

Welcome to edition 131 of our weekly newsletter on embedded systems!

This week, we have hand-picked a selection of links to please the C lovers among you. Whether you're an experienced professional or just starting to learn about embedded systems, we hope you enjoy this edition of our newsletter!

**Happy reading!**

## Articles 
[How to Identify a Microcontroller Model Using Firmware Analysis](https://www.apriorit.com/dev-blog/787-reverse-engineering-microcontroller-model-identification)
It's the first time that I read an article along this angle. It's very interesting to discover the techniques used to identify the microcontroller from the firmware.

[How the 8086 processor's microcode engine works](https://www.righto.com/2022/11/how-8086-processors-microcode-engine.html)
Besides the interesting writing on the 8086 itself, I like as well the part on the microcode history. Ken Shirriff is delivering yet another great article.

[Understanding Concurrency Vulnerabilities in Linux Kernel](https://arxiv.org/abs/2212.05438)
Based on bugs listed in the CVE database during the last ten years, the study covers 101 concurrency vulnerabilities. Among the things covered, the study classify the fixes in four different classes named condition check, code switch, lock strategy and design change.

[A Christmas tree bauble that plays Doom](https://spritesmods.com/?art=doom-bauble)
It is, at the same time, charming and impressive technically. The author shares the schematics. He shares how he modified an existing Doom port to make it possible to pair a BLE keyboard with the bauble. Yes, you got it. You can play on the bauble. With the case design files, everything is available in the [Doom on an ESP32-C3 based Christmas tree bauble](https://github.com/Spritetm/esp32c3-doom-bauble) repository.

## Jobs
[Octopus Energy, Embedded Software Engineer, Slough, UK (Partially remote)](https://jobs.embedsysweekly.com/job/9BNPORM9/embedded-software-engineer)
Our ambition is to help put the world on the path to Net Zero. Through our R&D team, we’re working on exciting projects that will directly impact the future of renewable energy. Our R&D team is now rapidly expanding and we’re looking for determined people to join us on our mission.

## Misc
[Quines (self-replicating programs)](http://www.madore.org/~david/computers/quine.html)
It is an oldie, but it remains fun to check out. Enjoy!
Introducing Foodie 🎉
Tags: beginners, nextjs, prisma, webdev
Published: 2022-12-18 10:26:23

I am excited to introduce my new side project, [Foodie](foodie-navy.vercel.app) — a web app built with NextJS and Tailwind for all you recipe lovers out there.

**🔍 Search and Filter**
With Foodie, you can easily search for recipes by name or filter your search based on whether you prefer vegetarian or non-vegetarian options. This way, you can find the perfect recipe to suit your tastes and dietary preferences.

**📝 Share Your Recipes**
Foodie is not just a place to find new recipes, but also a community for sharing your own creations. Simply post your recipe in markdown format and share it with others. You never know, you might just inspire someone to try something new in the kitchen!

**🍴 Get started with Foodie today!**
Ready to start exploring the delicious world of Foodie? Come visit [Foodie](foodie-navy.vercel.app).
A/B testing development - A developer overview (Part - 2)
Tags: javascript, cro, abtesting
Published: 2022-12-18 10:12:02

In my previous blog [Part 1](https://dev.to/faroqueabdullah/ab-testing-development-a-developer-overview-part-1-16ln), I have explained what is A/B testing and why we need A/B testing. Now I will discuss about different ways of A/B testing. Mainly there are two ways of A/B testing Client side and Server side.

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


## Client Side A/B testing:
Relatively quick and easy to deploy. It actually works only on the browser where you will inject javascript code to the browser to modify your UI/UX. The client-side approach is by far the most common solution employed in the market today. In this approach, all tests and experiences are rendered from the client-side browser, using Javascript. There are few.

**Advantages of client-side A/B testing:**
1. Easy to deploy.
2. Easy to work around.
3. No backend limitations.
4. Even non-technical people can work by the help of visual editor.
5. Only need basic javascript, HTML and CSS to develop a complex test.
6. No risk to conflict with your production code.


**Disadvantage of client-side A/B testing:**
1. Only targeted on browser.
2. Some times control flicker can arise.
3. Limited to the page functionality not to the app functionality.
4. Not able to work on business logic.
5. Sometimes page takes time to load.
6. Few browser can block third party A/B testing tools to inject script.


## Server-side A/B testing:
Server-side A/B testing is a form of experimentation where the variations of a test are rendered directly on the web server, before it is delivered to the client. So you need to deploy you variations code to the server.

**Advantages of server-side A/B testing:**
1. Write the same programming language which is using in the server.
2. Get more customising option in you app functionality.
3. No control flicker as code is coming from the server itself.
4. Work on any business logic inside your application.

  
**Disadvantage of server-side A/B testing:**
1. Time consuming and harder development process compare to client-side.
2. Every time needed production deployment to host the test.
3. Built into your web application tech stack.

There are many tools in the market to work on A/B testing. We will discuss about some A/B testing tools and their architecture in our future blog . Happy Coding !!!!!
Javascript Array.from() second argument
Tags: javascript, beginners, programming
Published: 2022-12-18 10:00:00

`Array.from()` is a method that creates a new array from an array-like or iterable object. However, one property that is often overlooked is that the method can accept a mapping function as a second argument. 

This map function is called on every element of the array that is being generated. Basically, `Array.from()` with a function as a second argument is equivalent to `Array.from().map()` only that it does not create an intermediate array.

```js
console.log(Array.from([1, 2, 3], x => x + x)); // [2, 4, 6]
```

One very simple use case for this is to create an array of a specific length and fill it with an arithmetic sequence. 
For example, if you want to create an array of 5 elements and fill it with the value 1 to 5, you can do it like this:

```js
const arr = Array.from({ length: 5 }, (v, i) => i + 1);
console.log(arr); // [1, 2, 3, 4, 5]
```
[Rust commands] Start project
Published: 2022-12-18 08:57:50

```
┌ Start project with subcommand 'new'
│$ cargo new <directory_name>
└─────
┌ Start project with subcommand 'init'
│$ mkdir <directory_name> && cd $_
│$ cargo init
└─────
```
```
┌ Cargo run with watch
│$ cargo install cargo-watch
│↳ cargo watch -q -c -x 'run'
└─────
```
What are your New Year's resolutions?
Tags: discuss, devjournal, abotwrotethis
Published: 2022-12-18 08:49:19

> I will work towards becoming a senior developer by expanding my skills and knowledge in backend development through continuous learning and practice. I will also focus on building my professional network and seeking out opportunities for professional growth.

It's great to have goals and resolutions for the new year! Here are a few tips for setting and achieving your new year resolutions:

1. Make your resolutions specific and achievable: Instead of resolving to "exercise more," try setting a specific goal such as "exercise for 30 minutes at least three times a week."

2. Break your resolution down into smaller goals: If your resolution is a big one, it can be helpful to break it down into smaller, more manageable goals. This will make it easier to track your progress and stay motivated.

3. Create a plan: Think about the steps you need to take to achieve your resolution and make a plan to follow. For example, if your resolution is to exercise more, you might plan to join a gym or find an exercise class that you enjoy.

4. Monitor your progress: Keep track of your progress and celebrate your successes along the way. This will help you stay motivated and on track.

5. Be flexible: It's okay if you have setbacks or if things don't go exactly as planned. Just stay positive and adjust your plan as needed.

Remember, the key to achieving your new year resolutions is to be patient, persistent, and positive. With hard work and determination, you can achieve your goals!

Surprise, this article was generated by ChatGPT!