teleren/devto huggingface dataset:
Progress on release 0.4
Tags: javascript, redis
Published: 2021-12-05 23:17:09

Last week, I managed to figure out how the `feed-queue` in the backend works and wrote some code to query the queue's status. 
The issue: https://github.com/Seneca-CDOT/telescope/issues/2414
The PR: https://github.com/Seneca-CDOT/telescope/pull/2541
### Trying to debug: 
I suspected the `redis` connection might not be entirely the same so I wanted to put a breakpoint and stop the code to inspect. The problem was that the app runs in docker containers so it took couple of steps to set up the debugger. I did not succeed in doing so, though, I learnt more about docker configurations, it'll probably come in handy in the near future. I ended up using `console.log`. 

### Changing the approach: 
After some discussions with the other devs, I decided that the `redis` connection is the correct because it works for other endpoints. I took some time reading Bull's [documentation](https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md) again, it turned out that I did not provide the `createClient` a client type. 
> When `type` is `client` or `subscriber` you can return the same connection for multiple queues, which can reduce the number of connections you open to the redis server

Therefore, I added a function to provide the connection a client type 

```js
const queue = new Bull('feed-queue', {
  createClient: (type) => {
    switch (type) {
      case 'client':
        return client;
      case 'subscriber':
        return subscriber;
      default:
        return redis;
    }
  },
});
```
Which also returns 
```js
{"queueInfo":{"waiting":785,"active":0,"completed":0,"failed":2,"delayed":0,"paused":0,"jobCnt":785}}
```

Since the `queue` in the backend removes any completed or failed job from the queue, `active` and `completed` were always 0. I tried listening the completed and failed events but since `queue` in `posts` is it a producer/worker, it's not possible to do so which is mentioned [here](https://optimalbits.github.io/bull/). Telescope also has [parser service](https://github.com/Seneca-CDOT/telescope/tree/master/src/api/parser) to handle this more efficiently but it hasn't been used.

### Wrapping up 
I agreed with David to use what I had for now for the front-end, then I wrote some tests for the need endpoint. All in all, this doesn't seem like a lot of work but it took me some time to understand Bull queue and I think this knowledge will be useful if I work on parser service next semester.
Free Resources to Learn About Software Testing
Tags: beginners, testing
Published: 2021-12-05 22:52:18

Looking for free resources or courses to kickstart your Quality Assurance Career. Here is a compilation of tools I hope you find helpful.

- [Guru99](https://www.guru99.com/software-testing.html): This online video tutorial is specially designed for beginners with little or no manual testing experience. It is an extensive resource that aims to teach you the fundamentals of software testings with topics like documenting tests, test plans... It has a real-world testing demo that takes 13 days to complete.
- [Test  Automation University](https://testautomationu.applitools.com/): Free test automation courses with videos, transcripts, quizzes, credits, rank badges and certificates. It provides courses on tools and frameworks in performing the automated tests and it consists of different paths like Web UI Javascript path, WebUIPython path, Mobile Java path, Codeless path etc.
- [uTest Academy](https://www.utest.com/academy): uTest is home to a growing family of freelance software testers who want to develop new skills, earn extra money, and make a real impact on the digital products of their favourite brands. This community provided a list of free courses for you once you become a member of the community.
- [Art Of Testing](https://artoftesting.com/): This website provides training that requires no prerequisites and it would teach you from scratch including the basics theories and technical training

### Conclusion
I hope you find these resources useful. Feel free to share and comment on additional helpful resources!
Solving day 5 of Advent of Code 2021 in JavaScript
Tags: challenge, adventofcode, javascript, video
Published: 2021-12-05 22:25:04

---
title: Solving day 5 of Advent of Code 2021 in JavaScript
published: true
description: JavaScript walkthrough of Advent of Code 2021 (day 5)
tags: challenge, AdventOfCode, javascript, video
series: Advent of Code 2021 in Javascript
---

{% youtube Y9Di64SW6g0 %}
Typing process.env automatically with this VSC extension
Tags: typescript, node, vscode, processenv
Published: 2021-12-05 22:17:31

what's up typescript enthusiasts 👋
tired from writing types for your env variables to get a type-safe version of process.env [as seen in this tutorial](https://dev.to/isthatcentered/typing-process-env-and-dealing-with-nodeenv-3ilm)?

## Setup

1- Install `@types/node` in your project
```sh
$ yarn add @types/node -D

// or using npm

$ npm i @types/node -D
```

2- First of all, download the VSC extension [TS Env Typings](https://marketplace.visualstudio.com/items?itemName=YassinEldeeb.env-typings)

3- Specify `env-typings.json` file in the root of your project.

![config JSON file in the root directory](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/05tgij9a3qk5sr7jdosg.png)

4- Add `path` field to your development `.env` file
![JSON config file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mvv35jrhdictxezclx1z.png)
and yep! you even have auto-completion in this JSON config too 😎

That's it, Enjoy!

## Cool Features 🆒
1- Specify path for the generated output using `output` field in the JSON config.
![output option in config file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r1kjekvysd0c17qu9758.png)

2- Auto detect env variable type so that It can give you a nice example in the intellisense on how to use and parse it.

so as an example if you've a number env variable It'll tell you to use parseInt to parse it before using it cause env variables are always read as strings.
![example in the intellisense on every env variable](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fmbj2gemqke91k0hg85q.png)

3- Variants for an env variable, so you tell the extension what are the possible values for an env variable so It can generate better types for it and recommend you a nicer example to use
![variants for an env variable](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kg86j6aisnllzra8creb.png)

### How to specify Variants in .env file?

- add a comment at the end of the env line that includes "# variants:"

- specify the different variants for your variable seperated by a "|" like you would in typscript

- quotes are optional around the variants values

![Specify Variants in .env file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pslspgt2jl5x2a05ya5g.png)


That's it.

If you liked the extension, please give it a [star here 🌟](https://github.com/YassinEldeeb/Env-Typings-VSC)

Hope you've a great day, curios to see your feedback 🤗
Flask MVT. Refactor to service layer
Tags: flask, python, mvc, softwaredesign
Published: 2021-12-05 22:08:41

In this short post I would like to show how we can improve separation of concerns using Service Layer pattern within Model View Template approach.

## Model View Template
MVT is an application building pattern, commonly used in frameworks like Flask (but also Django).
It consists of three separated components:
1. Model layer that is resposible for domain logic and persistence.
2. View that concerns about handling http request. It is a place where application API is defined. The view orchestrate application logic by interaction with model and executing requests to external services.
3. Template is a presentation layer (e.g. html templates) that handles User Interface part.

![mvt.drawio.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1637924048990/_vyXOsAHI.png)

MVT approach often results in following code smells:
- mixing resposibilites of handling http request (e.g. operating on query string params, cookies, headers, etc.) with application logic orchestration (strong coupling between a framework and business requirements).
- complicated test setup (always need a http request to test application logic).
- mixing resposibilities of domain logic and persistence (infrastructure concern)

## Push your framework outside application logic
A solution that can ease first two of three mentioned smells is an introduction of a service layer (it can be class but also standalone function, depending on the specific case). It can decouple application logic from a framework we use (application features / use cases become agnostic of framework code). View is now resposible for handling requests and executing service layer methods / functions, while application logic is now only a concern of a service layer. It allows us to focus on application core at first, and implement API that enables entry to it afterwards. Thanks to the separation, API does not necessary need to be API supporting rendered templates but it can be CLI (Command Line Interface), REST API, GraphQL API, RPC, etc. The decision about API (and framework) can be deferred, but we still can devop our application features. 
API and application logic separation could also improve our tests. We could now write tests of application core, covering logical paths extensively, while covering only happy path for API part.

![mvt_service.drawio.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1637918478947/8Uk5e6ZWI.png)

## Conclusion
This solution is not a silver bullet of course. We should consider it when our view endpoints are large and not trivial, and writing clean, readable code is challanging.
Social login made really easy
Tags: javascript, programming, tutorial
Published: 2021-12-05 21:30:04

> 
There are many social login libraries out there.
They all require registration and are domain dependent.

They are also hard to understand at first look.

This does not have to be. 

We tried a different approach to social login 

We do all the heavy lifting and return a signed JWT.
We also supply the npm module to verify this jwt and put the login info into the request and even the session.

So how to use it:

just add these lines:

`const azauth=require('azauth');
app.use(azauth.auth);`


Belive it or not you are done !!!!

Create your login button like this:

`
<a href="http://auth.azjs.io/googleAuth/authTo/{callback url}" GOOGLE LOGIN </a>
`

Where "{callback url}" is your website login rout (remember to encodeuricomponent this valeu)

Now on your server you will get the user profile at the {callback url} on the request.azAuth.data

For example:


```
app.get('/afterLoginCallback',  function(req,res){
    console.log(req.azAuth.data) //this holdes the user profile  
   res.send(`Hi <b> ${req.azAuth.data.emails[0].value} </b> <br>this all the profile info <br> ${JSON.stringify(req.azAuth.data)}` )

})

```
That is all. You are done.
Be happy to hear what you think about it.

This is a short explainer video : https://github.com/orenz/azauth
This is the git: https://github.com/orenz/azauth


Thanks
Advent of Code 2021 - Day 5
Published: 2021-12-05 21:29:39

---
title: Advent of Code 2021 - Day 5
published: true
description: In this video series, I try to challenge myself with the Advent of Code trials. Each solution will be published to Github, and I hope you will learn something from my coding mistakes and perhaps send some code my way on how you have done these challenges. I know by reading code, so this is such an exciting thing for me.
tags:
cover_image: https://i.ytimg.com/vi/Df6KPo9cx_E/maxresdefault.jpg
---

{% youtube Df6KPo9cx_E %}

In this video series, I try to challenge myself with the Advent of Code trials. Each solution will be published to Github, and I hope you will learn something from my coding mistakes and perhaps send some code my way on how you have done these challenges. I know by reading code, so this is such an exciting thing for me.
⭐️ CodeCast's Coding Advent: Day Five ⭐️
Tags: webdev, beginners, programming, tutorial
Published: 2021-12-05 20:57:40



![Day 5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwdz2ig2aq8hq7i1ueqd.png)

## DAY FIVE


Today we're featuring one of our favourite tech podcasts, [HTML All The Things](https://www.htmlallthethings.com/)! With a new episode weekly, they are an incredible resource and listen for anyone interested in coding - no matter how experienced.

Listen to their latest episode now:

{% spotify spotify:episode:6JE4x2VnNNe0LV9CVjr1cH %}
⁠
You can also be sure to follow us on [Instagram](https://www.instagram.com/codecastapp/), [Twitter](https://twitter.com/CodeCastApp), [Facebook](https://www.facebook.com/codecastapp), and [LinkedIn](https://www.linkedin.com/company/code-cast/) to see our daily advent releases there!
🎄CodeCast's Coding Advent: Day Four 🎄
Tags: javascript, webdev, beginners, programming
Published: 2021-12-05 20:57:30


![Day Four](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uwkkl2suzgmt6gdysslt.png)

## DAY FOUR

Trees are great for hanging ornaments on and putting presents under. Binary trees are a little less festive but an important data structure.⁠
⁠
Let's take on this [Coderbyte binary tree JavaScript challenge](https://www.coderbyte.com/information/Tree%20Constructor) for day four of our coding advent.⁠
⁠
You can also be sure to follow us on [Instagram](https://www.instagram.com/codecastapp/), [Twitter](https://twitter.com/CodeCastApp), [Facebook](https://www.facebook.com/codecastapp), and [LinkedIn](https://www.linkedin.com/company/code-cast/) to see our daily advent releases there!
Did you hit a wall at 10 years?
Tags: discuss, watercooler
Published: 2021-12-05 20:42:05

I have been doing this whole code thing for a good long time, but lately the whole prospect of developing libraries and other community efforts have taken a back seat, I guess I saw how robotic I had became.

I have interests now and hobbies and maybe one day, friends 🦾😉😅

I'm wanting to not become the enclopedia of web dev. Good is enough

Is that wrong? How do you feel, is this just motivation, or has COVID changed you too?
Get the balance of a Solana Wallet
Tags: blockchain, javascript, web3, webdev
Published: 2021-12-05 20:34:09

Hello Devs!

Developing apps in Solana can feel like the Wild West right now. This past weekend I spent 2 days just trying to get the balance of a certain token from a wallet that connects to my site. 

I felt really frustrated because it was something that seemed easy but I could not find a real example or how to do it. 

So, here I am trying to explain it the best way I can.

The first thing you need to do is to get the user’s public key. You can achieve this really easily retrieving the solana object from your window.
 ```javascript
const [walletAddress, setWalletAddress] = useState(null);
const connectWallet = async () => {
         //Get the solana object
        const { solana } = window;
        // If we have it, we assign the value to a variable
        if(solana) {
            const response = await solana.connect();
            console.log('Connected with Public Key: ' + response.publicKey.toString())
          setWalletAddress(response.publicKey.toString())
        }
      };
```
Nice! We can now talk to Solana and ask for the balance.

First, you need to import the following functions from web3.js (`npm install --save @solana/web3.js ` if you dont’t have it).

```javascript
import { Connection, clusterApiUrl, PublicKey } from '@solana/web3.js';
```
Then, we just do the following: 

```javascript
const [balance, setBalance] = useState(0);
const getBalance = async (wallet) => {
        const connection = new Connection(clusterApiUrl('mainnet-beta'), 'confirmed')
        const response = await connection.getParsedTokenAccountsByOwner(wallet, 
            {mint: new PublicKey(PUBLIC_KEY_OF_TOKEN)}    
        ) setBalance(response.value[0].account.data.parsed.info.tokenAmount.uiAmount) 
    }
```
OH YEAH!

We just received our user’s balance. But how? 🤔

Well, first, we create a useState with the initial value of 0 that is going to hold the balance. Then, we declare our function and that we need to pass it a string of our user’s wallet public key. 

Ok, we need to create a connection with the solana blockchain, that’s why we imported “Connection” and “clusterApiUrl” from the web3.js. I’m not going to explain what each of these things mean but you should be able to find them easily if you google them.

Now that we have the connection, we are finally able to ask for the balance. We do that calling the getParsedTokenAccountsByOwner function from our connection and passing the wallet address and an object containing the public key of the token you want to find. 

Finally, we just use setBalance to assign the value and that’s it!

I hope you found this useful and that you don’t spend as much time as I did trying to get a balance.

See you soon devs!
Advent.js🎅🏼| #5: Contando los días para los regalos
Tags: javascript, webdev, adventjs, spanish
Published: 2021-12-05 20:27:46

## [Contando los días para los regalos](https://adventjs.dev/challenges/05)

Con la emoción, ya estamos empezando a **contar los días del calendario hasta el 25 de diciembre** 📆.

Para ayudar a esto, vamos a crear una función que pasándole una instancia de `Date` nos diga el número de días que faltan.

Veamos unos ejemplos:

```js
const date1 = new Date('Dec 1, 2021')
daysToXmas(date1) // 24
const date2 = new Date('Dec 24, 2021 00:00:01')
daysToXmas(date2) // 1
const date3 = new Date('Dec 24, 2021 23:59:59')
daysToXmas(date3) // 1
const date4 = new Date("December 20, 2021 03:24:00")
daysToXmas(date4) // 5
```

El resultado tiene que ser **un número entero** y, como ves, aunque falte un segundo hasta el siguiente día, se entiende que todavía falta un día.

**¡Pero ojo!** También hay que indicar si la fecha es del mismo día (devolveríamos `0`) o si es una fecha futura (devolveríamos el número de días en negativo `-`):

```js
const date = new Date('Dec 25, 2021)
daysToXmas(date) // 0
const date1 = new Date('Dec 26, 2021')
daysToXmas(date1) // -1
const date2 = new Date('Dec 31, 2021')
daysToXmas(date2) // -6
const date3 = new Date('Jan 1, 2022 00:00:01')
daysToXmas(date3) // -7
const date4 = new Date('Jan 1, 2022 23:59:59')
daysToXmas(date4) // -7
```

Por cierto, la fecha de referencia para saber si es 25 de diciembre es `Dec 25, 2021`.

Completa el reto!

--- 

Mi solución:

{% jsitor https://jsitor.com/embed/31XL2KFIe %}

---
Puedes seguir a @midudev y estar pendiente de los retos de Advent.js 

{% twitter 1466086678507008003 %}
Learning Go #1
Tags: go, learning, beginners
Published: 2021-12-05 20:04:26

I am a **database engineer** for a while.  One time I decided to learn Go programming because many of the famous software developers such as @yakuter and [fatih](https://twitter.com/fatih?s=20) are using Go and they share their experience. I thought it is amazing for me. They learn it and build an app with this language and then share their experience on Twitter, Linkedin, Github, etc. platform. After deciding the learn this language, I want to share my adventure of Go learning. 

First of all, I ask a question on Twitter about how can I learn Go language systematically and mentioned the @yakuter, then this good man shared a tweet flood about learning Go documents, courses, books, etc. 
Now, we can start the adventure of Go learning.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uozjl5xdocwrjc9hnr0h.png)
Let's Go :)
Firstly, I started the official Go learning document with examples  [golang-tour](https://tour.golang.org). And I am on to read this documentation and learn basically. It is the first step for learning Go basically. This tour made up basic of Go language and some activities on them. The web page has two sides, left and right. The left page consists of the knowledge of the information such as variables, slices, maps, etc., on the other hand, the right page has consisted of activity/test area that is related to the information and you can run the sample code or can write your sample and then run it. With this tour, I learned data types, variables, packages, flow control statements, etc. basically and understand package and import logic, the usage of Go is simpler than in other languages, you can define any data type easily, and there is a spelling rule. For example, when you create any variable in Go, you must use this variable in your code block, at worst you can use this variable in the Println function :) Yeap, this is enough for the first step of learning Go. In the coming days, I will try to explain my Go experiences on the windows operating system in a more organized and regular way. 

The first code :)

```
package main

import "fmt"

func main() {
	fmt.Println("I am learning Go.")
}

```
Get the absolute path to the project directory in Hugo
Tags: hugo, jamstack
Published: 2021-12-05 19:42:06

---
title: Get the absolute path to the project directory in Hugo
published: true
description: 
tags: Hugo, JAMstack
---
Hugo doesn't seem to make it possible to get the absolute path of the project directory: all of its filesystem functions use the main project directory as the root. However, there may be times that you want to know the absolute path to the project, like if you wanted to build an "edit" link on your posts that would open the markdown file in VS Code.

Though Hugo doesn't provide access to the project path directly, we can grab it using the system's environment variables.

By default, Hugo can only access variables that are prefixed with `HUGO_`. Therefore, we must explicitly give Hugo access to the `$PWD` system environment variable. Add the following to the project's `config.toml` file:

```toml
# config.toml

[security]
  [security.funcs]
    getenv = ['^HUGO_', 'PWD']
```

Now you can use the `$PWD` environment variable in your Hugo template:

```html
<p>The working directory is {{ os.Getenv "PWD" }}</p>
```
This will print the `$PWD` shell environment variable, which is the current working directory. If you ran `hugo` from your project's main directory, `PWD` will be the absolute path to that directory.

## Considering edge cases

The code above will work in 95% of cases: most people run the `hugo` command from the main project directory. However, Hugo lets you specify any project directory with the `--source` flag.

```sh
hugo --source /path/to/project
```

In this case, `PWD` would give you whatever directory you ran this command from, which probably isn't the project directory.

In this case, you could use an environment variable to specify the project path:

```sh
HUGO_PROJECT_PATH=/path/to/project hugo --source /path/to/project
```

You can now access the `HUGO_PROJECT_PATH` variable in your template using the following:

```html
<p>
  The HUGO_PROJECT_PATH variable is
  {{ os.Getenv "HUGO_PROJECT_PATH" }}
</p>
```

If you wanted to use the `HUGO_PROJECT_PATH` variable if it is set, and fallback to `PWD` if it's not, you could do that with the following:

```html
{{ or (os.Getenv "HUGO_PROJECT_PATH") (os.Getenv "PWD") }}
```

On the other hand, maybe you want to make `HUGO_PROJECT_PATH` a required variable for Hugo to even start. You can do that by throwing an error if the project path isn't set.

```html
{{ if os.Getenv "HUGO_PROJECT_PATH" }}
  {{ os.Getenv "HUGO_PROJECT_PATH" }}
{{ else }}
  {{ errorf "Must have a HUGO_PROJECT_PATH environment variable to run project" }}
{{ end }}
```

---

In an ideal world, Hugo would provide a first-class way to access the project directory within your templates. Since it doesn't seem to do that at the time of writing (December 2021), these workarounds might be good enough for now.