teleren/devto huggingface dataset:
Testing Promise Rejection with Chai
Tags: javascript, testing
Published: 2022-02-01 15:57:19

I've been using [chai](https://www.chaijs.com/) to test my application, but today i faced a curious problem. I've been testing if the exception thrown in the try/catch matches with i expect, let’s check a snippet of my test code:

```javascript
it('Test if validate the customer externalId', function() {
  let flawedCustomerArgs = [{
    name: 'John',
    details: 'test'
  }]
  
  // we need to bind the parameters flawedCustomerArgs, 
  // because in the execution context the cai method "expect"
  // will invoke the "importCustomer()" method
  chai
    .expect(ImportService.importCustomer.bind(ImportService, flawedCustomerArgs))
    .to
    .throw('Field externalId not defined for Customer');
})
```

But let's suppose that now i need my method _importCustomer_ to be async, the snippet code above won't work, because it will return a promise and the exception that i'm expecting is coming in the Promise Rejection.

**How can i get this rejection in the chai?**

If we don't want to change our previous script too much, we can declare our rejection in the test file, like this:

```javascript
it('Test if validate the customer externalId', function() {
  let flawedCustomerArgs = [{
    name: 'John',
    details: 'test'
  }]

  ImportService.importCustomer(flawedCustomerArgs)
    .then(result => (...))
    .catch(error => {
       chai
        .assert
        .equal(error, 'Field externalId not defined for Customer')

    })
})
...
```

But instead i used the [chai-as-promised](https://www.npmjs.com/package/chai-as-promised) library, that allow us to get rid of writing expectations to promise in the test file and focus only in the result, like this:

```javascript
const chai = require('chai');
const chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);

it('Test if validate the customer externalId', function() {
  let flawedCustomerArgs = [{
    name: 'John',
    details: 'test'
  }]
  chai
    .expect(ImportService.importCustomer(flawedCustomerArgs))
    .to
    .be
    .rejectedWith('Field externalId not defined for Customer');
})

```

If you think that there's something confusing, or impacting the understanding, or that i can improve, please i'm going to appreciate your feedback.

See you guys and thanks a lot
Blog Post 11 Anatomy of routes.rb
Published: 2022-02-01 15:42:22

Hello all! Since my last blog I have been digging deep into understanding Rails using VScode.  The language seemed familiar from Ruby when I took the lessons at CodeCademy.  

A couple of things I have learned in Rails is R.E.S.T. and GET.
Understanding the connection of the Request method and Path on how they make up the first half of a Rails route.  The second part/half is the route action, the Ruby class and method that will take care of the incoming request. 

```Rails.application.routes.draw do
     # verb 'path', to: 'controller#action'
     get '/books', to: 'books#index'
   end```


I was able to break down the code by understanding that the verb was "GET", the 'path' was '/books', and the controller#action was the 'books#index' line.  This code reminded me of the Ruby language I was learning in Codecademy and I was able to remember it but also apply it in a new curriculum I am learning with Rails.
Getting Started with Microsoft Azure
Tags: azure
Published: 2022-02-01 15:26:50


Want to start your first project with Azure Functions? Have a look here: {% link https://dev.to/bascodes/use-azure-functions-to-periodically-download-your-tweet-stats-30i4 %}


[![screen shot 2022 02 01 at 12 34 13](https://bas.codes/static/8e2d86f6a2a55df0484233dfdc434630/d9199/screen-shot-2022-02-01-at-12.34.13.png "Microsoft Azure: 40 Services Free Forever + 200$ Credit")](/static/8e2d86f6a2a55df0484233dfdc434630/c211c/screen-shot-2022-02-01-at-12.34.13.png)

Starting with Microsoft Azure is free. Usually, you’ll get a $200 credit for your first 30 days. And even after this period, you’ll have access to popular services for free for the first 12 months and you can use approx. 40 services for free forever.

You can sign up directly on [azure.microsoft.com](https://azure.microsoft.com/en-us/free/)

## [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#install-software)Install Software

### [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#cli)CLI

To create resources in Azure from the command line, you’ll need the Azure CLI tools.

Installation guides are available for

- [macOS](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-macos)
- [Windows](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli)
- [Linux](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=script)

### [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#vscode)VSCode

If you use [VSCode](https://code.visualstudio.com/) (which I strongly recommend), the Azure extensions are really handy helpers for every workflow related to Azure.

The [Azure Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-node-azure-pack) extension comes with functionality for almost every service of Azure inside VSCode.
GitHub Action Runners
Tags: github, git
Published: 2022-02-01 15:17:26

I've been doing a lot of learning around GitHub Actions lately.  And being the techie that I am I have spent some time in the documentation understanding how they work under the covers and it was really interesting reading about the runners that GitHub Actions use. 

## What is a GitHub Actions Runner?
A GitHub Actions runner is the virtual server or environment that runs the job and steps that are specified within a GitHub Actions workflow. 

You can either use the built in runners or specific a self-hosted runner. 

## GitHub hosted GitHub Action Runners
GitHub hosted runners are either Linux, or Windows virtual machines that are hosted in Microsoft Azure.  They are typically using the Standard_DS2_v2 virtual machine size. The macOS runners are hosted in GitHub's own macOS Cloud. 

The benefit of using the GitHub hosted runners is you don't have to take care of the infrastructure or patching of the operating system.  That is all taken care of for you. 

## Self-hosted GitHub Action Runners
You can run your own runners if you have a need to control that side of things. The one word of advice or warning that GitHub place here is that if you are using self-hosted runners only configure them on your Private repositories.  

If you run a self-hosted runner on a public runner there is a chance that someone could run malicious code on that machine with a pull request.  So it's something to bear in mind when using a self hosted runner. 

Configuring your own GitHub Action Runner is a straight forward process.  You can find more information if you click on Settings > Actions and then Runners from within one of your repositories. 
The process is: 

- Build your self-hosted runner, such as a Windows or Linux or macOS server/machine. 
- Install the GitHub Actions software and follow the configuration steps. 
- Start to use it in your workflows!

To use your self-hosted runner in your GitHub Actions workflow you need to use the following code: 

```yml
runs-on: self-hosted
```

Below is one of my private repositories and I have a self-hosted runner configured to pick up any actions that are run there:

![GitHub self hosted runner](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sqswpx6fvd49qpb0uryk.png)
D8: An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier
Published: 2022-02-01 15:14:48

i am building application for Android 12 device. JDk used ; 11. my gradle file looks like

minSdkVersion 31
buildToolsVersion "31.0.0"
compileSdkVersion 31
targetSdkVersion 31

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_11
}

Still seeing D8: An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier

ALso tried with 8. still same issue is seen 

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
How to Use Google to Download Fast from Slow Sites or Mirrors?
Published: 2022-02-01 15:13:04

So... You want to download a Large file of about assume 500 MBs. But The Site is very slow and You Are Getting A Lot Slower download speeds than usual (assume 1 MB/s). 
The Just Use Google Colab (google has pretty high speeds ngl)

## But How?
### Don't Know How to Do it Follow the steps:
1) Go to [Google Colab](https://colab.research.google.com/) (Obviously...)
2) Create a New Notebook
3) In the first cell write the following code:

```
!wget <url>
```
change the url according to the *direct download url* (Redirecting urls will not work)

4) Run the cell and wait till it download
5) In a New Cell write the following code to check the filename of the file downloaded

```
!ls
```
Copy the filename to your clipboard

6) In a New Cell We Have to download the file. Write the following code

```python
from google.colab import files
files.download('<filename>') 
```
Change the filename with the name you copied

7) Run the cell and you will see a bar in the output showing your progress. After Some time You will get a save file prompt to finally save the downloaded file to your computer.

#### With this Technique You could now Skip the 2-3 days download time for just 500 MBs to your usual time.
Working around CORS in create-react-app
Tags: webdev, frontend, cors, javascript
Published: 2022-02-01 14:48:47

One problem we often face as frontend developers is dealing with CORS when making API requests.

##What is CORS?

CORS (Cross-Origin Resource Sharing) is essentially a mechanism that allows a server to express what other domains can make requests to it. For example, my app could be hosted on `http://domain-a.com`, so only requests made from that same domain are allowed. If another app hosted on `http://domain-b.com` tried to make a request to `http://domain-a.com`, it would fail depending on the CORS policy.

##Where does CRA fit in?

While using CRA (create-react-app), I've often run into a situation where I want to test my local changes against another team's API endpoint. I mean, there's only so much mocking you can rely on! By default, CRA runs locally on `http://localhost:3000`, so if I try to make an API request out to `http://domain-a.com/users.json`, CORS would block it. However, when developing locally, CRA lets us get around this by proxying all unknown requests to a specified domain. This can now help us make sure our frontend code lines up with the backend's responses. 

##What's the workaround?

All we need to do is add one new field in `package.json`. For example:

`"proxy": "http://domain-a.com",`

After you restart your CRA dev server, you should now be free to make requests to `http://domain-a.com/users.json`. This will of course only work locally and you should only make requests to a dev API endpoint, not production. That's it!

##Want to see more?

I mainly write about real tech topics I face in my everyday life as a Frontend Developer. If this appeals to you then feel free to follow me on Twitter: [https://twitter.com/cmacdonnacha](https://twitter.com/cmacdonnacha)

Bye for now 👋
Python challenge_15
Tags: programming, python, tutorial, beginners
Published: 2022-02-01 14:24:10

##All equal

Define a function named all_equal() 
that takes a list and checks whether all elements in 
the list are the same.

For example: 
calling all_equal([1, 1, 1]) should return True.

[Challenge URI](https://pythonprinciples.com/challenges/All-equal/)

####My solution
```
def all_equal(equal_list):

    result = all(element == equal_list[0] for element in equal_list)

    if (result):
        return True
    else:
        return False
print(all_equal([1, 1, 1]))
```

####Aother solution 
```
def all_equal(items):
    for item1 in items:
        for item2 in items:
            if item1 != item2:
                return False
    return True
```

All the best to you.
Thinkific vs Teachable vs MemberPress
Published: 2022-02-01 14:15:36

_If you want to sell courses as part of your business, choosing a quality learning management system (LMS) is key. It's important to make sure the platform you use has everything you need to set up engaging lessons, promote your classes, and collect payments.
Fortunately, if you've narrowed your options down to Thinkific vs Teachable vs MemberPress, you're on the right track. Each of these LMS solutions provides valuable features that can help you succeed._



**Features: Teachable**

Teachable is a platform that enables you to create and upload online courses for an unlimited number of students. Using Teachable, you can set up a branded or unbranded membership website for your online classes:
This solution enables you to build courses that include as many individual lessons as you want. You can also upload videos, text documents, audio recordings, and more. You can even design quizzes and certificates for graduating students.



**Features: Thinkific**

Thinkific is an LMS that enables you to set up a membership website and then publish your online courses to that site. The Thinkific platform stands out due to its user-friendly approach to course design:
With Thinkific, you can create classes and design a curriculum using an intuitive drag-and-drop builder. You can also create and upload multiple types of content for your lessons, including videos, quizzes, surveys, Google Docs, and Typeform forms.



**Features: MemberPress**

MemberPress is a bit different from the LMS solutions we've explored so far. Instead of a standalone platform, the MemberPress Courses add-on enables you to take any WordPress website and transform it into a learning portal.
Using this tool, you can design classes and craft a curriculum using WordPress' familiar post editor. You can then publish this content to your existing WordPress website (or a brand-new site). 
Since this is an add-on to the MemberPress plugin, it’s easy to restrict access to your content based on a subscription model. This enables you to control who has access to your online courses. You could even turn your knowledge into profit, by selling subscriptions to your e-learning content.


**Reference Blog**
[https://www.gomahamaya.com/thinkific-vs-teachable-vs-memberpress-vs-skillshare/](https://www.gomahamaya.com/thinkific-vs-teachable-vs-memberpress-vs-skillshare/)
Define default local maven properties
Tags: todayilearned, java
Published: 2022-02-01 14:09:31

Working with pipelines which are abstract from the projects and environments can be really useful, but for the dev, it can be really annoying. 

In a context of a maven project, all the variables added with **-D** parameters should be added by the dev to his commands right?

> **No!**

With **Maven** projects, there are 2 ways to counter that.

---

*For our solutions, we will take the following **pom.xml** part to understand what we should do.*
```xml
<project>
  ...
  <properties>
    <mavenVersion>3.0</mavenVersion>
  </properties>
 
  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-artifact</artifactId>
      <version>${mavenVersion}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-core</artifactId>
      <version>${mavenVersion}</version>
    </dependency>
  </dependencies>
  ...
</project>
```

---

## Default value in the pom
In the previous example, we can define a **property** "**mavenVersion**" which can contain our default value. 

```xml
...
  <properties>
    <mavenVersion>2.10.5</mavenVersion>
  </properties>
...
```

In this case we need to know that if **the same parameter is defined in the command line, the value in the command line will override this one!**

So you can keep something in your **pom.xml** file without any issue.

---

## Default value in the settings.xml

In the case where you can't keep the value in the **pom.xml** file, or **if you have the same required parameter for a lot of projects**, you can set it **in your settings.xml file!**

```xml
...
<profiles>
    <profile>
      <id>my-profile</id>
      <properties>
        <mavenVersion>2.10.5</mavenVersion>
      </properties>
      ...
    </profile>
</profiles>
...
```

---

Restart your IDE, refresh your maven configs, and everything should be fine!

I hope it will help you! 🍺

---

<center><h3>You want to support me?</h3></center>
<a href="https://www.buymeacoffee.com/mxguilbert7" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
Format Specifiers and Escape Sequence in C Language
Published: 2022-02-01 14:05:59

# What is Format Specifier
The format specifier is a way to tell your compiler what type of data are you dealing with. It is used while inputting and outputting any data. For all format specifiers, you can check this [chart](https://cdn.hashnode.com/res/hashnode/image/upload/v1643123291697/zwAw5c5m3.png?auto=compress,format&format=webp) or complete article [here](https://www.codewithrish.com/data-types-and-variables-in-c) 

# General Syntax in printf()
> printf("%a.b{formatSpecifier}", yourvariable); 

where `a` and `b` are integers where a tells total character spaces for output and b tells the accuracy after the decimal.

Let's look at this code for more details

```
#include <stdio.h>
int main()
{
    float b = 5.63;
    printf("%6.3f\n", b);
    return 0;
}
// output
 5.630
``` 
In the above code, there `a=6` and `b=3` means we will have 3 decimal places and if we look closely there is 1 space before 5 in the output 4 character spaces by `5`, `6`, `3` and `0` and fifth by `.` but we said 6 so it added a space before because a was positive if a would have been negative it will add spaces after the output.
 
# General Syntax in scanf()
> scanf("%{formatSpecifier}", &yourvariable); 

Sample Code

```
#include <stdio.h>
int main(){    
    float a;
    printf("Enter a number: ");
    scanf("%f", &a);
    printf("Your Input Is: %7.3f", a);
    return 0;  
}    
// output
Enter a number: 5.32
Your Input Is:   5.320
``` 

# What is Escape Sequence
In C, an escape sequence is a character sequence that cannot be used directly in a string literal. You need more character starting with backslash \. For example, \n represents new line.

## List of Escape Sequence in C

![Escape Sequence.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1643722830752/It7PPrh20.png)

Sample Code

```
#include <stdio.h>
#include<stdio.h>    
int main(){    
    int number=50;    
    printf("We\nareC\b learning\t\"C\" programming here \'on\' CodeWithRish");
    return 0;  
}    
// output
We
are learning    "C" programming here 'on' CodeWithRish
```
Crashing Instagram with a Message!
Tags: instagram, hack, trick, discuss
Published: 2022-02-01 14:02:25

Yes you read it right.

You can crash anyone’s Instagram by sending them a DM.

I will straight come to the point.

If you copy pasted below message in friend’s DM and when he clicks on it his Instagram crashes.

**Reason?**

The characters of this message have not been indexed in Instagram.

Instagram needs to index every language and special characters. But when new character is indexed in Instagram DM it can't recognise it.

*This message is a mobile strucking message*

> ۦོ͢⇣͢✰͢↬ÂмRØ^^O̷ ꦿ⃕O̷↬ۦོ͢✰͢⇣͢✘͢͢⁦ ✘͢͢ۦོ͢✘͢͢ۦོ͢⇣͢✰͢↬ÂмRØ^^O̷ ꦿ⃕O̷↬ۦོ͢✰͢⇣͢✘͢͢⁦ ✘͢͢ۦོ͢✘͢͢ۦོ͢⇣͢✰͢↬ÂмRØ^^O̷ ꦿ⃕O̷↬ۦོ͢✰͢⇣͢✘ ✘͢͢ۦོ͢⇣͢✰͢↬ÂмRØ^^O̷ ꦿ⃕O̷↬ۦོ͢✰͢⇣͢✘͢͢⁦ ✘͢͢ۦོ͢✘͢͢ۦོ͢⇣͢✰͢↬ÂмRØ^^O̷ ꦿ⃕O̷↬ۦོ͢✰͢⇣͢✘͢͢⁦ ✘͢͢ۦོ͢✘͢͢ۦོ͢⇣͢✰͢↬ÂмRØ^^O̷ ꦿ⃕O̷↬ۦོ͢✰͢⇣͢✘ ✘͢͢ۦོ͢⇣͢✰͢↬ÂмRØ^^O̷ ꦿ⃕O̷↬ۦོ͢✰͢⇣͢✘͢͢⁦ ✘͢͢ۦོ͢✘͢͢ۦོ͢⇣͢✰͢↬ÂмRØ^^O̷ ꦿ⃕O̷↬ۦོ͢✰͢⇣͢✘͢͢⁦ ✘͢͢ۦོ͢✘͢͢ۦོ͢⇣͢✰͢↬ÂмRØ^^O̷ ꦿ⃕O̷↬ۦོ͢✰͢⇣͢✘ ✘͢͢ۦོ͢⇣͢✰͢↬ÂмRØ^^O̷ ꦿ⃕O̷↬ۦོ͢✰͢⇣͢✘͢͢⁦ ✘͢͢ۦོ͢✘͢͢ۦོ͢⇣͢✰͢↬ÂмRØ^^O̷ ꦿ⃕O̷↬ۦོ͢✰͢⇣͢✘͢͢⁦ ✘͢͢ۦོ͢✘͢͢ۦོ͢⇣͢✰͢↬ÂмRØ^^O̷ ꦿ⃕O̷

_Comment Below_ 
*Did you send to your friend ?*
Follow us on [Instagram](instagram.com/zastixx)
Follow us on [Instagram](instagram.com/tkuttam_starboy)
Visualize the architecture of your Node.js app in under 5 minutes
Tags: node, javascript, architecture, vscode
Published: 2022-02-01 13:48:10

{% youtube qFjBiLVGXgg %}

[AppMap](https://marketplace.visualstudio.com/items?itemName=appland.appmap) is an open source VSCode extension which helps you improve your code by showing you how it really behaves, feature by feature, as you work. It does this by automatically generating beautiful, interactive maps of architecture and code behavior right in your editor.

This less-than-5-minute video shows how install the AppMap extension, how to configure it to map your Node.js code, and how to navigate your code using the interactive diagrams.

It uses an Express.js app as an example program. 

For full usage instructions, check out [the AppMap documentation](https://appland.com/docs/quickstart/).