teleren/devto huggingface dataset:
How to Commit like a Boss
Tags: tutorial, beginners, productivity, github
Published: 2022-01-15 12:39:03

## What's Committing anyways?

Well committing in here refers to staging up the changes that you make in your local machine and far from this pushing it to the branch where other teammates can get themselves update with what you've done in project.

## Why is it to learn committing, can't you commit just right away?

No, talking about myself I generally work on different projects almost daily. And which lead to change in programming environment.
By this I mean like if you're working on some project and commits some changes with some message that might not be very descriptive and you switch to some other work.

When you return back to the older project to work on it again, you might need to get familiar with what you did last time and what changes have already been made by your teammates(if you have any :P) before you actually start to work.

This leads to confusion and reduced in degree of DRY rule.

## The right way to commit/communication

**Commenting as you work**

When you're doing some work on a project make sure you place comments on what these lines of code do. This slowly but surely increases the productivity of you and your team when they return to work, as it reminds the programmer about things rather than understanding them him/herself.

**Writing less but more**
Writing a message during your commit gives idea about what this commit does and contributes to. So, giving a write message counts +1 towards productivity.

## What not to do

**Don't commit after every changes**

It's recommended that you commit once you're sure you'd commit your work. Completing a section of work and doing commits in order always benefits.

**Don't write weird and non-sense messages**

Committing a small yet informative message is necessary. It doesn't have to be a whole novel.

```
git commit -m "today i changed some theme colors and added few of mine because your colors suck I fkin hated them so i got rid of them. Apart from this I also added a Palette section it's was a hell lot of work i better get a raise :P"
```
Instead
```
git commit -m "added Palette section & few theme changes"
```
_Hope you find this informative._
Cody Rigsby Net worth 2022 : Income, Career, Wiki, Lifestyle , Bio 
Published: 2022-01-15 12:17:40

Cody Rigsby net worth is estimated to be $4 million in 2022. He is a fitness instructor, dancer, social media star, and entrepreneur from the United States.

Cody Rigsby is well-known for his work at Peloton as a fitness instructor. He is one of America’s most notable fitness instructors, and he is known for giving inspirational fitness and lifestyle tips on social media sites like Instagram. On Instagram, he has over 900,000 followers.

Apart from Instagram, Cody Rigsby is also well-known on other social media platforms, such as Tiktok, with over 150k followers, making him a million-plus fan.

So, let’s quickly go through Cody Rigsby’s complete net worth, income, monthly salary, earnings, assets, luxury lifestyle, career, biography, incredible automobile collections, multiple brand organizations, biography, [and more](https://usatoptechnews.com/cody-rigsby-net-worth/).
Striver's SDE Sheet Journey - #14 Pow(x,n)
Tags: programming, beginners, java, computerscience
Published: 2022-01-15 12:15:56

> **<u>Problem Statement</u> :-**

_Given a double x and integer n, calculate x raised to power n. Basically Implement pow(x, n)._

> Example


**Input** :  `x = 2.00000, n = 10`

**Result** : `1024.00000`

##  <u>Solution 1</u>
_The simple approach to find `pow(x,n)` is to initialize a variable `ans` and run a loop from `1` to `n`, keep multiplying `x` with `ans`._

**step-1** Initialise a variable `ans = 1.0`.

**step-2** run a loop from `1` to `n`.
 > **1.** `ans = ans * x`

**step-3** if exponent `n` < `0` then return `1 / ans`.

**step-4** return `ans`.


## Java

```java
class Solution {
    public double myPow(double x, int n) {
        double ans = 1.0;
        
         for(int i=0; i<Math.abs(n); i++){
               ans = ans * x;
            }
        if(n < 0){
           ans = 1 / ans; 
        }
        
        return ans;
    }
}
```
**Time Complexity** : _O(n)_
**Space Complexity** : _O(1)_

##  <u>Solution 2</u>
_this problem can be solved by the **Divide & Conquer** technique.
so what we are going to do in this approach, we recursively reduce the exponent `N` by half and compute them individually._

let's understand this approach with an example.

`x = 2 `, `n = 12`

in this example, we need to find `2^12` 

reduce exponent `N` by half.

**1.** 2^12 ----> 2^6 * 2^6

**2.** 2^6 -----> 2^3 * 2^3

**3.** 2^3 -----> 2 * 2^1 * 2^1

**4.** 2^1 -----> 2 * 2^0 * 2^0

**5.** 2^0 -----> 1

now, we know that `2^0` is `1` then,

**4.** 2^1 -----> 2 * 2^0 * 2^0
       2^1 -----> 2 * 1 * 1

**3.** 2^3 -----> 2 * 2^1 * 2^1
       2^3 -----> 2 * 2 * 2
       2^3 -----> 8

**2.** 2^6 -----> 2^3 * 2^3
       2^6 -----> 8 * 8
       2^6 -----> 64

**1.** 2^12 ----> 2^6 * 2^6
       2^12 ----> 64 * 64
       2^12 ----> 4096

see the java implementation.

## Java

```java
class Solution {
    public double myPow(double x, int n) {
        double ans = pow(x,n);
        
        if(n < 0) ans = 1.0 / ans;
        
        return ans;
    }
    
    private double pow(double x,int n){
        
       if (n==0)  return 1;
        
        double ans = pow(x,n/2);
        
        if((n&1) == 1){
            
            return x * ans * ans;
            
        }else{
            
            return ans*ans;
        } 
    }
}
```

**Time Complexity** : _O(logn)_
**Space Complexity** : _O(logn) for recursion stack_

---

Thank you for reading this article. save it for future use.
Kubernetes Cluster on AWS using Kops running on Docker Desktop - QuickStart Guide
Published: 2022-01-15 11:57:19

## Pre-requisites:

- Install Docker Desktop
- Install AWS CLI using Homebrew
- Create an AWS Account if you are first time user.
- Run the below command to install kops on your macOS.

```
brew update && brew install kops
```

## Adding Access & Secret Key 


```
aws configure
```

This will store your credential under ~/.aws/credentials


```
bucket_name=collabstore
```


## Create a AWS Bucket
```
[Captains-Bay]🚩 >  baws s3api create-bucket --bucket ${bucket_name} --region us-east-1
{
    "Location": "/collabstore"
}
```

## Configure

```
aws s3api put-bucket-versioning --bucket ${bucket_name} --versioning-configuration Status=Enabled
```


## Configure DNS Name

```
 aws route53 create-hosted-zone --name collabnix.com --caller-reference 2
 
```

```
export KOPS_CLUSTER_NAME=ajeet.k8s.local
```

## Export Cluster Name


```
export KOPS_CLUSTER_NAME=ajeet.k8s.local
```

## Exporting Kops State Store

```
[Captains-Bay]🚩 >  export KOPS_STATE_STORE=s3://${bucket_name}
```



```
[Captains-Bay]🚩 >  kops create cluster \
> --node-count=2 \
> --node-size=t2.medium \
> --zones=us-east-1a \
> --name=${KOPS_CLUSTER_NAME}
...

Must specify --yes to apply changes

Cluster configuration has been created.

Suggestions:
 * list clusters with: kops get cluster
 * edit this cluster with: kops edit cluster k8.aws.dev.collabnix.com
 * edit your node instance group: kops edit ig --name=ajeet.k8s.local nodes
 * edit your master instance group: kops edit ig --name=ajeet.k8s.local master-us-east-1a

Finally configure your cluster with: kops update cluster ajeet.k8s.local --yes

[Captains-Bay]🚩 >
```


```
[Captains-Bay]🚩 >  kops get cluster
NAME		CLOUD	ZONES
ajeet.k8s.local	aws	us-east-1a
[Captains-Bay]🚩 >
```


## Deploy Kubernetes

```
kops update cluster --name ${KOPS_CLUSTER_NAME} --yes
```


```
kops get cluster
NAME				CLOUD	ZONES
ajeet.k8s.local	aws	us-east-1a

```


```
[Captains-Bay]🚩 >  kops update cluster --name ${KOPS_CLUSTER_NAME} --yes
I0531 07:01:41.613598    1366 apply_cluster.go:456] Gossip DNS: skipping DNS validation
I0531 07:01:44.786395    1366 executor.go:91] Tasks: 0 done / 77 total; 30 can run
I0531 07:01:46.893202    1366 executor.go:91] Tasks: 30 done / 77 total; 24 can run
I0531 07:01:49.007022    1366 executor.go:91] Tasks: 54 done / 77 total; 19 can run
I0531 07:01:51.649219    1366 executor.go:91] Tasks: 73 done / 77 total; 3 can run
I0531 07:01:53.079596    1366 executor.go:91] Tasks: 76 done / 77 total; 1 can run
I0531 07:01:53.440746    1366 executor.go:91] Tasks: 77 done / 77 total; 0 can run
I0531 07:01:54.102339    1366 update_cluster.go:291] Exporting kubecfg for cluster
kops has set your kubectl context to ajeet.k8s.local

Cluster changes have been applied to the cloud.


Changes may require instances to restart: kops rolling-update cluster

[Captains-Bay]🚩 >
```

Now you can see K8s cluster under Context UI.
Testing file Download ⬇️ in Spring 🍃 Boot
Tags: java, kotlin, programming, webdev
Published: 2022-01-15 11:46:41

It's pretty common case to generate file on the backend and let user to download it. But how to test it? I found testing of this scenario not quite well documented. So here's my bit.

We have to use `getAsyncResult` method from `MvcResult` interface, which enables us to retrieve content provided using `StreamingResponseBody`. So first, let's look how to generate file in the controller.

I am going to use Kotlin btw. 😎

## Streaming body with `StreamingResponseBody`
Let's say we want to enable user to download some fine, which is not very small. For the demo I will just generate a text file containing a lot of `a` characters. 
```kotlin
@Controller
@RequestMapping(value = ["/api/v1/03/get-file"])
class FileProducingController {
    @GetMapping(value = [""], produces = ["application/text"])
    fun export(): ResponseEntity<StreamingResponseBody> {

        return ResponseEntity
                .ok()
                // set a filename
                .header(
                        "Content-Disposition",
                        """attachment; filename="%file.txt""""
                )
                .body(
                        // stream the body
                        StreamingResponseBody { out: OutputStream ->
                            val text = "a".repeat(1000000)
                            out.write(text.toByteArray())
                            out.close()
                        }
                )
    }
}
```
So what I am doing here is that I am setting the file name, which is the default when user downloads it in a browser. And then I am writing the text to the StreamResponseBody's output.

## Finally the testing part
So when I want to test it I have to do this.
```kotlin
@SpringBootTest
@AutoConfigureMockMvc
internal class FileProducingControllerTest {
    @field:Autowired
    lateinit var mvc: MockMvc

    @Test
    fun `produces correct body`() {
        val result = mvc.perform(
                MockMvcRequestBuilders.get("/api/v1/03/get-file")
        )
                .andDo { it.asyncResult }
                .andReturn()
        val content = result.response.contentAsString
        assertEquals("a".repeat(1000000), content)
    }
}
```
Notice the part with `it.asyncResult`. Without this part the test would fail. There will be just part of the output in the response's `contentAsString` result, because it won't wait for the stream to end. You can try this by removing the part and see it fails.

---

Tolgee is an open-source solution for software localization. It saves developer's time. Go to [Tolgee.io](https://tolgee.io) and have fun!

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/idu23asnj6dsz885l25x.jpeg)
VALUES in Microsoft Transact-SQL
Tags: programming, database, mssql
Published: 2022-01-15 07:34:51

---
title: VALUES in Microsoft Transact-SQL
published: true
date: 2022-01-15 07:33:42 UTC
tags: programming,database,mssql
canonical_url: https://siderite.dev/blog/values-in-microsoft-transact-sql/
---

Original post at: https://siderite.dev/blog/values-in-microsoft-transact-sql

  This blog post is about [Table Value Constructors](https://docs.microsoft.com/en-us/sql/t-sql/queries/table-value-constructor-transact-sql "Table Value Constructor (Transact-SQL)") or Row Constructors. While they make intuitive sense and this is how I will present them, they were introduced in Microsoft Sql Server 2008 and because they look like another very old feature, most database developers are not aware of them.

  So let's begin with a simple INSERT statement:

```
CREATE TABLE Position(X INT, Y INT)

INSERT INTO Position
VALUES (1,1),(1,2),(NULL,NULL),(2,1)
```

So we create a table and we insert some data using the VALUES expression. This is equivalent to

```
CREATE TABLE Position(X INT, Y INT)

INSERT INTO Position
SELECT 1,1
UNION ALL
SELECT 1,2
UNION ALL
SELECT NULL,NULL
UNION ALL
SELECT 2,1
```

I've certainly used this SELECT + UNION ALL construct to generate static data in my SQL statements. Sometimes, because it's such an annoying syntax, I've created a table or table variable and then inserted values into it in order to use data in a structured way. But could we use the VALUES expression in other contexts, not just for INSERT statements? And the answer is: Yes! (in Sql Server 2008 or newer)

Here is an example:

```
SELECT *
FROM (VALUES(1,1),(1,2),(NULL,NULL),(2,1)) as Position(X,Y)
```

This is not a disk table, nor is it a table variable, but an expression that will be treated as a table with columns X and Y, of type INT. As in a SELECT/UNION ALL construct, the type of the columns will be determined by the first set of values.

You can see a "real life" example in my previous post on how to [solve Sudoku using an SQL](https://siderite.dev/blog/using-cte-to-solve-sudoku-in-sql/ "Using Common Table Expressions to solve Sudoku in Microsoft SQL Server") statement.

Now, while I've explained how to remember the syntax and purpose of Table Value Constructors, there are differences between the VALUES expression used as a TVC and when used in an INSERT statement.

In an INSERT statement, VALUES is just a way to specify data to add and has been there since the beginning of SQL and therefore is subject to constraints from that era. For example, you cannot add more than 1000 rows in an INSERT/VALUES construct. But you can using an INSERT/SELECT/VALUES construct:

```
INSERT INTO Positions
VALUES (1,2),
       (1,1),
       -- ... more than 1000 records
       (0,1)

-- Error 10738 is returned

INSERT INTO Positions
SELECT x,y FROM (
VALUES (1,2),
       (1,1),
       -- ... more than 1000 records
       (0,1)
) as P(x,y)

-- Works like a charm
```

Hope it helps!
Manage Local State with Apollo V3
Tags: react, webdev, javascript, programming
Published: 2022-01-15 11:05:45

Howdy everyone, In this article,I will show how I removed redux from my project and managed state with Apollo Version .

I will try to show u just the difference  between **redux vs apollo **, for design check the first post.

For the project with state managed with Redux check my previous post.
_link here:_ https://dev.to/aom19/new-project-3afh

Project Repository: https://github.com/aom19/rentCar/tree/main/apollo-version


## Apollo Version 3
   Apollo Client is a comprehensive state management library for JavaScript that enables you to manage both local and remote data with GraphQL. Use it to fetch, cache, and modify application data, all while automatically updating your UI.

## Project Structure
![Project Structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1i6yld5r1yv7n8xrdans.png)
 

### Frontend
![Frontend Structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qapmb2vump6kaxtdhp7p.png)
 1.Setup
![Install Apollo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b21nxd15imnnf5l7o0lk.png)
 
 2.Initialize ApolloClient

![Initialize ApolloClient](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vm8c75igowivcepamiz5.png)

3.Create Mutations and Queries
![Mutations Queries](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p19sehmi9c4r9ref7yjb.png)
 
 
![Mutations](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dpforsuctqcgtd2naz0y.png)

4.Import _useQuery & useMutation_
![Import](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dnzs5e1a1xd13uugpqzp.png)

5.Simplest way to use a Mutation. 
![use a Mutation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ppm5zwmqm8uw0wb2bsqm.png)
 but this type of mutation won't provide immediately changes on the screen , it will just store that car booked. 
 for this one, I start update the cache directly rewriting this .
![Update cache](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9axd2y62kmvmfg3004fo.png)
Read-Only Access to specific resources in AWS EKS Cluster via EKS Authentication & Authorization
Tags: aws, kubernetes, security
Published: 2022-01-15 11:04:13

Hi, Folks.
Our objective for today is stated on the blog post header, let's get started.

<h2>Authorization in EKS Cluster using RBAC(Role Based Access Control)</h2>

1. Create a <b>manifest for ClusterRole or Role</b> as required in your use case. (ClusterRole is implied across all namespaces, Role is for specific namespace, we shall be using ClusterRole in this use-case as we need to access resources across different namespaces).

<br><a href="https://raw.githubusercontent.com/RajitPaul11/AmazonEKS/master/RBAC/ReadonlyClusterRole.yaml">Sample ClusterRole.yaml (Read only pods & pod/logs)</a> <br>

<br>
2. Create a <b>manifest for ClusterRoleBinding or RoleBinding</b> as required. 

<br><a href="https://raw.githubusercontent.com/RajitPaul11/AmazonEKS/master/RBAC/ReadonlyClusterRoleBinding.yaml">Sample ClusterRoleBinding.yaml</a><br>

<br>3. Apply the ClusterRole and then the ClusterRole Binding.
   <br>(kubectl apply -f ClusterRole.yaml)
   <br>(kubectl apply -f ClusterRoleBinding.yaml)<br>

<br>4. Please Note the groupname from ClusterRoleBinding we shall be requiring it while mapping the user during authentication.<br>

<br><h2>EKS Authentication using AWS IAM.</h2>
1. Create an AWS IAM User with Programmatic Access.<br>
2. Create an IAM policy with EKS Read-Only Permission and assign it to the IAM user.<br>
3. Download the IAM User creds, copy the IAM username and IAM user ARN.<br>
4. Go to aws-auth configmap in kube-system namespace.
 
<br>(kubectl edit cm aws-auth -n kube-system)

<br>5. Enter the userARN, username and groupname in mapUsers section in aws-auth configmap.

<br><a href="https://raw.githubusercontent.com/RajitPaul11/AmazonEKS/master/RBAC/sample-map-users.yaml">Sample mapUsers syntax</a>
<br>

<h2>Setup local access to our EKS Cluster and test the permissions.</h2>

<br>1. Install AWS CLI Latest Version locally (https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html). <br>
2. Install Kubectl latest version (https://kubernetes.io/docs/tasks/tools/). <br>
3. Configure AWS-CLI with the previously created IAM user creds (aws configure) <br>
4. Run after configuring aws-cli: aws eks update-kubeconfig --name Eksclustername <br>
5. Next, run following commands to test permission: <br>
 
<br>kubectl auth can-i create pods (Answer should be no) <br>

<br> kubectl auth can-i delete pods (Answer should be no) <br>

<br> kubectl auth can-i list pods (Answer should be yes) <br>

<br> kubectl auth can-i list pods/log (Answer should be yes) <br>
 
<br>Accordingly you can check with differnt resources and verbs, we should only be receiving yes for readonly verbs for pods and pods/log resources.

<br>If you face any issues or have any queries you can connect with me on Linkedin(https://www.linkedin.com/in/rajitpaul/).
Cheers!
JavaScript program to find Unique elements from an array
Tags: javascript, array, programming, html
Published: 2022-01-15 10:53:41

## Following are the 2 ways to find distinct or unique elements from an array

- _Using ES6 new Set_


`var array = [3,7,5,3,2,5,2,7];
var unique_array = [...new Set(array)];
console.log(unique_array);    // output = [3,7,5,2]`

- _Using For Loop_

`var array = [3,7,5,3,2,5,2,7];
for(var i=0;i<array.length;i++)
{
for(var j=i+1;j<array.length;j++)
{
if(array[i]===array[j])
{
array.splice(j,1);
}
}
}
console.log(array); // output = [3,7,5,2]`
The Map Function in JavaScript
Tags: javascript, webdev, beginners, programming
Published: 2022-01-15 10:42:34

Hi guys !.

In this post we will learn how to use the Map Function in JavaScript. This particular function is very useful because not only can you map an array of objects, but also map elements.

>[Check out my Blog too](https://salehmubashar.com/)

-----------------------------------------------------------------

## What is map() ?

In simple terms, the map function calls a function once for each element in an array. Basically, it iterates over each element or item in an array and creates a new array based on what is returned by the function.

## What is it used for?

It is commonly used when you want to take an array, make some changes on the items or apply a function on it, and get a new array.
The basic syntax is :

```javascript
map((element, index, array) => {
   //return something
})
```

#### Example 1

Lets look at the example below. We have a simple array that we are going to display on the console.

```javascript
const array = [3,1,15,1,5,3,23]
//map the array
array.map((el) =>{
    console.log(el)
})
```
We are using ES6 arrow functions instead of the traditional return function.
This will give the following output:

![Example 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b4qb5v3s865609p2skoy.png)

#### Example 2
 
Now let's look at a more useful example. Here we have an array of objects, and we want to return only the names.

```javascript
const users = [
  { firstName: "john", lastName: "doe" },
  { firstName: "Daniel", lastName: "steve" },
  { firstName: "mike", lastName: "hoff" },
];
//map the array and display only first names
users.map((el) => {
  console.log(el.firstName);
});
```

This will give the following result:

![Example 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1bvjfb5rr3bpse167qty.png)

## Mapping and Array to Elements

The most useful application of the map function is when you want to display HTML elements using an array. 
In this case, we have an array of objects containing some user information and we want to display a the content as a list
We will create an empty unordered list so that we can append the items to it.

```html
<ul>
</ul>
```
Here we will map over the array and display the names as a list.

```javascript
const users = [
  {
    name: "James",
    age: "17",
  },
  {
    name: "Ali",
    age: "19",
  },
  {
    name: "John",
    age: "21",
  },
];
//get the list
var list = document.querySelector("ul");

//display the names as a list
list.innerHTML = users
  .map((el) => {
    return "<li>" + el.name + "</li>";
  })
  .join("");
```
 
The join() method returns a new string by concatenating all of the elements in an array.

Your output will be :
![List](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jqw3vuejc8crh9kpr0xl.png)

----

>[Check out my recent hubpages tutorial](https://discover.hubpages.com/technology/Animated-Accordion-with-React-JS).

Thank you for Reading!