teleren/devto huggingface dataset:
adding testing
Published: 2021-11-13 04:55:01

This lab, i added testing to the ssg tool. I used Jest to test my tool. I choose Jest for testing as it is simple, and widely accepted. Also, documentation for it is very easy for beginners to understand and there is a huge community on the internet that shares knowledge on this framework if needed. The link to the official Jest website can be found [here](https://jestjs.io/), link to its open source on GitHub can be found [here](https://github.com/facebook/jest).

## Setting up Jest
to install Jest, you first need to install its npm package. most of the time it is preferred to install it as a dev-dependency as it is not the main part of developing. you can install it with this command.
> npm i -D jest

then you need to update your `package.json` file to add a command to test all the test cases with one command. Adding this will work
```
"scripts": {
    "test": "jest"
  },
```
I did have "aha!" moments while writing the test cases. one of them was, none of my function return a value. They all call another function on completion of a the work. 

In the process, I gained much testing knowledge and coding as well as I had to edit my code in some places for better testing of the ssg. I have done testing before on my coop where we use mocha and chai for testing. they are similar to Jest framework but with some changes. I think I will be using Jest testing in my future projects I am thinking of developing a web-extension.
How to test your code without testing your patience.
Published: 2021-11-13 04:48:33

this week I attempted to add testing features to my CLI application which I had created earlier this semester.

I wish I could say this was easy - as I thought it might be.. However, I learned a few things that I will share here. 

### The hurdles:

1. Implement a package that worked with modules (haha - none!);
2. code blocks with absolutely no returns
3. Asynchronous functions
4. Continuous function calls (Russian dolls)


**rule #1:**
To write tests for your code you should have a plan. I can't stress this enough. Due to the nature of this being a lab, I had a deadline - and as you guessed it, it's tonight. However, your planning should start before you start writing your code. You should begin questioning yourself how you want your code to be organized so that it is easier to test. This will really depend on the purpose of your code, and might differ each time. All I know is I was asking myself a few questions such as:

- Why did I use modules?
- Why do I have a function that does something and then enters into another function?
- Why are my functions asynchronous - when it does not need to be?
- Is my code structured as best as possible? (No - I wanted to tear the whole thing apart)



**rule#2:**

Research a test package you want to work with. Know its limitations. Look up the various perks of it. I learned that Jasmine is a bit behind in terms of other test packages such as Jest. I tried to install Jest first, but because i had modules in my code, I was not able to configure this. I read about Jasmine being fine with this, but that was not true either. I ended up changing one file for the testing, and eventually did that for all. I could have used Jest after all, but I was just about done half my tests by then. 



**rule#3**

It's difficult to test asynchronous function calls. I had to use a timeout, but I wasn't too sure this was the best approach either. Timing needs to be taken into consideration into the planning phase of your code. Does your code need to wait for data before being able to continue?



### Results:

In the end, I feel like my tests are still not the best. I rewrote some functions, and tried to add some returns. The structure is clearly poor as there are function calls within function calls creating a blackhole of function calls. As I mentioned before, I wish I had planned that I would be implementing testing into the application. I know I would have paid much more attention to the way I had written my code - which would have helped tremendously. 

In addition, writing the tests did reveal some discrepancies, which I did fix - so my code is a little better than what I started with. 

Learning how to write tests was actually really easy. I had tried to write a few in WEB422 - and remember the syntax is usually not too difficult. I think as you write more tests, and READ more tests you see new things that you can do. Maybe I will find a way to work with asynchronous functions in my tests one day - but for now, my plan is to rewrite the application before I add any more tests.
Learning Workflows: Build a Workflow to Get Notified When a New User Is Created
Tags: nocode, workflows
Published: 2022-02-10 17:53:21

---
title: Learning Workflows: Build a Workflow to Get Notified When a New User Is Created
published: true
date: 2021-11-13 04:31:59 UTC
tags: NoCode,Workflows
canonical_url: https://maxkatz.org/2021/11/12/learning-workflows-build-a-workflow-to-get-notified-when-a-new-user-is-created/
---

This video shows how to build a complete workflow. The workflow will notify in Slack when a new user is created in an organization. Other channels such as email or text message (SMS) can be used as well for notification.

[![Get notified when a new user is created](https://katzmax.files.wordpress.com/2021/11/learningworkflows_newuser_slack.png?w=1024)](https://katzmax.files.wordpress.com/2021/11/learningworkflows_newuser_slack.png)

{% youtube MJbuM700mZQ %}

Want to learn more? Watch other videos in the [Learning Workflows series](https://www.youtube.com/playlist?list=PLSAWywyhniCM6CKkp5vIiD0-pxSbdX71y).
Testing my application
Tags: javascript, testing
Published: 2021-11-13 04:23:40

This week's task is to [add tests]() to my program. I used [Jest](https://jestjs.io/) as my testing tool as it is well-developed and very popular among Javascript users. 

## Setting up Jest
I ran an `npm` command to install `Jest` and added it to devDependencies
```bash 
npm install --save-dev jest
```
I then added a script to `scripts` in `package.json` in order to run `jest`. 
```json
"scripts": {
    "test": "jest --"
  },
```

## Testing the program
I started testing my `index.js` file which is responsible for parsing command line arguments. I had to edit a few pieces of code to make testing easier. Below is an example
```js
describe("Testing parseCommand()", () => {
  reset();
  test("Input file path not specified", () => {
    const error =
      "error: required option '-i, --input <file path>' not specified";
    const option = {};
    const boolean = parseCommand(option);
    expect(finalize(logOutput)).toBe(null);
    expect(finalize(errorOutput)).toEqual(error);
    expect(boolean).toBe(0);
  });
```

The challenging part was `ssg.js` file because I had conflicts between `fs` and `fs.promise` and the way it was written, it was quite hard to test some functions using custom `mock`. I had to edit some code so that I could test one of the functions. Below is one of the tests.
```js 
describe("Testing createHTMLFile() with '.md' file", () => {
  const filename = "file.md";
  const ext = ".md";
  const fileData = `# Javascript Static Site Generator (SSG)

  A Javascript command line program that converts **.txt** and **.md** files into **.html** files.`;
  beforeAll(() => {
    fs.__setMockFileData(`${filename}`, fileData);
  });

  test("'.md' file", async () => {
    ssg = new SSG(null, null, null);
    const res = await ssg.createHTMLFile(filename, ext);
    expect(ssg.toBeGenerated_.length).toEqual(1);
    expect(ssg.toBeGenerated_[0].html).toEqual('<!DOCTYPE html>\n        <html lang="en-CA">\n          <head>\n            <meta charset="utf-8" />\n            <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />\n            <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css" />\n            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/styles/default.min.css">\n            <title>Javascript Static Site Generator (SSG)</title>\n          </head>\n          <body>\n            <main>\n              <div class="mainContent">\n                <h1>Javascript Static Site Generator (SSG)</h1>\n<p>A Javascript command line program that converts <strong>.txt</strong> and <strong>.md</strong> files into <strong>.html</strong> files.</p>\n\n              </div>\n            </main>\n          </body>\n        </html>');
  });
});
```
Through testing, I realized that it's important to break my code into small pieces and to modularize them, I will refactor my code again and add more tests. This week has been quite hectic 😅
Merging objects in Javascript
Tags: javascript, webdev, tutorial, beginners
Published: 2021-11-13 04:22:32

## Using Object.assign

The `Object.assign()` method works by copying over the values and properties of another object (referred to as the source object) into the object we are trying to update (referred to as the target object).

There are several ways we can use `Object.assign()` to merge our objects. The first way is to simply pass in the original object we want to be updated as the first argument and the other object containing the data we want to merge as the second argument.

```javascript
Object.assign(target, source);
```

The problem with this though is that it mutates the original object. So if we don’t want our original object to be mutated we can instead pass in an empty object as the first argument.

```javascript
Object.assign({}, target, source);
```

This will assign all of the properties and values from both the target and source objects into a brand new object.

We can also add more objects as arguments to be merged along with the other objects we’re copying data from. This can be done by passing in the object inline as an argument or defining it first and then passing it in.

```javascript
Object.assign({}, target, source, { name: "Bob" }); // inline

const name = { name: "Bob" }; // predefined object
Object.assign({}, target, source, name);
```

## Using the spread operator

The spread operator is another common method that happens to be more relevant for merging the properties and values of one object into another. I find it to be much simpler and more readable than using `Object.assign()`.

To use the spread operator we precede the object we want to copy data from with `...` when passing it in.

```javascript
const userData = {
  name: "",
  email: "",
  password: ""
};
const newUserData = {
    name: "Bob",
    email: "bob@email.com",
    password: "bobspassword"
};
const updatedUser = {...userData, ...newUserData};
```

This will extract out all of the properties and values merging them into a brand new user object.

If we want to add more properties we can do so just as we did before with `Object.assign()` passing in the property inline or as a predefined object.

```javascript
const updatedUser = {...userData, ...newUserData, updated: true};
```

This will give us a new object with all of the properties merged in and the added property of updated set to true.

```javascript
{
  email: "bob@email.com",
  name: "Bob",
  password: "bobspassword",
  updated: true
}
```

* [Object.assign()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)

* [Spread operator in objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#spread_in_object_literals)
Add testing to SSG 
Tags: osd600, opensource
Published: 2021-11-13 04:17:20

For this lab, I picked [Jest](https://jestjs.io/) as the testing tool for [mh-ssg](https://github.com/minhhang107/mh-ssg). This is a popular Javascript testing framework thanks to its simplicity and ease of usage.

The framework can be easily installed with the following command
```
npm install --save-dev jest
```
Since [mh-ssg](https://github.com/minhhang107/mh-ssg) is using ESLint, I also have to install [eslint-plugin-jest](https://www.npmjs.com/package/eslint-plugin-jest) so that ESLint can work with Jest.
```
yarn add --dev eslint eslint-plugin-jest
```

In `.eslintrc` config file, I added the plugin for Jest and `"jest/globals": true` to the `env` variable.
```
{
   "plugins": ["jest"],
   "env": {
      "jest/globals": true
   },
}
```
I also configured the rules under the rules section
```
{
  "rules": {
    "jest/no-disabled-tests": "warn",
    "jest/no-focused-tests": "error",
    "jest/no-identical-title": "error",
    "jest/prefer-to-have-length": "warn",
    "jest/valid-expect": "error"
  }
}
```

In this lab, I wrote some test cases for `generateHTML.js` and `validateOutputFolder.js` as unit tests. I realized that sometimes the code for testing can be even more than the code itself. Since the program might have several paths and in each path, it could direct even more sub-paths. Effective testing should cover most of these paths, hence, the amount of testing can be too much if we don't know which feature to focus on. For these test cases, I also learned about mocking. To be specific, I created a mock for the `fs` module to test the output folder.

Another thing I learned was to create end-to-end testing. In order to run this, I had to install another module - [execa](https://www.npmjs.com/package/execa). 
```
npm install execa
```

I created `run.js` to execute the program for end-to-end testing.
```
const execa = require("execa");

async function run(...args) {
  try {
    const result = await execa.node("bin/index.js", args);
    return result;
  } catch (err) {
    return err;
  }
}
```
Thinking from a testing perspective, there are a lot of scenarios to be tested since the program allows several options. I was planning to write tests for all scenarios but due to the limited time, I couldn't complete all of them. Currently, only the tests for `--input` are finished and other tests are commented out and I'll find some time to update them soon.
Realize about what is the phone number to chime customer service:
Published: 2021-11-13 04:11:57

Realization bout what is the phone number to chime customer service can help chime customer to the fullest. The proper strategy is the core requirement for managing the chime system, therefore; users should immediately initiate to know about the phone number that may help them to talk to the chime executives. They are experts at offering solutions and required guidance to manage the worst situation. https://www.primotechy.com/chime-customer-service/
How to Destructure Nested JavaScript Objects
Tags: javascript, webdev, programming, tutorial
Published: 2021-11-13 04:07:40

###### How to use destructuring in JavaScript to access deeply nested data


## How to destructure objects

Let’s first go over how to destructure objects in JavaScript. We can start with this simple example of an object representing an employee.

```javascript
const employee = {
    id: 1,
    name: "John Doe",
    occupation: "Programmer"
};
const { id, name, occupation } = employee;
```

This gives us access to all of the properties within the employee object.

```javascript
console.log(id); // 1
console.log(name); // John Doe
console.log(occupation); // Programmer
```

Pretty simple, right?

But what if we have to destructure an object that’s a bit more complex? Maybe one with several levels, meaning objects within objects.

## Destructuring nested objects

Now let’s say we need to access data from an object representing several employees.

```javascript
const employees = {
    engineers: {
        0: {
            id: 1,
            name: "John Doe",
            occupation: "Back-end Engineer"
        },
        1: {
            id: 2,
            name: "Jane Doe",
            occupation: "Front-end Engineer"
        },
    }
};
```

Here we have our employees object nested several levels deep. If we need to access an employee’s info we can destructure as many levels as it takes to get to our employee object’s properties.

```javascript
const {
    engineers: {
        1: {
            id,
            name,
            occupation,
        },
    },
} = employees;
```

Now we have access to all of the second employee object’s properties.

```javascript
console.log(id); // 2
console.log(name); // Jane Doe
console.log(occupation); // Front-end Engineer
```

## Summary

Destructuring is a very useful feature that was added to the ES6 version of JavaScript. With destructuring, we can quickly and conveniently extract out properties or data from objects and arrays into separate variables.

This was just a brief overview of how to use destructuring to extract out and access data from nested JavaScript objects.
Which Programming Language Should You Learn in 2022?
Tags: programming, career, computerscience, beginners
Published: 2021-11-13 03:57:20

This is the question I used to ask when I was starting to learn programming.
And I think not only me but everyone has this question at some point.

It’s because we want to secure our job, which means we want to get a job as soon as we learn a specific programming language.

And it’s normal as a human being that nobody wants to spend time for nothing.

So, if you want to learn programming language and get the job as soon as possible then look for the requirements or vacancies available near your location or where you want to work.

And based on that you can choose any programming language and hone your skill.

In a country like ours (Nepal) PHP programmers are highly required because most of the projects (websites) here are built with Wordpress or PHP frameworks like Laravel and CodeIgniter.

## And why are they popular?
Because the development cost is cheaper, you can develop and host the sites at low cost.

Besides PHP, vacancies for asp.net, Django (python), MEAN stack, flutter, etc. are also on rise.

So my first suggestion is **look for the vacancies available** in your area and then you can choose a programming language.


## Every programming language has its strengths and weakness

So if you’re learning programming then don’t deviate from it, just keep learning and excel at it.

TBH, none of the programming languages is the best or worst.

So you can [learn any programming language] (http://bit.ly/vijay-thapa-online-courses). If you become good at a language then it won't be that hard to learn another language (if you want to shift).

Logic is the same in every programming language, the only difference is syntax.

First **find the technology you're interested in**, like Web App, Mobile App, Desktop App, Data Science, AI, Blockchain, etc. and then choose programming accordingly.

For me, it was **Hit-and-Trial**.

I started with C, then learned C++, C#, Java (Android), Asp.net, PHP, etc. in college. And among them I found [PHP the easier language] (https://bit.ly/food-order-website-php) (It might be different for you).

So, focus on one programming first, you can always shift to another language within months once you're good at one programming language.



## Summary
Choose programming language
1. Based on the no. of vacancies
2. Based on Technology you’re interested in
3. Hit and Trial


**What do you think 🤔 ?** 
Let me know in the comment below 💬

## You may also like 👇
{% link https://dev.to/vijaythapa/how-to-make-food-ordering-website-l9a %}
GETTING STARTED WITH FIRST API AND DOCKER
Published: 2021-11-13 03:27:24

**

## What Is Fast API?
**

Fats API is a Python framework for developing web applications and deploying machine learning models.

It is now one of the fastest web frameworks in Python. It speeds up feature development by roughly 200 percent or more.

Because of its strong editor support, Fast API allows you to spend minor time troubleshooting. 

Learning Fast API is simple since it was designed to be that way. As a result, you can spend less time reading documentation and more time coding. 

You also don't need to write much code because it can figure out many things for you.

**

## What is Docker? 
**

Docker is a technology for automating the deployment of applications in a lightweight container to run efficiently in a variety of environments.

The container is a software package that includes all of the requirements needed to run a program. 

On the same hardware, many programs can execute:

- The canisters are kept in separate locations.
- They are quick and straightforward to set up.
- Their output is high.

So, what is the issue that Docker is attempting to solve in the development world?

Whenever a developer creates a product, there are particular challenges that nearly always exist. 

One of these issues is that when you build a project, it works well on your machine, the development machine, but it fails to work as soon as it is moved to the production stage, to servers or another developer's workstation.

The classic problem that Docker is intended to answer is the 'it works on my machine.' You've undoubtedly used or heard this term from another developer at some point in your development career. 

It is compatible with practically any language, including Python.

Docker supports completely sealed containers. 

Docker's heart is made up of containers. These containers encapsulate your entire code and are portable. 

Take that container and place it on any machine. It will work exactly as it does on your machine since, as we previously discussed, Docker is compatible with practically all frameworks.

Docker also enables social containers. They, like your social status, can be shared. Isn't it cool? 

The best thing is to share your creations on Instagram, Twitter, and other social media platforms. Again, cool, isn't it?

The Docker containers are packed up with your: 

1. Code
2. Process 
3. Networks
4. Configurations
5. Dependencies
code every day with me
Tags: javascript, programming, 100daysofcode, algorithms
Published: 2021-11-13 03:05:16

##--DAY 19--
Hi, I am going to make #100DaysOfCode Challenge. Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
**Now let's solve problem today:**
Problem: Picking Numbers
Detail: [here](https://www.hackerrank.com/challenges/picking-numbers/problem)
My solution(javascript):
- Using sort:
```
function PickingNumbers(){
    let max=1,tmp=1,idx=0;
    for(let i=1;i<a.length;i++){
        if(a[i]-a[idx]<=1) tmp++;
        else{
            idx=i;
            tmp=1;
        }
        max=(tmp>max)?tmp:max;
    } 
    return max;
}
```
- Using hash map:
```
function pickingNumbers(a) {
    let max=1;
    let map = new Map();
    for(let number of a){
        if(map.has(number)){
            map.set(number, map.get(number)+1);
        }
        else map.set(number, 1);
    }
    for(const [key,value] of map){
        let tmp=value;
        if(map.has(key+1)) tmp=map.get(key)+map.get(key+1);
        if(tmp>max) max=tmp;
    }
    return max;
}

```
-->*If you have better solution or any question, please comment below. I will appreciate.*
A Fun Programming Joke To Start Your Day
Tags: jokes, dailydeveloperjokes, watercooler
Published: 2021-11-13 01:37:43

---
title: "A Fun Programming Joke To Start Your Day"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes, #watercooler
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1258a197fb7.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit._

<!--
Joke text:
___Q:___ Whats the object-oriented way to become wealthy?

___A:___ Inheritance
 -->