teleren/devto huggingface dataset:
A Sieve of Eratosthenes TypeScript implementation
Tags: typescript, algorithms
Published: 2020-10-20 08:22:30

The [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) is an algorithm for finding all prime numbers between 2 (the smallest prime number) and a given limit, n. It has a time complexity of O(n log log n). The gist of the algorithm is to mark off all multiples of primes inside this range,leaving only the prime numbers themselves.

## The Algorithm

For this example, let n = 10.

Step 1: Create a list of all numbers between 2 and n.

```typescript
[2, 3, 4, 5, 6, 7, 8, 9, 10]
```

Step 2: Set p = 2.

Step 3: Mark off all multiples of 2 (excluding 2) until n leaving the following:

```typescript
[2, 3, 5, 7, 9]
```

Step 4: Assign the next smallest number that hasn't been marked in the previous operation to p. Repeat from step 3.

In this case, the next p is 3. We can safely assume that number is prime. Marking off multiples of 3, we are left with the following array:

```typescript
[2, 3, 5, 7]
```

Step 5: If there isn't any number left that hasn't been marked off, the algorithm is done. The unmarked numbers are the primes between 2 and n, inclusive. Our final output is:

```typescript
[2, 3, 5, 7]
```

## The Code

Here are a few test cases to check that our implementation does what it's supposed to do. The test setup is Enzyme + Jest.

```typescript
import { sift } from "../../lib/sieve"

describe("Sieve of Eratosthenes", () => {
  test("sift(0) returns an empty array", () => {
    expect(sift(0)).toEqual([])
  })

  test("sift(2) returns [2]", () => {
    expect(sift(2)).toEqual([2])
  })

  test("sift(10) returns all primes less than 10", () => {
    expect(sift(10)).toEqual([2, 3, 5, 7])
  })

  test("sift(11) returns all primes between 2 and 11", () => {
    expect(sift(11)).toEqual([2, 3, 5, 7, 11])
  })
})
```

And finally, the implementation:

```typescript
interface PrimesHash {
  [index: number]: boolean
}

export const sift = (limit: number): number[] => {
  if (limit === 2) return [2]

  // Step 1: create an array from 2..limit inclusive
  let allNums: number[] = Array.from({ length: limit - 1 }, (_v, k) => k + 2)

  // Step 2: set p = smallest prime
  let p = 2

  // create a hash of { number: boolean }, from the array created in step 1,
  // setting every value to true
  let primes: PrimesHash = allNums.reduce((hash: PrimesHash, num: number) => {
    hash[num] = true
    return hash
  }, {})

  // Step 4: find the next smallest prime and repeat step 3
  while (p <= limit) {
    if (primes[p] === true) {
      // Step 3: mark off all multiples of p. We start from p*p as
      // an optimisation
      for (let i = p * p; i <= limit; i += p) {
        primes[i] = false
      }
    }
    p++
  }

  // Step 5: return all unmarked numbers
  return Object.keys(primes).reduce((array: number[], key) => {
    if (primes[+key] === true) {
      array.push(+key)
    }

    return array
  }, [])
}
```

This was a fun algorithm to implement 🎉.
Day 5: CORS Setting for REST API in ReactJS
Tags: springboot, react, heroku
Published: 2020-10-20 08:09:36

## Intro
Please note that this solution is only applied for REST API that is developed using Spring framework, such as Spring Boot.

## Dev Environment
- React JS
- Spring Boot
- Axios
- Heroku

## Problem
```
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
```
I have problem when calling REST API, deployed in Heroku, from localhost of my ReactJS web application. 

## Solution
Simply add annotation in the controller backend. Please refer to [reference](#references) below.

```
@CrossOrigin(origins = "http://localhost:3000/", maxAge = 3600)
@RestController

.....

```

Actually I took the wrong approaches when looking for solution. If you simply copy paste the error from browser, the result will bring you to another solution. Some said to add certain value in header of the request data, some said to create cors proxy, etc.

That is not wrong, but not applicable for my problem. Honestly I've tried everything I found, but nothing works. Then suddenly I got a light bulb. The other solution said that other than client side, if you developed your REST API, then it is more simpler to add the cors setting from backend side. Then I searched the solution for Spring Boot :)

Its another story if we consume the available api. Then it might be more complicated.

## References
[Tutorial](https://www.baeldung.com/spring-cors)
My Pilot attempt at HactoberFest-2020
Tags: hacktoberfest, opensource
Published: 2020-10-20 04:19:41

## What I Learned From Hacktoberfest

Hey everyone! 
I was always amazed by the turf of opensource and always wanted to give it a shot. But, I never had the confidence or the motivation to try it out.
This time, I decided to take the leap of faith and give it a try. What better time than the month-long celebration of OSS? 

I registered for the event, read the rules, and found the resources extremely useful. Within no time, I had my first PR ready! This gave me the confidence to search for repos that might have issues that fall in my skill stack. To my surprise, there were plenty of them. I kept searching for such issues and solved a few of them a within just a few days into the process, I already had a total that crossed the threshold of 4 PRs. I made a total of 9! This happened without me realizing that I had unofficially completed the fest. I just couldn't stop. 

The next few days of the review was the hardest to pass. I was constantly looking at the profile to see how long till they get merged :3. Finally, all of them got merged just today!

I had a really fun time & I am taking back a lot of learning and experience from this fest. I hope to participate in future editions as well and contribute to the world of open-source not only for a T-Shirt but also as a passion. 

My only advice to whoever is reading this is - If you have not already tried open-source, what are you waiting for? Go for it!
You can contribute in plenty of ways, you need to be a top coder to contribute to coding based repos, you can add documentations if you are good at explaining concepts, you can add poems like haiku, and much more!

Cheers, 
Amogh Rajesh Desai!
Ecommerce website development cost for small businesses
Tags: ecommerecestorecost, ecommercestorebuilder, onlinestorebuilder
Published: 2020-10-20 06:44:57

Everyone knows that launching an ecommerce store can help multiply sales and profits but small businesses don’t take the digital leap fearing huge [ecommerce website development cost](https://www.techosquare.com/blog/ecommerce-website-development-cost-breakdown).  


While it obviously costs money to launch an online store, the pricing is something that can be debated for hours. That’s why we decided to unveil the mystery behind ecommerce store development costs. 


Read on to know what determines the estore pricing:


**Ecommerce store size**


The size of an ecommerce store depends upon the number of products you are selling and the type of shopping you are running (multi vendor or single-seller). A small business with a product list of 20-50 items won’t have to spend big on building an online shop. However, if you wish to host thousands of products, be prepared to shell out more. 

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

**Freelancer or agency**


Hiring a freelance web developer to create a simple no-frills online store can cost less than 1000 USD. However, collaborating with a well-renowned eCommerce web development company to build a feature-rich online store will cost tens of thousands of dollars. 


Here’s the complete [list of ecommerce store features](https://www.techosquare.com/ecommerce-playbook) for your eyes only.


**From scratch or technology**


There are a lot of online store development technologies out there that help entrepreneurs launch online shops at rock bottom cost. Swiftkart is currently the most powerful yet affordable solution to [launch online stores](https://www.livechat.com/success/launching-online-store/) in a jiffy. In case you choose to build the store from scratch, be prepared to shell out more. 


**Performance & scalability**

Everyone wants their online store to grow big. A lot of businesses however lag behind because they make the wrong technology choice in the beginning. Hosted solutions usually bring scalability challenges and caps growth for online sellers as well as entrepreneurs. 


We hope our quick e-commerce website development cost guide for building powerful stores helped you! Email at info@techosquare.com to inquire about the most online store launcher of 2020


Want to start a multi-vendor store? Here’s everything you need to know about [multi vendor marketplace platform](https://www.techosquare.com/blog/multivendor-marketplace-platform)
Request using node-fetch with async/await
Tags: node, javascript, fetch
Published: 2020-10-20 08:08:12

You might have used fetch on client side applications. To use fetch on server side we can use [node-fetch](https://www.npmjs.com/package/node-fetch) library. Let me show basic examples using async/await .

**GET request**
```
const fetch = require('node-fetch');
async function get_request(){
  const url = 'http://get-request-url.com'
  const res = await fetch(url);
  const data = await res.json();//assuming data is json
  console.log(data)
}
```
**POST request**
```
const fetch = require('node-fetch');
async function post_request(){
  const url = 'http://post-request-url.com'
  const body = {some_var:"some_value"}
  const res = await fetch(url,{method:'POST',body:JSON.stringify(body),headers: { 'Content-Type': 'application/json' }});
  const data = await res.json();//assuming data is json
  console.log(data)
}
```
Making an HR software with Spring Boot Part V
Published: 2020-10-20 08:00:37

Now, let's talk about a topic that's *not so* near and dear to my heart: relationships :grimacing:. Of course, I'm talking about the only relationships that programmers are really good at ... database relationships!

Anyway, before we go into that, there's something I forgot to put at the end of the `application.properties`. Copy paste this line:

`spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect`

I'll not be explaining what this line does (*I'm lazy lol*). Now that we're done, let's continue on to relationships... (*cough cough*). Right, we know that an **Employee** has a **Job**, and is under a **Department**, is allowed to take many **LeaveDays**, and can **misbehave** multiple times. From this alone, we now have our database relationships...

Open the Employee.java and paste the following code (*which of course I won't be explaining...*):

```java
...

@OneToOne
@JoinColumn(name = "job_id")
private Job job;

@OneToOne
@JoinColumn(name = "department_id")
private Department department;

@ManyToMany
@JoinTable(name = "employee_misconducts", 
joinColumns = @JoinColumn(name = "employee_id"),
    inverseJoinColumns = @JoinColumn(name = "misconduct_id"))
private List<Misconduct> misconducts;

@OneToMany(mappedBy = "employee")
private List<LeaveDay> leaveDays;

...

```

Open Job.java and put the following code:

```java

...

@OneToMany
private List<Employee> employees;

...

```

When you're done with that, put the following code inside LeaveDay.java:

```java

...

@ManyToOne
@JoinColumn(name = "employees_ecnumber")
private Employee employee;
...

```

Afterwards, put the following code inside Misconduct.java:

```java

...

@ManyToMany(mappedBy = "misconducts")
private List<Employee> employees;

...

```

And with that, we can say we're done-ish. Obviously, there are a lot of things that can be improved, but then again, we're not perfectionists ( *I know I'm not!* ). Anyway, in the next tutorial, we are going to finish up on the API by making repositories, controllers and DTOs. Enjoy your day ... or night ... chao :wave:
Introduction to Machine Learning 
Tags: machinelearning
Published: 2020-10-20 07:56:03

Let start by defining, what is machine learning, it is the science of programming computers so they can learn from data.

#Machine learning is great for:
* Problems whose current solution are lengthy.
* Tackling complex problems, for example, determining whether the person is happy or not when a word is shown to them through the scans(showing the activity of different parts of the brain).
* Fluctuating environments: for example predicting stock price (it changes from time to time).
* Getting insights into the complex problem.

There mainly four types of Machine Learning Systems so let discuss them one by one.
#Types of Machine Learning Systems:
**1)Supervised Learning**: In this type of learning, training set(data on which model is trained) is fed to the algorithm with labels.

**2)Unsupervised Learning**: In this type of learning, the solution is not given that is only data (without any labels or solutions) is fed to an algorithm and it learns from it. It is like observing the world around you and learning about how the world works without any guidance.

**3)Semi-supervised learning**: In it, the data has few labelled instances but have many unlabelled instances and algorithm is trained on this data.

**4)Reinforcement learning**: Let's say, a dog trainer wants to train a dog. The trainer will give a reward (a small candy or something else) to the dog whenever the dog acts according to trainer's wish and punish(by not giving the reward) the dog when the dog does not perform the according to trainer's will. By the end of the training, that dog will know what to do to get a treat. Same is the case in reinforcement learning, it learns in the same way. 

Now let talk about common challenges in Machine Learning.

#Challenges in Machine Learning:
**1)Nonrepresentative training data**: As you might have already guessed it, if your training data is not representing what you are trying to predict, then your model will have miserable performance.

**2)Poor-Quality of Data**: If your data is full of outlier and noise then don't expect good performance from your model. Try to remove outlier and/or the source of noise like a broken sensor etc.

**3)Irrelevant features**: Try to remove the useless feature from data and try to make some useful features from existing features.

**4)Overfitting the data**: Let's say you train a model and you get great performance and you put it in use but it does not perform as expected, why it happened, well your model just performed well on the training set but it does not generalize well.

**5)Underfitting the training data**: Underfitting is just opposite of overfitting. The model is too simple to learn from the data.
Mistakes were made and learned from during hacktoberfest
Tags: hacktoberfest
Published: 2020-10-20 07:47:46

## What I Learned From Hacktoberfest

<!-- What did you learn that can help others contribute to the project you worked on? What did you learn that can help the users of that project?! -->

So, to be honest I haven’t used git or GitHub for a bit, and I used GitHub Desktop for the first time and created an accidental pull request. To say the least I was embarrassed. It was a forked project and I wanted to test things out before starting anything. Well I didn’t realize I was creating one to the master copy that I didn’t own. So from now on I know to check before continuing!
Facebook launches new Multilingual Machine Translation Model supporting 100 languages
Tags: machinelearning, nlp, news, datascience
Published: 2020-10-20 07:41:57

Facebook AI is introducing, **M2M-100** the first multilingual machine translation (MMT) model that translates between any pair of 100 languages without relying on English data. 

Previously the models relied on English data because it was easily available. When translating, say, Chinese to French, previous best multilingual models train on Chinese to English and English to French, because English training data is the most widely available. M2M-100 model directly trains on Chinese to French data to better preserve meaning. It outperforms English-centric systems by 10 points on the widely used **BLEU** metric which is an NLP benchmark for evaluating machine translations.

M2M-100 is trained on a total of 2,200 language directions — or 10x more than previous best, English-centric multilingual models. Deploying M2M-100 will improve the quality of translations for billions of people, especially those who speak low-resource languages.

You can read about the details [here](https://ai.facebook.com/blog/introducing-many-to-many-multilingual-machine-translation/).

Detail of the 100 languages along with their family.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/e5paz3zrpr3skyd58ar2.PNG)
How to find outreach opportunities
Tags: discuss, outreach
Published: 2020-10-20 07:25:50

Interested on ideas on how to find mentoring or teaching opportunities for those that are not already working in the software industry.

If you've mentored or taught before to future potential developers, what organizations have you worked with to help you find mentees/students?

Is there a recommended place to advertise your willingness to mentor/teach that will help match you to interested students?
A snippet for exporting an Azure App Service ssl certificate for use with Azure front door
Tags: azure
Published: 2020-10-20 07:25:40

---
title: A snippet for exporting an Azure App Service ssl certificate for use with Azure front door
published: true
tags: #azure
canonical_url: https://darraghoriordan.com/2020/10/18/snippet-exporting-app-service-certificate/
---

Azure app service ssl certificates do not have a password but other Azure services only allow importing of certificates with passwords set. So this is the openssl snippet required to export the certificate and add a password

<!-- end excerpt -->
## Export you current certificate to a passwordless pem type

First you need to get the cert out of Azure keyvault. There is an export/download function for this on Azure.

Once you have the file you will need openssl.

```
openssl pkcs12 -in myappservicecertificate.pfx -out tmpmycert.pem -nodes
```

It might prompt you for a password here which is blank. Just hit enter.

## Convert the passwordless pem to a new pfx file with password

```
openssl pkcs12 -export -out mypasswordedcert.pfx -in tmpmycert.pem
```

Now you will be prompted to enter the new password.
Is C# the future?
Published: 2020-10-20 06:48:22

C# (C sharp) is the most used languages for Game Development and app development for the Windows Operating System. The most game engines like Unity uses C# for developing games.
C# was developed by Microsoft in the year 2000. The most common example of C# is the settings app in Windows 10. There is not much similarity between C# and languages like C or C++ except of their name and some core functions like the syntax which is like C and its family. 
         C# was designed to be simple and easy to use. That's why it is often recommended for beginners who want to proceed for Windows Application Development or Game Development. Today C#'s main popularity comes for game development. Languages like Java and C++ are also used for game development for C# beats them all when you use Unity. You can develop many beautiful UI based applications on C# with a strong backend.
Now lets look at the drawbacks of C#:

i)It is slower to run. This is somewhat taken care of when using WPF, although currently the launching of WPF application 

ii) It is less flexible than C++. C

iv) It depends greatly on .NET framework, anything that is not found in the .NET framework

So by reading this article I hope you have a clear sight of C#, both its pros and cons.
For further details you can visit the C# documentation
www.webroot.com/safe | Enter Product Key | Activate Webroot

Published: 2020-10-20 07:22:59

Webroot Safe is one of the established great Antivirus software programs. In case you own a device or device that you’re connecting it to the internet or some other tool you then must have antivirus software program.

Virus or any risky hazard like Malware, Trojan, spyware, Rootkit or online hacking or assault can souse borrow your statistics and damage your machine. And to protect your gadget from such treats, install antivirus software referred to as webroot from www.webroot.com/safe and relaxed your device. You can additionally set up it on your tool which includes the laptop, mobile, tablet, pc and so forth.

Earlier than you continue in addition, you need to have the antivirus’s security retail card alongside the Webroot key code. Regardless of your buying mode (online or retail keep); you’ll have a unique Webroot secure key code. If the antivirus is bought from a retail store, you will get a Webroot retail card together with the CD/ DVD. And, when you have bought the antivirus software online, you will acquire a Webroot license number / or key code on your registered e-mail Id. underneath are the step-through-step approaches to download, install & Activate Webroot .com/safe to your pc.
[Stripe payment] How To Integrate Stripe Payment Gateway In Laravel 8?
Published: 2020-10-20 07:18:03

**Stripe Payment Gateway Integration In Laravel 8 With example**

Step 1: Install Laravel 8 App
Step 2: Install stripe Package
Step 3: Stripe Configuration
Step 4: Make Route
Step 5: Create Controller
Step 6: Create a Blade View file
Step 7: Run Development Server
**Read More: [[Stripe payment] How To Integrate Stripe Payment Gateway In Laravel 8?](https://www.phpcodingstuff.com/blog/how-to-integrate-stripe-payment-gateway-in-laravel-8.html)**

```
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Session;
use Stripe;

class StripeController extends Controller
{
    /**
     * success response method.
     *
     * @return \Illuminate\Http\Response
     */
    public function stripe()
    {
        return view('stripe');
    }

    /**
     * success response method.
     *
     * @return \Illuminate\Http\Response
     */
    public function stripePost(Request $request)
    {
        Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
        Stripe\Charge::create ([
                "amount" => 100 * 100,
                "currency" => "usd",
                "source" => $request->stripeToken,
                "description" => "This payment is tested purpose phpcodingstuff.com"
        ]);

        Session::flash('success', 'Payment successful!');

        return back();
    }
}
```