teleren/devto huggingface dataset:
How to install Terraform on AWS CloudShell
Tags: aws, cloudshell, terraform
Published: 2022-08-26 17:23:09

---
title: How to install Terraform on AWS CloudShell
published: true
date: 2022-07-14 19:05:17 UTC
tags: aws, cloudshell, terraform
canonical_url: 
---

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

Before the announcement of AWS CloudShell at re:Invent 2020, we had Instance Connect, Cloud9, and EC2 servers that helped us manage our infrastructure on AWS. However, each of those demands the operation of an EC2 instance, which is expensive. With no personal API keys, using federated identities is considerably more problematic. With the announcement of AWS CloudShell, a browser-based shell that makes managing your AWS environment through the command line an absolute breeze.

AWS Using CloudShell, you can securely manage, explore, and interact with your AWS resources from a browser. When you log into your console, CloudShell authenticates you, So you don't need to worry about Access Key / Secret Key. CloudShell can be accessed directly from your browser and is free of charge.

Although some tools like git and aws-cli were preinstalled on AWS CloudShell, terraform was not, and that is what we are here to solve today. Let's get started without further ado.

Step 1: Initialize your cloud Shell Environment To check if your AWS CloudShell is available in your region, look for a shell icon in the top bar. Check out the image below. ![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1657801210343/pqwxmG7_q.png)If you can't find the icon, it means AWS cloudShell is not available in that region yet.

Click on the icon or click [here](https://eu-west-1.console.aws.amazon.com/cloudshell) to access the shell.

Step 2: Install Terraform We'll make use of tfenv, Terraform version manager. It allows us to install and switch between multiple versions of Terraform.

Clone tfenv by running this command :

```
git clone https://github.com/tfutils/tfenv.git ~/.tfenv


mkdir ~/bin

```

Make sysmlink for `tfenv/bin/*` scripts into a path `~/bin` because it has already added to `$PATH`

```
ln -s ~/.tfenv/bin/* ~/bin/

```

Install Terraform with `tfenv`. As of this moment the latest, the latest terraform is v.12.5

```
tfenv install 1.2.5

```

Tell `tfenv` to use the installed version

```
tfenv use 1.2.5

```

To check if everything is set, we can check for the terraform version with

```
terraform --version

```

The output should look like the screenshot below if everything goes well.

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

### Conclusion

We've seen how to use Terraform Version Manager to install Terraform on AWS CloudShell. We've also seen how AWS CloudShell can help you avoid using an Access Key / Secret Access Key because CloudShell is already authenticated with your console credentials.

PS: installing code outside of `$HOME` as it will not persist across sessions.

Thank you for reading, and remember to sign up for my newsletter to be the first to learn when I publish a new piece.

Peace :love:
My portofolio project
Tags: javascript, webdev, career, discuss
Published: 2022-07-14 18:44:05

In the past few months I've been creating projects and learning about DS and Algorithms to apply for an internship in a company but I don't know if my portfolio is good.
I hope that you guys could help me with a review or some feedback to improve it.
I'm not feeling ready for the interviews but I know that I keep this mindset I will never get what I want.

[Click here to watch it](https://www.josafath.com/)
Using AWS Incident Manager to implement support tickets on our website
Tags: aws, programming, go
Published: 2022-07-14 18:23:30

I wrote [a blog](https://www.dolthub.com/blog/2022-07-13-hosted-dolt-incident-manager/) about how we used AWS Incident Manager to implement a support ticket system on our website. Also compares some alternatives to AWS (PagerDuty and Splunk On-Call). Let me know what you think!

Here it is: https://www.dolthub.com/blog/2022-07-13-hosted-dolt-incident-manager/
Future React Components: ES2022
Tags: react, es2022, javascript
Published: 2022-07-14 17:41:00

Hi, here's an **accessible checkbox**, which is probably the web's 1st React Component, created using ES2022.

Here the state is a **private instance variable**.  Private instance variables, prefixed with `#`, are supported in **ES2022**.  

```javascript
class Checkbox extends React.Component {

        #state = {checked: false};

        handleClick=(evt)=>{
            this.setState((state)=>
                ({checked: !state.checked})
            );
        }

        handleKeyDown=(evt)=>{
            if([' ','Enter'].includes(evt.key)) {
                this.handleClick();
            }
        }

        render() {
            return <div className="checkbox" 
                id={this.props.id} 
                role="checkbox" 
                aria-checked={this.state.checked} 
                aria-disabled={this.props.disabled} 
                onClick={this.handleClick} 
                onKeyDown={this.handleKeyDown} 
                tabIndex={!this.props.disabled? "0":null}>
                    {this.state.checked ? "✓":""}
            </div>
        }

    }
```

Unfortunately the latest **Babel** version (7.0.0-beta.3), does not support it yet (14 July 2022). We'll have to wait, before using it with JSX.

If you don't like creating components using the `class` keyword, here's another article that shows how to create class compomnents without it. (Internet Explorer 11 compatible) {% embed https://dev.to/citronbrick/es5-class-based-react-components-14jf %}
Raspberry Pi. Connect to hidden WiFi
Tags: raspberrypi, wifi, tutorial
Published: 2022-07-14 18:15:57

A few days ago I faced a weird issue with connecting my Raspberry Pi to my WiFi after changing some settings on my router.
I spent a few hours before I realized that the cause of the problem is in that I disabled broadcast SSID. Therefore all others devices connect to a hidden network without any issues.

I have started to find out about the way of connecting to WiFi using CLI.

The first thing that I learn is that the connection config is stored in the file:
`/etc/wpa_supplicant/wpa_supplicant.conf`

My file when I use broadcast SSID on the router:

```
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=HR

network={
    ssid="MyWiFi"
    psk="123456"
    key_mgmt=WPA-PSK
}
```

And I didn't have any issues with this config before disabled broadcast SSID on my router.

After spending some reading forums I found one parameter that was missed in my config:

`scan_ssid=1`

After updating my config (In addition, I removed `country=HR`), Raspberry connected to the WiFi after rebooting.

Now my wpa_supplicant.conf looks:

```
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    scan_ssid=1
    ssid="MyWiFi"
    psk="123456"
    key_mgmt=WPA-PSK
}
```

I hope this simple solution will help someone save time during configuring WiFi.
Life After Github?
Tags: git, github, opensource, tutorial
Published: 2022-07-14 18:11:07

> [Cover Photo (cropped)](https://unsplash.com/photos/60G1nFGkzEo) by [Vinay Tryambake](https://unsplash.com/@winayy_999)

---

In my last post I decided I would leave GitHub for freer libre pastures.

I plan to work on federation, distributing the code to multiple hosts that align better with the ideals of free (libre) open source software.  For awhile I'll continue to federate to GitHub, but I'm not sure how long it will last.  GitHub's Copilot product is toxic to open source.

But before all that I have to pick the first host to move projects to, and that will be SourceHut.

I've been reading the blog of the founder, and his views on many things, but particularly on [open source tools](https://drewdevault.com/2022/03/29/free-software-free-infrastructure.html) and development, are the same as mine.

Given that I have an opportunity to rebuild my online coding persona, I want to do it carefully.

# Rebrand myself

First I have long used what I consider an enterprisey handle on platforms related to code: `pboling`.  In my rebirth, I am `galtzo`, the handle I have long used on non-coding platforms.  It is Mongolian for "crazy".  Given that sanity is concerned with the viewpoint of the majority, in many ways I am "crazy".  The highest compliment I can receive is that of an "iconoclast", which necessarily pits me against any who hold tightly to sacred icons, whether that be $$$, irrational dogmas, or anything else that is unnaturally holy.

# New ideas

I am going to look ever more earnestly into new technologies, well beyond the scope of what I have done in the past.

Things I want to discover:

* Low tech alternatives
* Local-first computing
* Gemini protocol
* Hypercore P2P protocol
* Distributed and Federated resources of the Fediverse

# Steps

1. Create a new email address, to use exclusively for my FLOSS (Free Libre Open Source Software) efforts: `floss@galtzo.com`
2. Create a new PGP key for the new email address, and use it to register my new SourceHut account.
3. Pay for SourceHut.  Supporting independent FLOSS tools is important.
4. Import a library from GitHub... (which one first?)

This post will be updated as I build out.

## UPDATE!!

Because it is so simple, I am first migrating some major projects to GitLab, and I'll do SourceHut once those migrations are complete.  On GitLab I already had an account, and will continue with the same old handle there, `pboling`. 
 Distributed source code is great!  I did pay for SourceHut, even though I haven't used it much yet.
Delete and Destroy
Tags: rails, webdev, beginners, programming
Published: 2022-07-14 17:57:39

The simplest breakdown: destroy runs any callbacks and delete doesn't. What all does that mean though? Why are there two different functions? When do you implement them? How do you know when to implement the different functions?  Does it really matter??

Well. The answer to all of those questions is incredibly nuanced once you really get into it. But the answer to the most important one of "does it matter?" is Yes. It really does. Lets start with delete.

**What does delete do?**
In the most basic terms I can possibly write, delete just removes the selected SQL row and then returns the number of rows deleted. There is no behind the scenes. You just remove the data from the database. 

Now... **What does destroy do?**
Destroy, on top of removing the selected SQL row fires off all of the callbacks and filters before the object(s) is deleted and it also removes the specific ID(s) from the table. It essentially creates a new object from the attributes and then calls destroy on it.

While destroy is less efficient than delete *because* it fires off callbacks and filters, such things are necessary in certain instances because all of those methods being called allows for cleanup methods to work their magic. 

Even though it seems like it it would make more sense to use destroy all the time, you can and should use delete if you want your object to be removed more quickly buuuut, you should absolutely use destroy if you care about your validations and your callbacks. It might run slower but it will make things easier for you in the long run. Like everything with code use common sense and ask questions! There is no one right answer to anything!
Problems Starting Spring Boot Application
Tags: springboot, security
Published: 2022-07-14 12:00:49

I'm trying to configure Token authentication in Spring Boot 2.7.1 with the following setting:

```
@Configuration
@RequiredArgsConstructor
@EnableWebSecurity
public class SecurityConfig {
	@Autowired
	private UserService userService;

	@Autowired
	private AuthEntryPointJwt unauthorizedHandler;

	@Bean
	AuthTokenFilter authenticationJwtTokenFilter() {
		return new AuthTokenFilter();
	}

	@Bean
	UserDetailsService userDetailsService() {
		return userService;
	}

	@Bean
	AuthenticationManager authenticationManager(AuthenticationManagerBuilder builder, PasswordEncoder encoder)
			throws Exception {
		return builder.userDetailsService(userService).passwordEncoder(encoder).and().build();
	}

	public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
		http.cors().and().csrf().disable().exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
				.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authorizeRequests()
				.antMatchers("/api/v1/auth/**").permitAll().antMatchers("/api/v1/test/**").permitAll().anyRequest()
				.authenticated();

		http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);

		return http.build();
	}

}
```
But when I start the application, you are getting the following error:

> org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': **Unsatisfied dependency expressed through method 'setFilterChains' parameter 0**; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'defaultSecurityFilterChain' defined in class path resource [org/springframework/boot/autoconfigure/security/servlet/SpringBootWebSecurityConfiguration$SecurityFilterChainConfiguration.class]: Unsatisfied dependency expressed through method 'defaultSecurityFilterChain' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.HttpSecurityConfiguration.httpSecurity' defined in class path resource [org/springframework/security/config/annotation/web/configuration/HttpSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.config.annotation.web.builders.HttpSecurity]: Factory method 'httpSecurity' threw exception; nested exception is java.lang.IllegalStateException: Cannot apply org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration$EnableGlobalAuthenticationAutowiredConfigurer@194e1965 **to already built object**
30. Leetcode Solution in Cpp
Published: 2022-07-14 17:13:56

```
class Solution {
 public:
  vector<int> findSubstring(string s, vector<string>& words) {
    if (s.empty() || words.empty())
      return {};

    const int k = words.size();
    const int n = words[0].length();
    vector<int> ans;
    unordered_map<string, int> count;

    for (const string& word : words)
      ++count[word];

    for (int i = 0; i < s.length() - k * n + 1; ++i) {
      unordered_map<string, int> seen;
      int j;
      for (j = 0; j < k; ++j) {
        const string& word = s.substr(i + j * n, n);
        if (++seen[word] > count[word])
          break;
      }
      if (j == k)
        ans.push_back(i);
    }

    return ans;
  }
};
```

#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/substring-with-concatenation-of-all-words/
10. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 17:13:06

```
class Solution {
 public:
  bool isMatch(string s, string p) {
    const int m = s.length();
    const int n = p.length();
    // dp[i][j] := true if s[0..i) matches p[0..j)
    vector<vector<bool>> dp(m + 1, vector<bool>(n + 1));
    dp[0][0] = true;

    auto isMatch = [&](int i, int j) -> bool {
      return j >= 0 && p[j] == '.' || s[i] == p[j];
    };

    for (int j = 0; j < p.length(); ++j)
      if (p[j] == '*' && dp[0][j - 1])
        dp[0][j + 1] = true;

    for (int i = 0; i < m; ++i)
      for (int j = 0; j < n; ++j)
        if (p[j] == '*') {
          const bool noRepeat = dp[i + 1][j - 1];  // min index of '*' is 1
          const bool doRepeat = isMatch(i, j - 1) && dp[i][j + 1];
          dp[i + 1][j + 1] = noRepeat || doRepeat;
        } else if (isMatch(i, j)) {
          dp[i + 1][j + 1] = dp[i][j];
        }

    return dp[m][n];
  }
};
```
#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/regular-expression-matching/
8. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 17:12:20

```
class Solution {
 public:
  int myAtoi(string s) {
    trim(s);
    if (s.empty())
      return 0;

    const int sign = s[0] == '-' ? -1 : 1;
    if (s[0] == '+' || s[0] == '-')
      s = s.substr(1);

    long num = 0;

    for (const char c : s) {
      if (!isdigit(c))
        break;
      num = num * 10 + (c - '0');
      if (sign * num < INT_MIN)
        return INT_MIN;
      if (sign * num > INT_MAX)
        return INT_MAX;
    }

    return sign * num;
  }

 private:
  void trim(string& s) {
    s.erase(0, s.find_first_not_of(' '));
    s.erase(s.find_last_not_of(' ') + 1);
  }
};
```


#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/string-to-integer-atoi/
7. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 17:11:17

```
class Solution {
 public:
  int reverse(int x) {
    long ans = 0;

    while (x) {
      ans = ans * 10 + x % 10;
      x /= 10;
    }

    return (ans < INT_MIN || ans > INT_MAX) ? 0 : ans;
  }
};
```

#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/reverse-integer/
6. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 17:10:33

```
class Solution {
 public:
  string convert(string s, int numRows) {
    string ans;
    vector<vector<char>> rows(numRows);
    int k = 0;
    int direction = (numRows == 1) - 1;

    for (const char c : s) {
      rows[k].push_back(c);
      if (k == 0 || k == numRows - 1)
        direction *= -1;
      k += direction;
    }

    for (const auto& row : rows)
      for (const char c : row)
        ans += c;

    return ans;
  }
};
```

#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/zigzag-conversion/
124. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 17:09:10

```
class Solution {
 public:
  int maxPathSum(TreeNode* root) {
    int ans = INT_MIN;
    maxPathSumDownFrom(root, ans);
    return ans;
  }

 private:
  // root->val + 0/1 of its subtrees
  int maxPathSumDownFrom(TreeNode* root, int& ans) {
    if (!root)
      return 0;

    const int l = max(0, maxPathSumDownFrom(root->left, ans));
    const int r = max(0, maxPathSumDownFrom(root->right, ans));
    ans = max(ans, root->val + l + r);
    return root->val + max(l, r);
  }
};
```
#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/binary-tree-maximum-path-sum/
Vue 3 is amazing!
Tags: vue3, pinia, compositionapi
Published: 2022-07-14 17:06:16

---
title: Vue 3 is amazing!
published: true
description: Vue 3 IMO
tags: vue3, pinia, compositionAPI
cover_image: https://th.bing.com/th/id/OIP.9h0Acjdkh0TNEvNOZPSdVwHaDt?pid=ImgDet&rs=1
# Use a ratio of 100:42 for best results.
---

Guys, recently I had to take a [Vue 3 course](https://www.udemy.com/course/vue-js-3-composition-api/) so I can start working with composition API among other tools and I had to say Vue is always surprising me. I liked the way you can build up your components with the composition API. I also got to know Pinia, the new state management for Vue and is amazing as well. Vuex was already easy to integrate and use but with Pinia is mindblowing 🤯.

I think it is good you have the options and composition Apis available. I hope I can share more insights once I get used to work with the new API, for sure it should have caveats we should be aware of. Feel free to make suggestions or share your thoughts about Vue3.

p.d. vue mugiwara's jolly roger looks terrific
357. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 17:04:09

```
class Solution {
 public:
  int countNumbersWithUniqueDigits(int n) {
    if (n == 0)
      return 1;

    int ans = 10;
    int uniqueDigits = 9;

    for (int availableNum = 9; n > 1 && availableNum > 0; --n, --availableNum) {
      uniqueDigits *= availableNum;
      ans += uniqueDigits;
    }

    return ans;
  }
};
```
#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/count-numbers-with-unique-digits/
687. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 17:01:11

```
class Solution {
 public:
  int longestUnivaluePath(TreeNode* root) {
    int ans = 0;
    longestUnivaluePathDownFrom(root, ans);
    return ans;
  }

 private:
  int longestUnivaluePathDownFrom(TreeNode* root, int& ans) {
    if (!root)
      return 0;

    const int l = longestUnivaluePathDownFrom(root->left, ans);
    const int r = longestUnivaluePathDownFrom(root->right, ans);
    const int arrowLeft =
        root->left && root->left->val == root->val ? l + 1 : 0;
    const int arrowRight =
        root->right && root->right->val == root->val ? r + 1 : 0;
    ans = max(ans, arrowLeft + arrowRight);
    return max(arrowLeft, arrowRight);
  }
};
```

#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/longest-univalue-path/
The CSS classList.toggle Method (And a surprise feature of it)
Tags: css, webdev, javascript, programming
Published: 2022-07-14 17:00:20

Hello everyone! Today i want to talk to you about the CSS classList.toggle method and an interesting feature of it that i've found.

So, let's begin by learning what the method itself does:

```html
<p>Lorem ipsum</p>
```

```css
.blue {
  color: blue;
}
```

```javascript
const p = document.querySelector("p");

p.classList.toggle("blue");

setTimeout(() => {
  p.classList.toggle("blue");
}, 5000)
```

So, above is a snippet of an HTML page with the p tag with the text "Lorem ipsum", and what we just did in the js part is, we selected the tag first, and then "toggled" the "blue" class of it.

And 5 seconds later, we just "toggled" the "blue" class again.

What that means is JS basically checks if the "blue" class exists in the element, it removes it, if it does not, it simply adds the element.

This can be used in a lot of ways! To make more reactive content and to just simply hide things in a dynamic manner, the "classList.toggle" method is great!

But what about the special part i just talked to you about?

Take the program below as an example:

```html
<p>Lorem ipsum</p>

<button>Increment</button>
```

```css
.blue {
  color: blue;
}

.red {
  color: red;
}
```

```javascript
const p = document.querySelector("p");
const incrementBtn = document.querySelector("button");
let i = 0;

p.classList.toggle("blue");

incrementBtn.addEventListener("click", (_) => {
  i++;
  if (p) {
    p.classList.toggle("red", i > 3);
    p.classList.toggle("blue", i <= 3);
  }
});
```

But Kaan, what is the second boolean property you just gave to it? I hear you asking, well that my friend, is the "force" property of the toggle method. Basically, if that method is true, the class is immediately added to the element, and if not, it is immediately removed.

So i used it to make a counter, that when it gets above 3, the text turns red, and if not, the text is blue!

Using this property you can add or remove things based on a conditional, which is amazing and very useful!

I hope today's article has been any use to you, if so, i'd appreciate your like!

And if you found any problems in the code or in any information i've given, please feel free to leave a comment and tell me about it, i'd love to hear your opinion on things!

Until then, see you in the next article!
690. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 17:00:06

```
class Solution {
 public:
  int getImportance(vector<Employee*> employees, int id) {
    unordered_map<int, Employee*> idToEmployee;

    for (Employee* employee : employees)
      idToEmployee[employee->id] = employee;

    return dfs(id, idToEmployee);
  }

 private:
  int dfs(int id, const unordered_map<int, Employee*>& idToEmployee) {
    int values = 0;

    for (const int subId : idToEmployee.at(id)->subordinates)
      values += dfs(subId, idToEmployee);

    return idToEmployee.at(id)->importance + values;
  }
};
```

#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/employee-importance/