teleren/devto huggingface dataset:
[NodeJs/AWS] Self-reload SSO keys in credentials file
Tags: aws, credentias, sso, awscredentials
Published: 2021-06-28 14:07:02

# AWS SSO Credentials Script

Hello everyone! I just wanted to share a script i made in Nodejs using the V3 AWS Sdk for javascript.
This is a script to (almost)automatically update your local credentials file.
I say _almost_ because at some point you'll need to click a button (or two in the worst scenario).

## Motivation
The SSO credentials expires every day, so I did not want to update this file manually. This script is very useful when you have a lot of accounts/roles in your organization.

## Requirements
* Node.js - [Install Node.js](https://nodejs.org/en/)

## How to use

First of all download the code from github - [aws-sso-creds-tool](https://github.com/leandrosalo/aws-sso-creds-tool)
 ```git clone https://github.com/leandrosalo/aws-sso-creds-tool.git```

### Update .env file with the correct params

It is required to set the sso url like this:
```shell
SSO_URL="https://<your-project>.awsapps.com/start#/"
```

The credentials will be stored as __[account-name_AWSRoleName]__.
If you want to store it as __[123456789098_AWSRoleName]__ add this:
```shell
USE_ACCOUNT_ID=true
```
_if you want a different profile name pattern update the code..._

It uses _us-east-1_ as default aws region and searches for the credentials file in the default path.
If you want to change it, add this:
```shell
REGION=us-east-1
AWS_CREDENTIALS_PATH=/Users/you/.aws/credentials
```

### First time use
1. Run `npm install` in this folder
2. Update the `.env` with the correct values
3. Run `node app.js`
4. At some point the aws webpage will popup
    1. Log in to aws if you are not already
    2. The code for device authentication will be auto filled
    3. Click on Sign In

<img width="346" alt="Screen Shot 2021-06-25 at 11 59 23" src="https://user-images.githubusercontent.com/7031690/123454656-2e73bb00-d5b7-11eb-8db7-a79fda950bc5.png">

5. When the success alert shows then come back to the terminal and press a key

<img width="346" alt="Screen Shot 2021-06-25 at 11 59 36" src="https://user-images.githubusercontent.com/7031690/123454778-52cf9780-d5b7-11eb-9081-c2a08c2430b0.png">


7. Done!

For consequents runs just start from step 3.

# Feel free to share, copy and improve!
Database... or Goose?
Published: 2021-06-28 13:56:00

Once a platform reaches a certain amount of usage, database migration can quickly bring a platform down. For example, adding a column, if not done carefully, [can block entirely lock a table](https://medium.com/doctolib/stop-worrying-about-postgresql-locks-in-your-rails-migrations-3426027e9cc9) for a few minutes.

At Doctolib, we developed [safe-pg-migrations](https://github.com/doctolib/safe-pg-migrations), a tool which automatically makes migrations safe. In 2018, we open-sourced this library. From an internal solution developed by our team only, it is now used on other projects, and even received contribution from external authors.

To acknowledge, we decided to give safe-pg-migrations a logo. Our design team came up with two propositions.


![parachute logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aveqh0v09mg7s9khd76v.png) | ![bird logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hh35yxdp132zhcbgmxdq.png)
---|---

We would like you to help us choose the best logo. To do so, answer to the survey on the tweet bellow: 

 {% twitter 1409421282773549058 %}
TDD and tests with Mocks
Tags: tdd, mockito, java, beginners
Published: 2021-06-28 13:47:24

#TDD

Test Driven Development is a way of developing your code where the test is created before the actual code. This is made to make sure that the development works. The test must be the first thing to be created so the code can be created around it.

A good way to make these tests is using Mockito.

#Mockito

Mockito is a mocking framework that is frequently used in unit tests. Mocking an object simulates it's behavior. When this simulation is created, it makes possible to realize a test without the need to call a complex object, we call only the mocked object.

###Exemples

It's necessary to initiate the mocks before the tests.

```
@Before
public void setup(){
	service = new RentService();
	RentDAO dao = Mockito.mock(RentDAO.class);
	service.setRentDao(dao);
	spcService = Mockito.mock(SPCService.class);
	service.setSpcService(spcService);
}
```

I'm simulating the interfaces RentDAO and SPCService with Mockito.

RentDAO: `public void save(Rent rent);`
SPCService: `public boolean isNegative(User user);`

With this we can make our test calling the mock.
```
@Test
public void rentTest() throws Exception {
	//given
	User user = UserBuilder.aUser().now();
	List<Movie> movies = Arrays.asList(MovieBuilder.aMovie().withValue(5.0).now());
	
	//when
	Rent rent = service.rentMovie(user, movies);

	//then
	error.checkThat(rent.getValue(), is(equalTo(5.0)));
	error.checkThat(DataUtils.isSameDate(rent.getRentDate(), new Date()), is(true));
	error.checkThat(DataUtils.isSameDate(rent.getReturnDate(), DataUtils.obtainDataInDifferenceInDays(1)), is(true));
}
```
In this test, a user and a movie where initiated and the rent service was mocked.

####Conclusion

This way, it's possible to test if the rent service works without actually using it. That's useful to avoid, for example, unnecessary calls to the data base, just mock the object that make this call.

In case you are interested, here's the repository on GitHub, with more of these mocked tests: https://github.com/pedro-henrique-arruzzo/poc/tree/main/MockTests
How do you organize your css?
Tags: html, css
Published: 2021-06-28 13:41:34

Hello, take a moment and think of how you organize your css code in order to avoid wasting time while debugging your programs. I have been reading about [BEM](http://getbem.com/introduction/) of late which offers a pretty nice way of going about this, as you scale.

I will walk you through a summary of what to expect.

**BEM**
This is like the ideology used to organize the css depending on how your html is structured. I will brake it down below.

**B for Body**
This represents the outer container of any html element. This can be any type of element depending on the context.

**E for Element**
This represents the element being enclosed by the body above.

**M for Modifier**
This represents the actual style appended to the element.

In summary the element that has the actual style is wrapped around its parent element. This simple organization can be applied to different levels of html element nesting and it can be applied to different styles of programming.

In my next post, I will walk you through the details of this ideology with code samples.

Happy coding 😅
Don’t upgrade your npm package versions by accident
Tags: npm, javascript, webdev, devops
Published: 2021-06-28 13:06:27

_Looking for ways to make sure that your deployments to different environments are identical and use the exact same package versions? Or does your company have requirements to be able to reproduce deployments and trace exactly what dependencies were used at a specific time? **Great - continue reading!**_

Being dependent on open source 📦 npm packages means dependencies to the public npm registry and npm package maintainers = constantly changing environment. This also means that you have the responsibility to keep track of what package versions were used in a specific deployment. This is a crucial task to reduce risks and make sure unintended changes have not been made.

Even without any change to package.json your builds may produce a different set of dependencies at different points in time (semver versioning and addition of new minor versions to public registries).

The slightest change in patch versions means your builds are no longer deterministic where you are guaranteed the exact same results - and deploying dependencies that have not been tested is never a good idea...


## So what's the solution?
💡 For me, the way to go is to freeze your registry when you want to avoid accidental updates. Freezing a registry effectively locks down the state of your package versions and makes the registry read-only so that only intended changes are applied to code you trust.

The video below shows the easiest way to make your registry read-only using the [Freeze policy](https://docs.bytesafe.dev/policies/freeze/) in Bytesafe:

{% youtube JdxeDRxvp7M %}

Benefits of using the **Freeze policy** in Bytesafe:

✅ Guaranteed exact same versions when testing and building your applications

✅ Deterministic and consistent results across all your environments such as Test, UAT and Production

🔗 [This blog post](https://bytesafe.dev/posts/freeze-registry-states/) also describes how to work with the [Freeze policy](https://docs.bytesafe.dev/policies/freeze/) to achieve consistent tests and builds.


## What's your solution to this issue?
I would love to hear what you think of this solution and how you avoid accidental updates today. I'd be happy to answer any questions you might have. 


[![Follow Bytesafe on Twitter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j3uehdo8j7i2g40bk382.png)](https://twitter.com/bytesafedev) <a href="https://www.producthunt.com/posts/bytesafe?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-bytesafe" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=300547&theme=light" alt="Bytesafe - A better way to control your software supply chain | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
👥 Secrets Access with Managed Identities in .NET Applications
Tags: security, dotnet, identity
Published: 2021-06-28 13:12:18

#### 📘 How to securely access secrets stored in the #Azure Key Vault service using the new Azure #SDK and managed #identities.

#### <br>
**TL;DR:** Managing secrets and credentials used to secure communication between the different components of a cloud solution can be challenging for developers. This can be simplified with managed identities available in the Microsoft Azure cloud. Let's see how to deal with secrets management in ASP .NET Core applications hosted on the Azure cloud.

## Managing Secrets Securely in the Azure Cloud

Managing secrets in cloud solutions can be a big challenge. Whether it's a database password or a connection string to access a specific service &mdash; these values should be stored securely. In the Microsoft Azure cloud, there is a dedicated service called [Azure Key Vault](https://docs.microsoft.com/en-us/azure/key-vault/general/basic-concepts). It is a cloud service for securely storing and accessing secrets. When thinking about secrets, we should have in mind that they can be in many different forms. A database password is a secret, a certificate is a secret, and a cryptographic key is also considered a secret.

Storing secrets in places like a configuration file can expose our application to vulnerabilities similar to the ones due to bad programming practices or bugs. Many developers struggle with managing secrets properly and looking for a solution to test the application locally without worrying about secrets management after deployment. This is where Azure Key Vault and Azure managed identities can help.

In this article, we will explore how to set up Azure Key Vault, store the secret in it, and access this secret from the ASP .NET Core application using Azure managed identity. We will learn how to combine using secrets locally and access them after the deploying to the Azure cloud.


## What Are Managed Identities for Azure Resources?

[Read more...](https://auth0.com/blog/secrets-access-managed-identities-dotnet/?utm_source=content_synd&utm_medium=sc&utm_campaign=dotnet)
Being a Dev with ADHD
Tags: dev, adhd, programming, life
Published: 2021-06-28 12:52:09

Probably many of you here suffer with the ADHD condition, and many of you here don't. Share this maybe make others feel more comfortable and make you that maybe work with a ADHD colegue or manage a Dev that have it, understand how is our day. 

Live with ADHD is not easy... You feel lost, you forget your tasks, you don't understand what you have to do, you don't find the best solution, your code sucks, you don't want work, you procrastinate, you give up.Yes, it's a mess... And it can even get worse when you work remotely.

Focus is not the only monster that you have to fight when you are a Dev with ADHD. You still have to deal with not understand simple things of the language or framework, even if you try your best, you still don't understand and this can make you feel dumb, even you know you're not and you are a good developer.

The sensation of losing yourself can make you feel like you are an impostor, that you can't do what you do,that everybody is better than you, that you will lose your job and will not achieve your goals in life, and yet, you have to try make others understand that is not all your fault.

Only who have ADHD knows how being alive feels so bad sometimes. It can even lead you to a depressive condition, and you still try, take your pills and go fight for your place on this earth.

Do you have ADHD? 
Do you work with someone that have it? 
Do you manage someone with ADHD? 

Leave in the comments your experience.

"Sorry if I make some English mistake, it's not my native language."
How To Make A Sub And Sub Sub Categories In Django [Most Important]
Tags: django, python, programming, career
Published: 2021-06-28 12:51:44

Hello Devs, in this category I'm gonna teach you how to make categories, sub categories and sub sub categories in django in simple steps. 

Post Link:- https://pythondjangogeek.com/python/how-to-make-a-sub-and-sub-sub-categories-in-django/

Linkedin:- https://www.linkedin.com/in/shivamrohillaa/

```
Github Repo:- https://github.com/ShivamRohilllaa/django-
categories-tree

```

Django Categories

![Screenshot (91)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/itre4946j0iphbz6xr5x.png)
  
Django Sub Categories
 
![Screenshot (91)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0zy2mhh6l4poz4q2r3k7.png)
 
Django Sub sub categories
 
![Screenshot (92)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7yyhktdpin54h9vkmvfq.png)
 
Make a model for Django categories.

```
class Category(models.Model):
    parent = models.ForeignKey('self', related_name='children', on_delete=models.CASCADE, blank = 
    True, null=True)
    title = models.CharField(max_length=100) 
    slug = AutoSlugField(populate_from='title', unique=True, null=False, editable=False)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title

    class Meta:
        #enforcing that there can not be two categories under a parent with same slug
        
        # __str__ method elaborated later in post.  use __unicode__ in place of

        unique_together = ('slug', 'parent',)    
        verbose_name_plural = "categories"     

    def __str__(self):                           
        full_path = [self.title]                  
        k = self.parent
        while k is not None:
            full_path.append(k.title)
            k = k.parent
        return ' -> '.join(full_path[::-1])  
```


Write code in Views.py

```
def home(request):
    catg = Category.objects.filter(parent=None)
    context = {'catg':catg}    
    return render(request, 'index.html', context)
```

Now render everything in your templates

Make an index.html file
And start fetching the details in the HTML file.

![carbon (2)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sk9eqnp2lhlvx2yz0u3h.png)
 
 
Thank you

Shivam Rohilla | Python Developer
Code as Visual Component
Tags: visualcodedesign, visualprogramming, domainspecificlanguage, nocode
Published: 2021-06-28 12:19:21

---
title: Code as Visual Component
published: true
description: Visual Code Design, Visual Programming, Domain Specific Language, NoCode
tags: VisualCodeDesign, VisualProgramming, DomainSpecificLanguage, NoCode
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cidkkd75xouphzejbucm.gif
---

This is the first post of a series to come on Code as Visual Component (NOT Yet Another Visual Programming Language ;)). 

After 2 years of research on DX (Developer's eXperience) I'm now sure of the proof of concept for a new Visual Code Design concept. Personal motivations are :

-  I wanted to keep a dev journal while training on the jobs. I don't want to lose time and write much "literature" and it is not precise enough, I want to "picture" code with all its context. Git versioning is mandatory but as for getting a mental model it's not appealing enough.

- I don't like all the Visual Programming Languages currently : they oblige you to code in a language I have to learn. I want to be able to use all mainstraim and not so mainstream languages (from javascript,...) or frameworks (react,...).

- I want to capitalize on code by creating code as component or block, a bit like in scratch but for adults. I want to be able to create them quickly and visually so I chose figma platform.

- I don't want to use drag & drop, it's not very productive, I want to type instead. I want to be able to use it as a complement or integrate with an IDE to be more productive and have clean code by capitalizing with a code knowledge management system.

- and many more (student and teacher/self-taught to be able to customize and build visual tool and playground thanks to a plugin architecture).

Below is a very simple example of a component to select a node in figma as I'm eating my own dog food as self validation first. But as soon as possible (once I have fixed some pesky details), you'll be able to test also (join more than 1000 subscribers at https://grafcet.online)

Long term I intend to opensource.

{% youtube TOmDwkHLH20 %}
How to Use the Linux Command Line
Tags: linux, bash, ubuntu, beginners
Published: 2021-06-28 10:53:32

[Linux](https://www.linux.org/) is a popular operating system for servers, but it can also be used in other ways. You can install and run Linux on a regular computer, and the process isn't that difficult. Once installed, you can run the Linux command line on that computer even if you don't log in as root (the superuser).

For many people, the Linux command line can be a scary place. It looks different and feels different than what they're used to. But I like to think of it as a tool that allows you to do very specific things, like nothing else can.

![linux terminal using gnome terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kw9vwdy5w1z42sgozgm1.png)

In the Linux command line, you type a command and get output in the same window. There are hundreds of commands and it can take a long time to master them. You can [practice Linux](https://www.practicelinux.com/) and quickly master all the commands online.

The popularity of the Linux operating system, along with the rise of powerful, quad-core computers has made the command line interface (CLI) relevant again.

## GUI vs command line

Whereas once, a mouse was necessary to navigate the user interface, today with GUI interfaces, you typically just use your keyboard to access functionality. 

However, by going back to the command line and using the CLI, you can boost productivity and work more efficiently.

The Linux command line is different from other operating systems and that's why many people avoid it. Instead of worrying about how to use it, focus on what you can do with it. 

Get to know your way around the Linux command line and it will make your time more efficient when working with Linux systems. 

Using the Linux command line not only increases your productivity, but it helps in debugging and troubleshooting issues that may arise.

![linux command line](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2uv4ggr75gnauntqi7f.png)

You can use [commands](https://bsdnerds.org/what-is-linux-shell/) from the Linux command line to navigate files, change permissions, configure services, mount devices and a lot more.

Commands include `ls` (list files), `cd` (change directory), `pwd` (see current directory) and lots and lots more. In fact there are so many commands and programs (bash, vim, ssh, git etc), that without training it can take over a year to master.

Plus on many jobs you are expected to know the command line, to use ssh and more. It's a good skill to have
Implement scroll-to-top in Angular
Tags: angular, rxjs, javascript, webdev
Published: 2021-06-28 12:13:45

@angular/cli: 15.2.8
Source: [GitHub](https://github.com/anirbmuk/angular-scroll-to-top.git)

In this article I would like to talk about an often-used feature on a user-centric application - the scroll-to-top button for allowing a user to quickly scroll to the top of the page, without having to use the mouse. The end result would be something like this:

![preview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q6gwb6bf5ea680k0cl8f.gif)


---
Let's break up this implementation into 3 steps:

:heavy_check_mark: Set up the scroll-to-top button (with some nice styling).
:heavy_check_mark: Determine when the button should be displayed.
:heavy_check_mark: Scroll to the top of the page on clicking the button.


---
#### Set up the scroll-to-top button:

I have used **@angular/material** for some easy styling. In order to display the button fixed to the bottom-right corner of the page (and some nice hover effects with opacity), I have used the below properties on the **:host** -
 
![scroll.component.scss](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7vv30s7a3rr5ka5c916n.JPG)


---
#### Determine when the button should be displayed:

This is an interesting section. To begin with, we need to set up an `Observable` on the scroll event of the **`DOCUMENT`**. You may directly access the document object, or you may use an **`InjectionToken<Document>`**, provided by angular.

This observable starts emitting values as soon as the user starts to scroll up or down. Now we are not really interested in the actual scroll event, but we would like to check something important every time the scroll event is fired - and that is the scroll position. Angular makes this quite simple with the **`ViewportScroller`** service from `@angular/common` package. This service has few useful methods, and I am going to use two of them - **`getScrollPosition`** and **`scrollToPosition`**.


![list.component.ts](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kbbyatuiddlwkyizpyl4.JPG)

The `getScrollPosition` method returns an array of 2 numbers - the X and Y coordinate. I check if the Y coordinate is more than 0 (which means the user has scrolled down) and I enable the scroll-to-top button.


---
#### Scroll to the top of the page on clicking the button:

For this last part, I make use of the `scrollToPosition` method, which again takes in the X and Y coordinates, and I scroll to [0, 0].

![list.component.ts](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9j39rwkjw902r72yphql.JPG)

---
#### UPDATE  

> The source code has been updated to **angular 15**, with _standalone components_. The [main](https://github.com/anirbmuk/angular-scroll-to-top) branch contains the updated syntax of angular 15. Refer to the [legacy](https://github.com/anirbmuk/angular-scroll-to-top/tree/legacy) branch to view the old syntax of **angular 13**.

Cheers :-)
[Anirban Mukherjee](https://anirbmuk.appspot.com/en)