teleren/devto huggingface dataset:
Using BitWarden and Chezmoi to manage SSH keys
Tags: unix, chezmoi, bitwarden, ssh
Published: 2020-08-28 19:14:42

I have recently started using [Chezmoi](https://www.chezmoi.io/) to manage my dotfiles (and various other pieces software config) across multiple machines. The distribution is done via a git repo and therefore we should not check in secrets such as the private part of the SSH key. Using [Bitwarden](https://bitwarden.com/), we can store the key in a Secure Note and retrieve on the other machines.

## Setup

The rest of this post assumes you already have [Chezmoi](https://www.chezmoi.io/) installed and set up:

```bash
curl -sfL https://git.io/chezmoi | sh
chezmoi init
```

You will also need a pre-existing SSH key:

```bash
ssh_keygen -o
```

## Store the key

The public key part of the SSH key can be stored in Chezmoi in plain text:

```bash
chezmoi add .ssh/id_rsa.pub
```

To store the private part we are going to need to install the [`bitwarden-cli`](https://github.com/bitwarden/cli) and then login and unlock it:

```bash
bw login <EMAIL-ADDRESS>
bw unlock
export BW_SESSION="<SESSION-ID>"
```

Now, we get to the magic sauce. This line will store your SSH key (stored at `~/.ssh/id_rsa`) in a secure note in Bitwarden:

```bash
echo "{\"organizationId\":null,\"folderId\":null,\"type\":2,\"name\":\"sshkey\",\"notes\":\"$(sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\\\n/g' ~/.ssh/id_rsa)\",\"favorite\":false,\"fields\":[],\"login\":null,\"secureNote\":{\"type\":0},\"card\":null,\"identity\":null}" | bw encode | bw create item
```

And finally, we need to tell chezmoi where to get the key from. Create a file in your chezmoi repo at this location: `private_dot_ssh/private_id_rsa.tmpl` and add this as the contents:

```
{{ (bitwarden "item" "sshkey").notes }}
```

(For OSX, this file needs a new line character at the end. For Linux, I believe it mustn't, so you might need to end the file with `-}}` instead)

Make sure all the files are committed and pushed to the origin.

## Retrieve the key

On another machine where you want to retrieve the same key, make sure `bitwarden-cli` and Chezmoi are installed and first do the same login and unlock steps for Bitwarden as above. Then simplpy do:

```bash
chezmoi init --apply <GIT-REPO>
```

And that's it. Check your private key has made it safely to your machine by doing `cat ~/.ssh/id_rsa`.

You can see the full example of my chezmoi config [here](https://github.com/jmc265/dotfiles).
Longest Substring Without Repeating Characters 
Tags: javascript, leetcode, algorithms
Published: 2020-08-28 19:12:02

I have recently started attempting one [LeetCode](https://leetcode.com/) LeetCode problem everyday, to keep me "in shape".

Today's task? To [find the length of the longest substring without any duplicate characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/).

Here's my solution process:
* Loop through giving string (s) while counting characters, and break if a duplicate is found
* Use a **hash-map** (in this case, a `javascript object`) to store the unique characters
```
let uniqueChars = {}
let length = 0;
for(let i=0; i<s.length; i++){
  let char = s.charAt(i)
  if(uniqueChars[char]) {break;}
  else {
     uniqueChars[char] = true
     length ++
  }
}
return length;
```
Now, we're not done, because we are assuming that the longest substring starts from the first index (!).
So, to account for that, we'll need to make it into a *recursive* function where we keep slicing the string till the end, and compare the lengths.

Looks like this:
```
var lengthOfLongestSubstring = function(s) {
    if(s.length <= 1) return s.length  //for 1-letter or empty strings
    let uniqueChars = {}
    let length = 0;
    let counter = 0
    for(let i=0; i<s.length; i++){
        let char = s.charAt(i)
        if(uniqueChars[char]) {break;}
        else {
            uniqueChars[char] = true
            length ++}
    }
    if (length >= s.length -1) return length
    return Math.max(length, 
         lengthOfLongestSubstring(s.slice(++counter)))
};
```
Let's break this down:
- From index, counter, we loop through string UNTIL there's a duplicate or we reach the end.
- After the loop, we check if the length of our substring is at least **1 less than the string length**. If true, we can stop searching, because this is our max length.
- Otherwise, we call the function again, moving the counter a step forward, and return the maximum of both lengths.
This happens until the counter is at the last letter.

> As you can probably tell, this method has a time-complexity of O(n^2), as we have to loop through the rest of the string at every index. 👎

I will be updating this with a faster algorithm, but please feel free to let me know your suggestions!
To quit or keep trying? 
Tags: javascript, java
Published: 2020-08-28 19:03:45

I am struggling. 

I have a basic understanding of Java and Javascript. 

But when it comes to implementing the knowledge I can't seem to think of how to put it together. I feel like I'm just moving with no direction. 

Any tips and advice will help. I have completed loads of courses on udemy/code academy and the likes. But still struggling with building a personal portfolio.
Install Ansible on Mac
Tags: ansible, devops, macos, tutorial
Published: 2020-08-28 18:50:53

For my own tastes, the easiest way to install Ansible on my Mac is via Homebrew...

```bash
brew install ansible
```

For some additional paths, and other OS guides, check out this post...

{% link https://dev.to/craicoverflow/how-to-install-ansible-24kn %}

Hope this helps someone out there find the answer _slightly quicker_ if searching. 😄

What is Ansible you ask?

{% wikipedia https://en.wikipedia.org/wiki/Ansible_(software) %}
Postgres concat_ws() function
Tags: postgres, sql
Published: 2020-08-28 18:30:55

Postgres provides a [`concat_ws()`](https://www.postgresql.org/docs/current/functions-string.html) string function with this signature:

```
concat_ws(sep text, str "any" [, str "any" [, ...] ])
```

Consider a schema where the `projects.second_user_id` and `project.third_user_id` columns can be `NULL`:

```
              Table "public.projects"
     Column     |            Type        | Nullable |
----------------+------------------------+-----------
 id             | bigint                 | not null |
 name           | character varying(255) | not null |
 lead_user_id   | bigint                 | not null |
 second_user_id | bigint                 |          |
 third_user_id  | bigint                 |          |

                Table "public.users"
     Column     |            Type        | Nullable |
----------------+------------------------+-----------
 id             | bigint                 | not null |
 initials       | character varying(255) | not null |
```

Consider a query to get the "team" for a project by each user's initials:

```sql
SELECT
  projects.name,
  concat_ws(' / ', u1.initials, u2.initials, u3.initials) AS team
FROM
  projects
  LEFT JOIN users u1 ON u1.id = projects.lead_user_id
  LEFT JOIN users u2 ON u2.id = projects.second_user_id
  LEFT JOIN users u3 ON u3.id = projects.third_user_id
GROUP BY
  projects.name,
  team
ORDER BY
  projects.name ASC;
```

Example output:

```
     name     |     team    
--------------+--------------
Private Beta  | AB / CD
SLA           | EF / GH / IJ
Treasury Ops  | KL
(3 rows)

Time: 1 ms
```

Using `concat_ws()` instead of `concat()` avoids ugly output like `AB / / CD`.
Helping Build Bridges in Rwanda 
Tags: node, react, javascript
Published: 2020-08-28 18:27:23

A wonderful opportunity came by! And it was to work on a project that will help map ideal locations for a non-profit company to build bridges for the people of Rwanda, I couldn't be happier to get started.😃

I collaborated with a team of 6 remote web developers, 3 Data Scientists, and a UX/UI designer.

<h3>WHAT ARE WE GOING TO BUILD? 🤔</h3>

After meeting with the stakeholder, we found out their main needs:
- A map to show villages and where current bridges are located
- Filter through bridges
- Search for bridge sites by specific criteria
- The ability for admin to add, edit, and delete bridge sites. 

<h3>User Personas</h3>
- Staff can get and retrieve data and view results
- Admin can add, edit, and delete bridge sites.

<h3>💼 What tech stack to use?</h3>
<h4>Front-End</h4>
- React,Redux and Javascript
- MapBox to display the data on a map
<h4>Back-End</h4>
- NodeJS, Postman, Postgres

<h3>📝 Planning the project</h3>
After a few good ideas on how we would display the information to the users, we decided to go with a familiar design that's similar to google maps style. This will make it easy to visualize the data.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/m9k5hviggouc6et0x5ue.png)

 <h3>📈 What's our project status?</h3>
Well, working with an amazing team of devs has certainly made this project very enjoyable to work on. We have managed to collaborate well through our daily stand-ups and pair-programming and we have made significant progress so far.

This is a work in progress, but our landing page will look like this:
![Landing Page](https://dev-to-uploads.s3.amazonaws.com/i/o0np5e4flr02s0kv9vob.PNG)

With over 1300 bridge sites, we want to give our users the ability to search/filter through the bridges and display only relevant data. 
![Map](https://dev-to-uploads.s3.amazonaws.com/i/1rlnpxljojthxd2xhknz.JPG)

<h3>Where to from here?</h3>
This is the end of our first version of the application. In the next several weeks, we will meet with our stakeholders and look to improve upon the application. 

<h3> Our Team</h3>
 <h4>👨🏼‍💻 Devs:</h4>
- Jimmy McBride: [Github](https://github.com/JimmyMcBride)
- Devin Graham: [Github](https://github.com/Devin44G)
- Anthony Amaro: [Github](https://github.com/anthonyamaro15)
- Gerald Ryan: [Github](https://github.com/GeraldRyan)
- James Carpino: [Github](https://github.com/jameslcarpino)
- Mosae Litsoane: [Github](https://github.com/Mosae)

<h4>🧪 Data Science:</h4>
- Alex
- PingAo
- Jessica Cooper

<h4>🕺🏻 UX/UI:</h4>
- Brian Nam:[Github](https://github.com/oozboy)
AlgoliaQB - First Release
Tags: algolia, query, builder, search
Published: 2020-08-28 18:21:01

---
title: AlgoliaQB - First Release
published: true
description: A python package to aid in building algolia queries
tags: algolia, query, builder, search
cover_image: https://res.cloudinary.com/hilnmyskv/image/upload/v1527077656/Algolia_OG_image_m3xgjb.png
---

Today I am releasing the first version of Algolia Query Builder. Its purpose is to make generating a filter query easier. You can then pass the generated query directly into the algoliasearch search function. Hopefully, this can help make others' lives easier as well as my own.

#### Installation:

```
pip install algoliaqb
```

#### Usage Example:

```
from algoliasearch.search_client import SearchClient
from algoliaqb import AlgoliaQueryBuilder
from flask import request


aqb = AlgoliaQueryBuilder(
    search_param="search",
    filter_map={
        "group_id": "tenant_id",
        "is_reported": "is_reported"
    }
)

# Extract the search query from our flask apps request.args var.
search_query = aqb.get_search_query(request.args)
# Get the filter query from our request args.
filter_query = aqb.get_filter_query(request.args)

# Now that we have the filter string, we just pass it into the search function.

search_client = SearchClient()
index = search_client.init_index("contacts")
results = index.search(search_query, {"filters": filter_query})
```

For more information please checkout [Github](https://github.com/Ryanb58/algoliaqb) or [Pypi](https://pypi.org/project/algoliaqb/).
Answering a Stack Overflow question per day
Tags: java, challenge, devlive
Published: 2020-08-28 18:06:14

I recently decided to try and experiemnt with Stack Overflow. always had mixed feelings about Stack Overflow. It’s incerible resource of knowlage, if you google almost any technical question it’s in the top results. Usually with pretty good answer. On the other hand it’s community seems incredibly toxic. When you ask question that may have been answered, or not properly formatted or in general do not study really long guidelines they will let you know.

I decided to answer a question per day. This way I will improve my mentopring skills, writting skills and figure out why the community seems so toxic.

I am a mainly java developer so I decided to answer Java related questions. I filtered by Java tag and tried to answer muy first question. And there was my first problem. Lots of stupid questions. Third of the questions were about Android, third were mislabeled (a lot of people tag Java on Java Script questions) and third were easily googleable. By easily I mean copy the question title to google and first link is probably stack overflow answer of the question.

It’s hard to find question that is worth answer. Stack overflow allows you to tag already answered questions, bad questions, etc. Their moderation works pretty well. When I was tagging those questions I always tried politly explain to the poster what he did wrong. Most of the posters never learn tho. If your are member of the community it’s easy to see why you start to be more offensive to people. The flow of bad questions is really bad.

When you finally find the question you want to answer too, you need to be really fast. There is usually like ten people answering the same time. Tactic here is to post the very bare bone answer without editing or explaning. Just to be first. You will edit it later. This seems toxic to me. A lot of the answers are generic and not good. But hey it brings karma. Yey.

During the month I went from 75 karma to 647 karma. That is not that much. When uyou answer you almost never get any feedback to get karma. Most of the time the answer is not even accepted. People if you find helpful answer just upvote it. Even if it was posted years ago.

At the end my feelings are still mixed. I understand why the community seems toxic and I will not continue with answering. It seems like waste of time.
Let's pay some Attention!
Tags: machinelearning, neuralnetwork, transformers, tutorial
Published: 2020-08-28 18:05:12

Before discussing a new technology or methodology, we should try to understand the need of it. And so, let us know what gave path to the Transformer Networks. 

## Challenges with Recurrent Neural Networks
![Image from mc.ai](https://dev-to-uploads.s3.amazonaws.com/i/ptwajkhdgj3i1zhgsqgv.png)
_(Image Source : mc.ai)_

Gradients are simply vectors pointing in the direction of highest rate of increase of the function. During backpropagation, gradients go through matrix multiplication multiple times using the chain rule. Small gradients get smaller until they vanish and thus it gets harder to train the weights. This is called the vanishing gradient problem.
While smaller gradients vanish, if your gradient is a large value they go on increasing and result in very large updates to our network. This is known as the exploding gradient problem. 

Another challenge one faces with RNNs is that of 'reccurence'. Recurrence prevents parallel computation.
Also, large number of training steps are required to train an RNN.

Solution to all our problems is - __Transformers__!
As the title says, _Attention is all you need_ by [Vaswani et al, (2017)](https://arxiv.org/abs/1706.03762) is the paper that introduced the concept of transformers.
Let us first understand the __Attention Mechanism__.
Below attached is an image from my notes of [Prof. Pascal Poupart's](https://www.youtube.com/channel/UC7ZVvEo7-B7lA6LY2MVX72A) lecture on Transformers.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/nvhmz014asq2ygtwip42.jpg)

Attention Mechanism mimics the retrieval of a value (v) for a query (q) based on a key (k) in the database. 
We have a query and some keys (k1, k2, k3, k4), we aim to produce an output which is  a linear combination of values where the weights come from the similarity between our query and keys. 
In the above diagram, the first layer consists of the keys (vectors). We generate another layer from the similarity comparison of these keys with the query (q). Thus the second layer consists of similarities (s).

We take softmax of these values to yield another layer (a). The product of values in (a) with the values (v) gives us the attention value. 

So far we have understood what gave rise to the need of _Attention_ and what exactly is _Attention Mechanism_.
What more will we cover?
- Multihead Attention
- Masked Multihead Attention
- Layer Normalisation 
- Positional Embedding
- Comparison of Self Attention and Recurrent Layers

Let's cover all this in the next blog! 
You can follow me on [twitter](https://twitter.com/ShambhaviCodes) where I share all the good content and blogs!
netselect: A CLI tool to find the fastest host based on the lowest ICMP latency.
Tags: go, githunt, showdev, github
Published: 2020-08-28 18:01:57

---
title: netselect: A CLI tool to find the fastest host based on the lowest ICMP latency.
published: true
description: 
tags: golang,githunt,showdev,github
---

`netselect` is a CLI tool and go library to select the fastest host based on the lowest ICMP latency.
Try it and let me know your feedback. I would greatly appreciate it.

https://github.com/pgollangi/netselect

```sh
$ netselect google.com google.in google.us
google.com       55 ms  100% ok         ( 3/ 3)
google.in        56 ms  100% ok         ( 3/ 3)
google.us        59 ms  100% ok         ( 3/ 3)
```
Creating Rust Functions in Node.js with SSVM and Docker
Published: 2020-08-28 17:54:22

I recently came across SSVM with which we can easily create an app with Rust functions. I followed these steps for creating the application:

## 1. Creating the development environment with Docker

### Get the code
$ git clone https://github.com/second-state/ssvm-nodejs-starter
$ cd ssvm-nodejs-starter

### Run Docker container
$ docker pull secondstate/ssvm-nodejs-starter:v1
$ docker run -p 8080:8080 --rm -it -v $(pwd):/app secondstate/ssvm-nodejs-starter:v1
(docker) $ cd /app

## 2. Create an application
### Copy the example application
https://github.com/second-state/wasm-learning/tree/master/nodejs/quadratic

### Replace files in the sample application and build

$ ssvmup build
$ npm install express # The application requires the Express framework in Node.js
$ node node/server.js

## 3. Run application in the browser and check

From the web browser, go to http://localhost:8080/ to access this application.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/t5p9q174a8of4whpseob.png)
Execute Cloud Hosted GraphQL Queries From your Browser
Tags: tutorial, wayscript, graphql
Published: 2020-08-28 15:37:31

Introduction
------------

Integrating GraphQL into your workflow is easy with wayscript. With our prebuilt module, all you need is the url of the server you're writing your query against & your own GraphQL code. Let's take a look at how we can easily query an API with information about countries and their calling codes.

Working with GraphQL
--------------------

Our new GraphQL module let's you write graphQL queries directly in our editor. Let's take a look at how to set this up. We'll create a new script and place the graphQL module as the first step of our workflow.  
  

![](https://cdn.wayscript.com/blog_img/110/1.png)

  
  
To configure it, we'll need a few things. We'll need the URL in which we want to send our request to, the GraphQL query, and the headers we want to send with the request. In the below example we want normal JSON, from a server which provides country calling code data.  
  

![](https://cdn.wayscript.com/blog_img/110/2.png)

  
  
There are a few advanced options should you need them as well. We can set the number of retries we want to send should the query be unsuccessful the first attempt and if JSON is the preferred request method. The code we're using in this example looks like this: <pre>
query { 
    CallingCode { 
    name 
    countries {
     name 
        } 
        } 
    }
</pre>
Using the GraphQL Return
------------------------

GraphQL will return the specified response, the default being displayed with a struct type object within WayScript. Here's the example response in this example:  
  

![](https://cdn.wayscript.com/blog_img/110/3.png)

  
  
We can access these values within wayscript in other modules. These wayscript variables are part of what makes it so fast to develop solutions using our platform.

Looping & Conditional Statements
--------------------------------

Let's say we wanted to loop through our response, looking for countries only with a certain calling code. This is easy to do using a loop and an if statement module:  
  

![](https://cdn.wayscript.com/blog_img/110/4.png)

  
  
The Loop we can set to loop oer each object within our dictionary type object. The if statement we can set to look for the certain desired calling code.  
  

![](https://cdn.wayscript.com/blog_img/110/5.png)

  
  

Questions, Feedback?
--------------------

As always, if you have any questions, comments, feedback, or suggestions, please let us know on WayScript or through our [discord](https://discord.gg/VWbXSbj). The script used in this tutorial can also be found [here](https://wayscript.com/user/derricks/S_qrNUw8).
Ask Octopus - Can I check my server health with the API?
Tags: octopus, tutorial, api, devops
Published: 2020-08-28 17:38:03

---
title: Ask Octopus - Can I check my server health with the API?
published: true
description: You want to monitor your Octopus server to see if it's running and what its state is. Is there an API endpoint for that? Find out in this week's Ask Octopus.
tags: octopus,tutorial,api,devops
series: Ask Octopus
---

You want to monitor your Octopus server to see if it's running and what its state is. Is there an API endpoint for that? Find out in this week's Ask Octopus.

{% youtube 4dkQmlG9iEQ %}

Do you have a question about how to use Octopus? Email advice@octopus.com and someone from our team will get you an answer. You might even see it in a future episode.

Join our community slack at https://octopus.com/slack
GitHub app fails after deploying to production
Published: 2020-08-28 17:37:19

So I have this github app, which manages to update file content and create new files when I use it on my localhost. But as soon as I deploy the app to production, it fails and gives an error saying 403 forbidden "Resource not accessible by integration". Any help on this topic will be hugely appreciated. I have been blocked for a week now and this frustrating.


**Update:** Managed to get it up and running. Needed a Personal Access Token to be genarated and passed on to the Authorization Header while making the service call.

https://stackoverflow.com/questions/63638496/any-idea-why-my-github-app-manages-to-update-the-file-content-using-the-same-ser